PATH: //opt/alt/python311/share/doc/alt-python311-pyparsing-doc/examples
FILE_BARU
CREATE
FOLDER_BARU
MKDIR
UPLOAD_FILE
GO
[ .. KEMBALI ]
📄 0README.html
↓
X
📄 AcManForm.dfm
↓
X
📄 LAparser.py
↓
X
📄 Setup.ini
↓
X
📄 SimpleCalc.py
↓
X
📄 SingleForm.dfm
↓
X
📄 TAP.py
↓
X
📄 __init__.py
↓
X
📁 __pycache__/
X
📄 adventureEngine.py
↓
X
📄 antlr_grammar.py
↓
X
📄 antlr_grammar_tests.py
↓
X
📄 apicheck.py
↓
X
📄 bigquery_view_parser.py
↓
X
📄 booleansearchparser.py
↓
X
📄 btpyparse.py
↓
X
📄 builtin_parse_action_demo.py
↓
X
📄 cLibHeader.py
↓
X
📄 chemicalFormulas.py
↓
X
📄 commasep.py
↓
X
📄 configParse.py
↓
X
📄 cpp_enum_parser.py
↓
X
📄 cuneiform_python.py
↓
X
📄 datetimeParseActions.py
↓
X
📄 decaf_parser.py
↓
X
📄 delta_time.py
↓
X
📄 dfmparse.py
↓
X
📄 dhcpd_leases_parser.py
↓
X
📄 dictExample.py
↓
X
📄 dictExample2.py
↓
X
📄 ebnf.py
↓
X
📄 ebnftest.py
↓
X
📄 eval_arith.py
↓
X
📄 excelExpr.py
↓
X
📄 fourFn.py
↓
X
📄 gen_ctypes.py
↓
X
📄 getNTPserversNew.py
↓
X
📄 greeting.py
↓
X
📄 greetingInGreek.py
↓
X
📄 greetingInKorean.py
↓
X
📄 groupUsingListAllMatches.py
↓
X
📄 holaMundo.py
↓
X
📄 htmlStripper.py
↓
X
📄 htmlTableParser.py
↓
X
📄 httpServerLogParser.py
↓
X
📄 idlParse.py
↓
X
📄 include_preprocessor.py
↓
X
📄 indentedGrammarExample.py
↓
X
📄 indented_block_example.py
↓
X
📄 invRegex.py
↓
X
📄 javascript_grammar.g
↓
X
📄 jsonParser.py
↓
X
📄 left_recursion.py
↓
X
📄 linenoExample.py
↓
X
📄 listAllMatches.py
↓
X
📄 lua_parser.py
↓
X
📄 lucene_grammar.py
↓
X
📄 macroExpander.py
↓
X
📄 make_diagram.py
↓
X
📄 matchPreviousDemo.py
↓
X
📄 mozilla.ics
↓
X
📄 mozillaCalendarParser.py
↓
X
📄 nested.py
↓
X
📄 nested_markup.py
↓
X
📄 number_words.py
↓
X
📄 numerics.py
↓
X
📄 oc.py
↓
X
📄 one_to_ninety_nine.py
↓
X
📄 parsePythonValue.py
↓
X
📄 parseResultsSumExample.py
↓
X
📄 parseTabularData.py
↓
X
📄 partial_gene_match.py
↓
X
📄 pgn.py
↓
X
📄 position.py
↓
X
📄 protobuf_parser.py
↓
X
📄 pymicko.py
↓
X
📄 pythonGrammarParser.py
↓
X
📄 railroad_diagram_demo.py
↓
X
📄 rangeCheck.py
↓
X
📄 readJson.py
↓
X
📄 removeLineBreaks.py
↓
X
📄 romanNumerals.py
↓
X
📄 rosettacode.py
↓
X
📄 scanExamples.py
↓
X
📄 searchParserAppDemo.py
↓
X
📄 searchparser.py
↓
X
📄 select_parser.py
↓
X
📄 sexpParser.py
↓
X
📄 shapes.py
↓
X
📄 simpleArith.py
↓
X
📄 simpleBool.py
↓
X
📄 simpleSQL.py
↓
X
📄 simpleWiki.py
↓
X
📄 snmp_api.h
↓
X
📄 sparser.py
↓
X
📄 sql2dot.py
↓
X
📄 stackish.py
↓
X
📁 statemachine/
X
📄 test_bibparse.py
↓
X
📄 unicode_denormalizer.py
↓
X
📄 urlExtractor.py
↓
X
📄 urlExtractorNew.py
↓
X
📁 verilog/
X
📄 verilogParse.py
↓
X
📄 withAttribute.py
↓
X
📄 wordsToNum.py
↓
X
SAVING...
BERHASIL DIUBAH!
EDITING: ebnf.py
# This module tries to implement ISO 14977 standard with pyparsing. # pyparsing version 1.1 or greater is required. # ISO 14977 standardize The Extended Backus-Naur Form(EBNF) syntax. # You can read a final draft version here: # https://www.cl.cam.ac.uk/~mgk25/iso-ebnf.html # # Submitted 2004 by Seo Sanghyeon # from pyparsing import * all_names = """ integer meta_identifier terminal_string optional_sequence repeated_sequence grouped_sequence syntactic_primary syntactic_factor syntactic_term single_definition definitions_list syntax_rule syntax """.split() integer = Word(nums) meta_identifier = Word(alphas, alphanums + "_") terminal_string = Suppress("'") + CharsNotIn("'") + Suppress("'") ^ Suppress( '"' ) + CharsNotIn('"') + Suppress('"') definitions_list = Forward() optional_sequence = Suppress("[") + definitions_list + Suppress("]") repeated_sequence = Suppress("{") + definitions_list + Suppress("}") grouped_sequence = Suppress("(") + definitions_list + Suppress(")") syntactic_primary = ( optional_sequence ^ repeated_sequence ^ grouped_sequence ^ meta_identifier ^ terminal_string ) syntactic_factor = Optional(integer + Suppress("*")) + syntactic_primary syntactic_term = syntactic_factor + Optional(Suppress("-") + syntactic_factor) single_definition = delimitedList(syntactic_term, ",") definitions_list << delimitedList(single_definition, "|") syntax_rule = meta_identifier + Suppress("=") + definitions_list + Suppress(";") ebnfComment = ( ("(*" + ZeroOrMore(CharsNotIn("*") | ("*" + ~Literal(")"))) + "*)") .streamline() .setName("ebnfComment") ) syntax = OneOrMore(syntax_rule) syntax.ignore(ebnfComment) def do_integer(str, loc, toks): return int(toks[0]) def do_meta_identifier(str, loc, toks): if toks[0] in symbol_table: return symbol_table[toks[0]] else: forward_count.value += 1 symbol_table[toks[0]] = Forward() return symbol_table[toks[0]] def do_terminal_string(str, loc, toks): return Literal(toks[0]) def do_optional_sequence(str, loc, toks): return Optional(toks[0]) def do_repeated_sequence(str, loc, toks): return ZeroOrMore(toks[0]) def do_grouped_sequence(str, loc, toks): return Group(toks[0]) def do_syntactic_primary(str, loc, toks): return toks[0] def do_syntactic_factor(str, loc, toks): if len(toks) == 2: # integer * syntactic_primary return And([toks[1]] * toks[0]) else: # syntactic_primary return [toks[0]] def do_syntactic_term(str, loc, toks): if len(toks) == 2: # syntactic_factor - syntactic_factor return NotAny(toks[1]) + toks[0] else: # syntactic_factor return [toks[0]] def do_single_definition(str, loc, toks): toks = toks.asList() if len(toks) > 1: # syntactic_term , syntactic_term , ... return And(toks) else: # syntactic_term return [toks[0]] def do_definitions_list(str, loc, toks): toks = toks.asList() if len(toks) > 1: # single_definition | single_definition | ... return Or(toks) else: # single_definition return [toks[0]] def do_syntax_rule(str, loc, toks): # meta_identifier = definitions_list ; assert toks[0].expr is None, "Duplicate definition" forward_count.value -= 1 toks[0] << toks[1] return [toks[0]] def do_syntax(str, loc, toks): # syntax_rule syntax_rule ... return symbol_table symbol_table = {} class forward_count: pass forward_count.value = 0 for name in all_names: expr = vars()[name] action = vars()["do_" + name] expr.setName(name) expr.setParseAction(action) # ~ expr.setDebug() def parse(ebnf, given_table={}): symbol_table.clear() symbol_table.update(given_table) forward_count.value = 0 table = syntax.parseString(ebnf)[0] assert forward_count.value == 0, "Missing definition" for name in table: expr = table[name] expr.setName(name) # ~ expr.setDebug() return table
SIMPAN PERUBAHAN