grammar OptOperator; prog: CONST? NUMBER EOF;
CONST : [Cc] [Oo] [Nn] [Ss] [Tt];
NUMBER : [0-9]+ ;
I have small grammar like the following
grammar OptOperator;prog: CONST? NUMBER EOF;CONST : [Cc] [Oo] [Nn] [Ss] [Tt];NUMBER : [0-9]+ ;
I want to make sure that, the user can input one of either "const 1" or "12". But I can't seems to do that. How to achieve this?
I'm using c++ target.
line 1:5 token recognition error at: ' 'line 1:0 mismatched input 'const' expecting {CONST, NUMBER}
std::string buffer="const 1"; // or "124" antlr4::ANTLRInputStream input(buffer); OptOperator::OptOperatorLexer lexer(&input); antlr4::CommonTokenStream tokens(&lexer); OptOperator::OptOperatorParser parser(&tokens); parser.setBuildParseTree(true); tokens.fill(); antlr4::tree::ParseTree *tree = parser.prog();
On Aug 4, 2018, at 11:08 AM, kang joni <kangj...@gmail.com> wrote:
yeah that sounds right, but I get this output
line 1:5 token recognition error at: ' 'line 1:0 mismatched input 'const' expecting {CONST, NUMBER}
My code so far is like the following one :
antlr4::ANTLRInputStream input(buffer);OptOperator::OptOperatorLexer lexer(&input);antlr4::CommonTokenStream tokens(&lexer);OptOperator::OptOperatorParser parser(&tokens);parser.setBuildParseTree(true);tokens.fill();antlr4::tree::ParseTree *tree = parser.prog();
Any idea?
On Saturday, August 4, 2018 at 9:32:26 PM UTC+7, Steve Vinoski wrote:On Sat, Aug 4, 2018 at 10:17 AM, kang joni <kangj...@gmail.com> wrote:I have small grammar like the following
grammar OptOperator;prog: CONST? NUMBER EOF;CONST : [Cc] [Oo] [Nn] [Ss] [Tt];NUMBER : [0-9]+ ;
I want to make sure that, the user can input one of either "const 1" or "12". But I can't seems to do that. How to achieve this?I'm using c++ target.You need to skip whitespace by adding the following:WS : [ \t\r\n]+ -> skip;--steve
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.