Mike Gering wrote:
OK - I think that you are probably making the classic error of trying to overspecify the grammar and express semantics/context as part of the rules. The general idea is to step back and write rules that parse all valid constructs without trying to infer too much about them, then when you know what you have, rewrite to an AST. So you want to left factor the a and b so it can parse all the valid forms, then work out what the differnces are once you have valid syntax. Something like aorb : simple_name aorbelement+ // Or maybe *? ; aorbelement : STAR (INT {set a flag} | simple_name {set a flag} ) | SLASH simple_name ; THne work out if any of these elements turned up in positions they were not allowed to be in, such as STAR INT not being the last element. You can then issue a nice semantic error explaining what is wrong with the code rather then just 'syntax error'. As in: "The construct '*99' must be the last element of a foobar" and so on. You will get in to a real mess trying to follow the normative grammar/language specification too literally and you will not have as neat a parser when you are done. Jim --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~--- |
List: http://www.antlr.org/mailman/listinfo/antlr-interest Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address
