ANTLR error when generating C file using ANTLRWorks -
i using antlrworks 1.5 c (antlr 3.5). created lexer , parser file. when trying generate code, returns error <[18:52:50] error(100): script.g:57:2: syntax error: antlr: missingtokenexception(inserted [@-1,0:0='<missing eof>',<-1>,57:1] @ options {)>
.
here code, please tell missing.
/* ############################## l e x e r ############################ */ grammar lexer; options { language = c; output = ast; //generating ast astlabeltype = pantlt3_base_tree; //specifying tree walker k=1; // 1 lookahead character required } // define string values - either simple unquoted or complex quoted string : ('a'..'z'|'a'..'z'|'0'..'9'|'_' | '+')+ | ('"' (~'"')* '"'); // ignore whitespace ws :(' ' | '\t' | '\r' '\n' { newline(); } | '\n' { newline(); } ) { $settype(token.skip); } ; // todo:single-line comment line_comment : '/*' (~('\n'|'\r'))* ('\n'|'\r'('\n')?)? { $settype(token.skip); newline(); } ; // punctuation lbrace : '<'; rbrace : '>'; slash : '/'; equals : '='; semi : ';'; trigger : ('trigger'); triggertype : ('fall') slash ('rise')|('rise') slash ('fall')|('fall')|('rise'); default : ('default timeset'); timesetval : ('tset_')('0..9')*;
/* ############################## p r s e r ############################ */ grammar script; options { language=c; output=ast; // automatically build ast while parsing astlabeltype=pantlr3_base_tree; //k=2; // need lookahead of 2 props without keys (to check =) } /*tokens { script; // imaginary token inserted @ root of script block; // imaginary token inserted @ root of block command; // imaginary token inserted @ root of command property; // imaginary token inserted @ root of property }*/ /** rule parse trigger line */ trigger : trigger equals triggertype semi; /** rule parse timeset line */ timeset : default timesetval;
your "combined" grammar lexer
has lexer rules, while when define grammar
, antlr expects @ to the lowest degree 1 parser rule.
there 3 different types of grammars
combined grammar:grammar foo
, generates: class fooparser extends parser
, class foolexer extends lexer
parser grammar: parser grammar bar
, generates: class bar extends parser
lexer grammar: lexer grammar baz
, generates: class baz extends lexer
so, in case, alter grammar lexer;
lexer grammar scriptlexer;
(don't name lexer grammar lexer
since base of operations lexer class in antlr!) , import lexer in parser grammar:
parser grammar scriptparser; import scriptlexer; options { language=c; output=ast; astlabeltype=pantlr3_base_tree; } // ...
related:
antlr3 wiki: composite grammars c antlr antlrworks
No comments:
Post a Comment