0

The below is a snippet of an ANTLR grammar which works fine.

It is intended to become a tex-parser.

If I modify rule everywhere by uncommenting | text, ANTLR reports a left recursion in rule escSeq which I think is funny.
I cannot find a left recursion: either I am blind or I misunderstood what left recursion is.

Any suggestions?

afterNewline : (everywhere | par );

par : EoL {System.out.println("<PAR>");} afterNewline ;

everywhere : (Esc escSeq //| text
        );

escSeq : (
            EoL          {System.out.println("<cmd:''>");}        afterNewline |
            Space        {System.out.println("<cmd:' '>");}       skipSpace |
            name=Letter+ {System.out.println("<cmd:"+$name.text+">");} skipSpace |
            Other        {System.out.println("<cmd:Other>");}      inLine // **** Other is too restrictive. 
        );

text : (Letter | Other) inLine;

skipSpace : (everywhere | (Space|EoL) {System.out.println("<SKIP>");});

inLine : (everywhere | Space | EolInLine);

EolInLine : EoL {System.out.println("<text:' '>");};

texDocument : afterNewline EOF;
Sam Harwell
  • 97,721
  • 20
  • 209
  • 280
user2609605
  • 419
  • 2
  • 14
  • I'm not an expert in grammars but: `everywhere` => `text` => `inLine` => `everywhere` – André Stannek Jul 23 '13 at 08:28
  • Ah, i see from what antlr produced: it requires options { backtrack=true ; } which seems to allow recursion at all. Then it works fine... at least for small documents, because the history of nonterminals is stored on the stack which carries the risk of (good intuition to post it on stackoverflow.com ;-) ) I think, my grammar is conceptually inappropriate, at least with antlr. – user2609605 Jul 23 '13 at 09:32

1 Answers1

0

The grammar above does not have left recursion, with or without the | text alternative in everywhere. ANTLR 4 does not report left recursion. If ANTLR 3.5 reports left recursion, you should post this as an issue here:

https://github.com/antlr/antlr3/issues

Sam Harwell
  • 97,721
  • 20
  • 209
  • 280