문제

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top