If you aren't going to lex that token to something else, I'm pretty sure the right solution is to just lex it as the invalid token. If you are going to lex it to something else, then likely you have the "keyword" vs. "id" problem (use one token for it in the lexer, and pick which one it really is during parsing). Which I believe is best resolved by a gated predicate in the parser. If it "looks" like legal code, you'd be better of actually generating the error at the semantic check phase. You have a lot more context in order to generate a useful error message at that point.
Kirby On Mon, Jul 19, 2010 at 7:23 PM, Billy O'Neal <[email protected]> wrote: > Hello, Everyone :) > > Was referred here from my StackOverflow question: > http://stackoverflow.com/questions/3278338/using-the-antlr-c-target-how-can-i-get-the-previously-matched-token-in-the-lexer > > I'm quite new to ANTLR; and my Lexer needs to have a gated rule which > makes it valid if and only if it occurs directly after another rule. > If there's a way to get the previously emitted token type, that would > make that gating easy. Otherwise I have to fail over to a nasty hack > of turning the boolean flag off after every lexer rule. > > Is it simple/easy to get that information in a lexer rule predicate? > > Billy3 > -------------------------------------------------------------- > Intern - PreEmptive Solutions, LLC > Malware Response Instructor - BleepingComputer.com > Analyst, Security Team - TechSupportForum.com > > 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.
