Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Antlr 3.2 Rewrite Rules

I've recently started learning Antlr and downloading AntlrWorks 1.4 which supposedly includes Antlr 3.2. Now, 3.2 is supposed to support the rewrite rules grammars like '->' but I've not been able to get even the simplest case I could construct to work either based on Lexer or Parser rules:

grammar TestRewrite;

ab  :   a b -> a;

a   :   A;
b   :   B;

A   :   'a';
B   :   'b';

When I try to compile this, I get the error:

[11:26:29] error(100): TestRewrite.g:3:13: syntax error: antlr: TestRewrite.g:3:13: unexpected token: a

Why is this. The construction seems simple enough: ab should generate a tree where only the a node is captured. Isn't that how you do it? I can't get it to work with rooting ('^') or ignoring ('!') either. I've very confused.

like image 201
TimeHorse Avatar asked Mar 02 '26 00:03

TimeHorse


1 Answers

options {output=AST;}

like image 168
Terence Parr Avatar answered Mar 04 '26 21:03

Terence Parr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!