At 08:47 22/08/2009, Stanislav Sokorac wrote: >What is the best way to handle this problem when the children of >a node are coming from different CharStreams (include files, >macros, what have you...), and you could expect to have the first >or last token be from another stream? [...] >It seems to me that the tree walker has no way of determining the >location of the first character in PROGRAM without us tracking >the locations of char stream switches during lexing, but that >creates a special case to be checked for every one of the nice >and simple methods below. Is there a more elegant solution >available?
You're going to want to track that information anyway, in order to provide good error reporting (people will want to know that an error is on line 16 of include file B, not on line 152 of the input after preprocessing). ANTLR already includes a line number with each token, and the filename is in the char stream. You just need to link the token with the char stream it came from (which might even already be done; I haven't checked) and you should be good to go. If you don't care about the error reporting, then the simplest thing to do is to run a complete preprocessing pass to merge all the include files before starting the "real" lex/parse/treewalk. 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 -~----------~----~----~----~------~----~------~--~---
