I am implementing parser for language similar to java but simpler. I have written a lexer, and am now writing parser. I have written the grammar, I need to implement counting of elements but I have no idea were to put it. I think that it should be in action code after productions but I don't know were to initialize it.
For example
MethodDecl ::= ReturnType:type IDENTIFIER:id LPAREN FormParsOp:pars RPAREN VarDeclListOp LBRACE StatementListOp RBRACE
{: System.out.println("Method: " + type + " " + id + "(" + pars + ")"); methodNumber++;:}
| STATIC ReturnType:type IDENTIFIER:id LPAREN FormParsOp:pars RPAREN VarDeclListOp LBRACE StatementListOp RBRACE
{: System.out.println("Static method: " + type + " " + id + "(" + pars + ")"); staticMethodNumber++;:} ;
Where should I define and initialize the variables methodNumber and staticMethodNumber?
Solved... I put them in action code and initialized there