CONVERTING ANTLR V3 TO V4

55 views
Skip to first unread message

Siya Mzam

unread,
Apr 26, 2016, 7:21:56 AM4/26/16
to antlr-discussion
I am converting from antlr3 to 4. I have stripped out all the syntactic predicates, but now I am struggling finding the equivalent of something like this in antlr4

 relaxed_date_month_first
  : relaxed_day_of_week? relaxed_month COMMA? WHITE_SPACE relaxed_day_of_month (relaxed_year_prefix relaxed_year)?
      -> ^(EXPLICIT_DATE relaxed_day_of_month relaxed_month relaxed_day_of_week? relaxed_year?)

I get an error at input "->" and "^". It says, "{EXPECTING TOKEN_REF, RULE_REF...ACTION}". How can I rewrite that grammar rule to so as to be antlrV4 compliant? 



Jim Idle

unread,
Apr 26, 2016, 7:27:54 AM4/26/16
to antlr-discussion
There are no rewrite rules in v4. You basically write a parser listener and construct your own structure or act directly. 





--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Siya Mzam

unread,
Apr 26, 2016, 7:31:18 AM4/26/16
to antlr-discussion
Okay, thanks, so you mean I would write the above as 

 relaxed_date_month_first
  : relaxed_day_of_week? relaxed_month COMMA? WHITE_SPACE relaxed_day_of_month (relaxed_year_prefix relaxed_year)?

and antlr will generate an appropriate listener?

Jim Idle

unread,
Apr 26, 2016, 7:43:57 AM4/26/16
to antlr-discussion
Yes. Though you need to read the book or one of the online tutorials to see what to do. It's not difficult :)







Siya Mzam

unread,
Apr 26, 2016, 7:49:26 AM4/26/16
to antlr-discussion
Okay, Thanks Jim.
Reply all
Reply to author
Forward
0 new messages