0

I need a valid grammar for regular expressions that works in ANTLR4. I tried to write it:

grammar RegExp;

prog : s ;

s : (s)* t
| s + t
| t
;

t : t v
| v
;

v : v + z
| z
;

z : ID
| '(' s ')'
| '_' 
;

ID : [a-zA-Z0-9];

It tells me that s and v are mutually left-recursive

Bart Kiers
  • 166,582
  • 36
  • 299
  • 288
Giuseppe
  • 3
  • 3
  • P.S. '_' stands for empty string – Giuseppe Jun 05 '18 at 14:39
  • 1
    Lexer rules start with a capital. So all your rules are lexer rules. I recommend you first read a decent ANTLR tutorial before going forward. – Bart Kiers Jun 05 '18 at 14:51
  • Your updated question is posted more than once on SO, and more information about mutually left-recursive rules can be found through a web search (hence the closure, checkout the link on top of your answer). I'd like to emphasise my recommendation about reading up on ANTLR before going further. It looks to me you're trying to copy-paste some stuff together, which is (IMHO) not the way to go with this tool. – Bart Kiers Jun 05 '18 at 17:09

0 Answers0