Reputation: 21
I am using antlr3. I have my parser and lexer files.I want to print the incoming token(As given by user input) in the parser file.I have tried input.LT(1).
It prints the input token(given by user) nicely. But then for future analysis I can't use this lookahead token. So is there any other commands or instruction that can print the incoming tokens?
(For example if my input is 1+2+; my token for '+' is 'PLUS', then I must print '+' not 'PLUS').
Upvotes: 0
Views: 266
Reputation: 12440
To get the actual text of the token ("+"), use token.getText()
.
To get the text representing the token name ("PLUS"), you'll have to ask the parser: <YourParserClass>.tokenNames[token.getType()]
.
Upvotes: 0