title: How to include counting of method declaration, constants, functions calls in parser?
body: <p>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.</p>
  
  <p>For example</p>
  
  <pre><code>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++;:} ;
  </code></pre>
  
  <p>Where should I define and initialize the variables methodNumber and staticMethodNumber?</p>