yacc - execute action in PLY Python before the symbol are parsed -


i'm making parser parse tokens 3 address code. generate correct tac code when calling function need call function "givetac" before , after tokens parsed.

my problem can't find way call function before parses token. in documentation of ply there section 6.11 embedded actions claims can add empty rule this:

def p_foo(p):     "foo : seen_a b c d"     print("parsed foo", p[1],p[3],p[4],p[5])     print("seen_a returned", p[2])  def p_seen_a(p):     "seen_a :"     print("saw = ", p[-1])   # access grammar symbol left     p[0] = some_value            # assign value seen_a 

but if try in code "syntax error in input!" error. code:

def p_fun_declaration_type_formal_pars_block(p):     'fun_declaration    : before type name lpar formal_pars rpar block'   def p_fun_before_fun(p):     'before :'     givetac("function",none,none,'main')     p[0]=p[1] 

if remove "before" in p_fun_declaration_type_formal_pars_block function accept syntax.

pastebin links of code: yacc.py

parser.out


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -