Inherited attributes in bison/yacc -
how can use inherited attributes in bison/yacc ?
say, have grammar -
program -> stmts
what wanted in bison :
program : stmts {$$.next = newlabel(); $1.next = $$.next; }
here next attribute declared in structure , type added union.
in btyacc can use:
program: stmts(newlabel()) { $$.next = $1.next; } stmts($arg) : .... { $$.next = $arg; ... }
to sort of thing. equivalent to
program: { $<tag>$ = newlabel()); } stmts { $$.next = $1.next; } stmts: .... { $$.next = $<tag>0; ... }
in bison (or yacc), more type-safe. you'll need right %union
, %type
declarations in either case.
Comments
Post a Comment