On Wednesday 11 November 2009 11:40:44 am Jim Idle wrote: > Just add counters in the parser rules (scope probably), let there be any > number of them, then issue errors if the counts are wrong. You really don't > want to do things like this at the grammar level - the messages you will > issue will be confusing to users "Error at 'y', expecting '}'" leaves you to > guess the meaning. It is generally better to produce a CommonTree, verify it > and output whatever you need. Every task is different though.
Jim, Thanks for the counter suggestion, I hadn't thought of that. Since my token is a fixed length, I started off measuring the total length of the production's child nodes in order to determine the number of tokens, but it didn't sit right with me. I will definitely need good readable error messages so I've relaxed the main grammar a bit and now I handle the rest in my semantic processing phase. > You can also use gated predicates or ordinary predicates perhaps, but you > will end up with a messy grammar that isn't as easy to deal with. That's an interesting thought, but I believe you're right, that will make things messy and more intertwined than need be. Thanks. -- Kaleb Pederson Blog - http://kalebpederson.com Twitter - http://twitter.com/kalebpederson 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]. For more options, visit this group at http://groups.google.com/group/il-antlr-interest?hl=.
