grammar with fragments

56 views
Skip to first unread message

Philipp Kraus

unread,
Feb 28, 2017, 12:03:54 PM2/28/17
to antlr-discussion

Hello,

I have created a grammar and I use some "constants" e.g. pi, if the user create a function call like "setpi", the lexer returns
a parsing error, because the "pi" fragment is found inside the own word definition.


In detail the problems are the fixed constants:

inside a rule like


I need a tip how can I fixe this. I the "fragment" option an idea? In my case the atom and variable rule can contain
a string which is equal to a literal iif it not exactly equal.

Thanks

Phil

Gerald Rosenberg

unread,
Feb 28, 2017, 1:09:49 PM2/28/17
to antlr-discussion
Do no use the `import` statement to import the lexer.  Use a standard split grammar form.

Philipp Kraus

unread,
Mar 1, 2017, 2:12:56 AM3/1/17
to antlr-discussion
in my case I use 3 main grammars (Agent.g4, PlanBundle.g4, Type.g4), which are based on the imported grammar files AgentSpeak.g4, ComplexType.g4 and
Terminal.g4. 
So imho I don't import the Terminal.g4 lexer grammar, into my ComplexType.g4 grammar, so I have to change this line only:

to "options { tokenVocab=Terminal; }"

If I do this I get on the build the errors / warnings:

src/main/antlr4/imports/ComplexType.g4 [28:0]: options ignored in imported grammar ComplexType
[WARNING] warning(125): org/lightjason/agentspeak/grammar/Type.g4:60:6: implicit definition of token LEFTANGULARBRACKET in parser
[WARNING] org/lightjason/agentspeak/grammar/Type.g4 [60:6]: implicit definition of token LEFTANGULARBRACKET in parser

The "implicit definition" warning is called for each terminal element. How can I do this correctly?

Thanks
Phil

Gerald Rosenberg

unread,
Mar 1, 2017, 12:51:07 PM3/1/17
to antlr-discussion
Split grammars are named

parser grammar name ;
....

and

lexer grammar name;
....

See TDAR pg 257 for more.

Reply all
Reply to author
Forward
0 new messages