Issue with parsing a function in Python (optionally with pyparsing) -


i'm using pyparsing library parse python-like programming language. seem having trouble figuring out how translate bnf grammar executable code.

my script more complex this, i've distilled problem few lines:

arg_or_func_name = word(alphanums + '_') expr = forward() func = expr + literal('(') + literal(')') expr << (arg_or_func_name | func) statement = expr + literal(';')  parsed = statement.parsestring('func_a();') 

i want parse [('expr', [('func', ['func_a', '(', ')')])]), ';']. instead, causes error pyparsing.parseexception: expected ";", assume because greedily considers func_a arg_or_func_name, , disregards parentheses.

however, when reverse order of expr statement , change to

expr << (func | arg_or_func_name) 

or when

expr << (func ^ arg_or_func_name) 

i maximum recursion depth exceeded error; apparently searching in order results in infinite recursive loop.

i program match longest string possible (specifically, of func_a()), in way not cause infinite loop. possible?

i prefer continue using pyparsing, answers using library preferred, i'd appreciate answers using other python tools translating bnf grammars.


Comments

Popular posts from this blog

php - How to display all orders for a single product showing the most recent first? Woocommerce -

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

angularjs - How restrict admin panel using in backend laravel and admin panel on angular? -