I wanna print out the value of the tokens called in parser (returned by the scanner) however it shows null for each.
For example when the input file is
tmp := X*X;
This grammar should print "tmp assigned" instead of "null assigned":
assignment ::= IDENTIFIER:i ASSIGNMENT math_expression SEMI
{: System.out.println(i + " assigned"); :}; // null assigned
Is there any other way to get the actual value (other than the written code :D) or shall I do any further step beyond this to get to them?
Parts of code that may be needed:
lexer.jflex
public Symbol symbol(String name, int code){
return symbolFactory.newSymbol(name, code,
new Location(yyline+1,yycolumn+1, yychar),
new Location(yyline+1,yycolumn+yylength(), yychar+yylength())
);
}
public Symbol symbol(String name, int code, String lexem){
return symbolFactory.newSymbol(name, code,
new Location(yyline+1, yycolumn +1, yychar),
new Location(yyline+1,yycolumn+yylength(), yychar+yylength()), lexem);
}
The way I have returned it in YYINITIAL state:
{identifier} {return symbolFactory.newSymbol("IDENTIFIER", IDENTIFIER);}
parser.cup
terminal String IDENTIFIER;