1

I have follow simple grammar:

grammar G;

var : str ('as' str)?;
str : WORD;

WORD : LETTER+;
fragment LETTER : [a-z];
WS : [ ] -> skip;
NEWLINE : [\n] -> skip;

I want the word "as" to unfold by antlr as strrule. For example, the "as" string has to be accepted by the parser, but antlr unfold 'as' as token.

line 1:0 missing WORD at 'as'
line 1:2 missing WORD at '<EOF>'
(var (str <missing WORD>) as (str <missing WORD>))

How to use antlr so that the word "as" is a keyword only in second position?

P.S. The initial problem was to use "as" as a keyword only in the import expression and to be able to give variables the name "as".

0 Answers0