4

I have never used antlr in past, but now have to migrate grammar for an older version to the latest. I am trying to generate lexer and parser for c# target. I am stuck on migrating the start rule seen below.

grammar expr;

DQUOTE: '\"';
SQUOTE: '\'';
NEG   : '-';
PLUS  : '+';
OPEN  : '(';
CLOSE : ')';
PERIOD: '.';
COMMA : ',';

start returns [Expression value]
:

    expression EOF { $value = $expression.value; }

;

expression returns [Expression value]

  :

    literal                             { $value = $literal.value; } 
  | name                                { $value = $name.value; } 
  | functionCall                        { $value = $functionCall.value; }

;

I get the following error. syntax error:

mismatched input '[Expression value]' expecting ARG_ACTION while matching a rule.

I have already come across a post Troubles with returns declaration on the first parser rule in an ANTLR4 grammar. But Sam's response has not helped me figure out what I should be changing in my case.

I would appreciate if anyone could let me know the equivalent of the start rule in latest grammar.

Community
  • 1
  • 1
VikasGNS
  • 41
  • 4
  • 1
    Please post the full grammar or at least the part up to the rule. –  Sep 08 '15 at 12:37
  • @doublep : I have inserted all the grammar preceding the start rule. Also inserted the parser rule following the start rule. Code generation appears to work well for all rules except the start rule. Let me know if you need more details. – VikasGNS Sep 09 '15 at 05:49

1 Answers1

2

The answer you linked appears to be applicable to your case. Move lexer rules (i.e. those starting with uppercase letters, DQUOTE and so on) after parser rules like start.