Hi all, I have a grammar I'm currently working on (posted in another thread the other day), which has the following rule:
meth_call_expr : (id = IDENTIFIER DOT)? func_call_expr -> ^(METHOD_CALL { ($id==null) ? adaptor.create(SELF, "SELF") : adaptor.create(IDENTIFIER, $id.getText()) } func_call_expr) ; As you can see, I'm using an action in the rewrite rule to insert either the (optional) IDENTIFIER, or an imaginary SELF node if IDENTIFIER is not specified. The problem I'm having is that this generates a parser that won't compile. Specifically, it generates the following bit of code (edited by hand for brevity and to highlight the error): /* **** [ CODE ] **** */ // $ANTLR start synpred6_BasicLang public final void synpred6_BasicLang_fragment() throws RecognitionException { Token =null; // <-- ERROR HERE /* ... later on ... */ switch (alt23) { case 1 : // C:\\Users\\chantelle\\workspace\\basiclang\\src\\com\\roscopeco\\basiclang\\parser\\BasicLang.g:99:8: id= IDENTIFIER DOT { id=(Token)match(input,IDENTIFIER,FOLLOW_IDENTIFIER_in_synpred6_BasicLang232); if (state.failed) return ; // <-- AND HERE match(input,DOT,FOLLOW_DOT_in_synpred6_BasicLang234); if (state.failed) return ; } break; } /* **** [ END ] **** */ Obviously the problem is the "Token =null" line, which should be "Token id = null". Changing it by hand fixes the errors and makes the parser work as expected. So I have two questions - is this the right way to go about inserting an imaginary token if an optional token isn't in the input, and if so, what am I doing wrong to cause the error above? Thanks in advance, Ross 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 il-antlr-inter...@googlegroups.com. To unsubscribe from this group, send email to il-antlr-interest+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=en.