3

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?

user1319267
  • 73
  • 1
  • 8

1 Answers1

1

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';
Bill the Lizard
  • 398,270
  • 210
  • 566
  • 880
  • 1
    Yes, it is working!! Thanks! But know the parse is not able to read Out_S($A,$B,xn,x) giving this error: mismatched input 'O' expecting {'!', ALPHA}! Why? – user1319267 Sep 13 '18 at 14:05
  • @user1319267 It looks like `Out_S($A,$B,xn,x)` doesn't match any of the definitions for `fact`. – Bill the Lizard Sep 13 '18 at 14:58
  • True! It was missing factIdentifier '(' msetterm (',' msetterm)* ')' – user1319267 Sep 13 '18 at 15:19
  • Ok, I fixed the grammar but I still have the problem! in fact, I got the same error! If I see the parser tree, the parser sees there is a genericRule, sees the facts but at the first fact is not able to read Out_S($A,$B,xn,x) even if now there is the rule. – user1319267 Sep 13 '18 at 16:51
  • @user1319267 I'm not sure what's causing it, but I think it might be the `$`. I only see those as part of the `nonnode_var` definition, and I don't see that anywhere as a component of `msetterm`. – Bill the Lizard Sep 13 '18 at 17:11