Am i getting tree grammars completely wrong ?

43 views
Skip to first unread message

afran...@gmail.com

unread,
Aug 12, 2013, 7:07:09 PM8/12/13
to antlr-di...@googlegroups.com
Hi, I have read the book on antlr and other post related to building the tree grammar which all comes up to, "it does not contain the tokens that have been omitted from the tree, and also does not contain any lexer rules " #Bart. I have tried this method for days on a grammar file to no avail; errors keep pilling up. Do i need to change certain rules ? and what about the rules in the grammar that had no "rewrite rule or tree operator" should it stay that way in the tree grammar ?

for example a rule like this in my grammar file :

relational_expression : additive_expression ((ST|GT|STEQ|GTEQ)^ additive_expression)* ;

How will the tree grammar version look like ?

Sam Harwell

unread,
Aug 12, 2013, 8:13:27 PM8/12/13
to antlr-di...@googlegroups.com
The tree grammar rule corresponding to that is the following:

relational_expression
: ^((ST|GT|STEQ|GTEQ) relational_expression relational_expression)
| additive_expression
;
--
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/groups/opt_out.


afran...@gmail.com

unread,
Aug 15, 2013, 3:36:58 AM8/15/13
to antlr-di...@googlegroups.com, afran...@gmail.com

Thanks for your reply Sam, that solves the problem there. Please can you answer my theoretical question about the implementation of tree grammars ? I have noticed that rules with syntactic predicates get rejected.

Jim Idle

unread,
Aug 15, 2013, 4:50:40 AM8/15/13
to antlr-di...@googlegroups.com
Essentially, as you are in charge of the tree structure, you should produce a structure that is inherently not ambiguous and so contains no syntactic predicates. The rewrite rules and annotations allow you to do that :)

Jim
Reply all
Reply to author
Forward
0 new messages