It would be nice if it were possible to define custom methods and custom initialization code in the lexer and parser classes. It is often useful to factor out common code from productions currently one can define functions in the %footer section, but often it would be better/cleaner if they were methods of the Parser class. Additionally often the interesting result of a parse is the assembly of a structure, which is done by method calls on the resulting object and not the semantic value of the root node. Also the %function lexaction better were a %method lexaction.
Current Workaround: Just use the methods in the actions, use derived classes of Lexer and Parser which have the init code and supply the methods.
Another Possible workaround: use stupid and complete %AST generation and derive a visitor accordingly. This may be desirable for building up legacy structures anyway.
It would be nice if it were possible to define custom methods and custom initialization code in the lexer and parser classes. It is often useful to factor out common code from productions currently one can define functions in the
%footersection, but often it would be better/cleaner if they were methods of theParserclass. Additionally often the interesting result of a parse is the assembly of a structure, which is done by method calls on the resulting object and not the semantic value of the root node. Also the%functionlexaction better were a%methodlexaction.Current Workaround: Just use the methods in the actions, use derived classes of
LexerandParserwhich have the init code and supply the methods.Another Possible workaround: use stupid and complete %AST generation and derive a visitor accordingly. This may be desirable for building up legacy structures anyway.