terminal node in rule will not be recognize

10 views
Skip to first unread message

Philipp Kraus

unread,
Apr 10, 2018, 7:04:34 PM4/10/18
to antlr-discussion
Hello,

I have got the following (excerpt) rules and terminals on my grammar:

belief_action :
    BELIEFTRIGGER literal
    ;

literal :
    ( AT | STRONGNEGATION )?
    ATOM
    termlist?
    ;

BELIEFTRIGGER :
    PLUS
    | MINUS
    ;

STRONGNEGATION : '~' | 'not';

ATOM :
    LOWERCASELETTER
    ( LOWERCASELETTER | UPPERCASELETTER | DIGIT | SLASH | MINUS | UNDERSCORE )*
    ;

UNDERSCORE     : '_';
SLASH          : '/';
fragment PLUS  : '+';
fragment MINUS : '-';

fragment LOWERCASELETTER   : [a-z];
fragment UPPERCASELETTER   : [A-Z];
fragment DIGIT             : [0-9];

Within the belief_action rule the terminal node BELIEFTRIGGER will not recognize e.g. on an input "+foo" the + sign
is not matched. How can I fix this correctly?

The full grammar can be found under
https://github.com/LightJason/AgentSpeak/blob/feature/expression/src/main/antlr4/org/lightjason/agentspeak/grammar/Agent.g4
https://github.com/LightJason/AgentSpeak/tree/feature/expression/src/main/antlr4/imports

Thanks a lot

Phil



Kevin Cummings

unread,
Apr 10, 2018, 9:47:07 PM4/10/18
to antlr-di...@googlegroups.com
In your Terminal.g4 grammar, ARITHMETICOPERATOR3 gets recognized before
BELIEFTRIGGER. Since they are basically the same rule )both are either
PLUS or MINUS) you need to remove the ambiguity from your grammar. LEX
syntactically, not semantically.
> --
> 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
> <mailto:antlr-discussi...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
Kevin J. Cummings
cumm...@kjchome.homeip.net
cumm...@kjc386.framingham.ma.us
kjc...@icloud.com
Registered Linux User #1232 (http://www.linuxcounter.net/)
Reply all
Reply to author
Forward
0 new messages