You are just getting that because you need the rewrite at the end of an alt or section:
| ( primary -> primary) ... Jim > -----Original Message----- > From: [email protected] [mailto:antlr-interest- > [email protected]] On Behalf Of Stephen Tuttlebee > Sent: Saturday, March 05, 2011 4:08 PM > To: [email protected] > Subject: [antlr-interest] Tree construction rewrite rule error > > Hi there, > > I'm currently using the Java.g parser grammar (by Yang Jiang) from > http://openjdk.java.net/projects/compiler-grammar/ and am trying to add > tree construction rewrite rules and operators to build an AST. That's > quite a job in itself (I'm trying roughly to base it on one I found in > the mercurial repository on that site that contained actions that > created a javac-style AST). > > Anyway, my specific question relates to the LAST ALTERNATIVE in the > following rule (from the "expression hierarchy"): > > unaryExpressionNotPlusMinus > : TILDE unaryExpression -> ^(BITWISE_COMPLEMENT unaryExpression) > | BANG unaryExpression -> ^(LOGICAL_COMPLEMENT unaryExpression) > | castExpression > | {inHandlerDeclaration||inRunMethodDeclaration}?=> > inSynchronizationExpression // only allowed within handler declarations > (which in turn are inside component definitions) > | primary -> primary > (selector -> selector[$unaryExpressionNotPlusMinus.tree])* > ( PLUSPLUS -> ^(POSTINC $unaryExpressionNotPlusMinus) > | SUBSUB -> ^(POSTDEC $unaryExpressionNotPlusMinus) > )? > ; > > The last alternative does look a little complicated but it is basically > creating a single tree from the 'primary' in case nothing else is > matched (due to the * and ? that mean we could not match anything), > while the subsequent rewrite rules (->) within the alternative are > successively building up the tree by making the tree constructed thus > far a child of a newly created tree (this is done by referencing the > rule itself -- referencing $unaryExpressionNotPlusMinus in the context > of a rewrite rule means "take the current value of the tree of > unaryExpressionNotPlusMinus"). > > However, when I run the grammar through ANTLR (3.3) I get the following > errors: > > error(100): /JavaBTranslator/src/JavaBPhase1SynSem1.g:1026:19: syntax > error: antlr: expecting RPAREN, found '->' > |---> (selector -> selector[$unaryExpressionNotPlusMinus.tree])* > > error(100): /JavaBTranslator/src/JavaBPhase1SynSem1.g:1027:22: syntax > error: antlr: expecting RPAREN, found '->' > |---> ( PLUSPLUS -> ^(POSTINC $unaryExpressionNotPlusMinus) > > error(10): internal error: /JavaBTranslator/src/JavaBPhase1SynSem1.g : > java.lang.NullPointerException > 3 errors > > > It seems that ANTLR does not like the -> that appear in the middle of > the alternative for some reason. The problem could be a simple ANTLR > syntax thing which I'm not clear about. > > Anyone have any ideas about why I'm getting these errors. > > Thanks, > Stephen > > PS. also, it seems that coming up with the tree grammar rules to > recognise the tree might be a little harder than constructing the tree > in the parser, at least for the more complicated tree rewrite rules > like this. But I'll have to cross that bridge when I come to it. > > List: http://www.antlr.org/mailman/listinfo/antlr-interest > Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your- > email-address List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address -- You received this message because you are subscribed to the Google Groups "il-antlr-interest" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.
