Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ANTLR4 grammar no viable alternative at input

I am working on a project and I have to create a parser for the following grammar:

grammar T;

I am trying to read this piece of code:

theory oo
begin

builtins: asymmetric-encryption
functions: f/1  // f/1 used for function in protocol

/* Channel rules */ 

rule ChanOut_S:
    [Out_S($A,$B,xn,x)]
    --[ChanOut_S($A,$B,xn,x)]->
    [!Sec($A,$B,xn,x)]

I used to generate the parser tree using grun as follows:

grun T theory oo.spthy -gui

But every time I try to generate the parser tree I have the following error:

line 9:5 no viable alternative at input 'ruleC'

It seems the grammar has some problem but I am not able to figure it out. Do you have any clue?

like image 323
user1319267 Avatar asked Dec 10 '25 11:12

user1319267


1 Answers

It seems that the lexer is getting confused by these two rules:

ALPHA : 'A'..'Z';

ALPH : ('a'..'z' | 'A'..'Z');

Since the first letter of ChanOut_S matches the rule ALPHA, the C gets consumed by that lexer rule. If you switch the order of those two rules, the entire identifier is recognized.

ALPH : ('a'..'z' | 'A'..'Z');

ALPHA : 'A'..'Z';
like image 112
Bill the Lizard Avatar answered Dec 13 '25 11:12

Bill the Lizard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!