On Tue, Jun 29, 2010 at 03:18:55PM -0700, Alex McMains wrote: > Hi all, > > I'm new to Antlr. I've bought?and read portions of the?Antlr book, > and I've read dozens of postings and tutorials, but I still can't > see how to do deal with a recursively changing input stream in > Antlr. Do I somehow use TokenRewriteStream, or am I missing > something?
Hi Alex, Yes, you are missing something, the Antlr book does not say much about symbol tables or type systems. For simple type systems, it is probably easier to just use the approach which is called a "symbol table" in old school books on compiler construction. A really good description of this approach is in chapter 7 of the book Language Implementation Patterns by Terence Parr. An introduction to this approach is at: http://www.antlr.org/wiki/display/CS652/Symbol+tables You obviously need to implement forward references scopes. Mainly for the mailing list archive, I would just like to say that I find this symbol table approach seems difficult to use for complex type systems. For complex type systems the approach I recommend is described in the book "Types and Programming Languages" by Benjamin Pierce, the online book "Software Foundations", see the course: http://www.seas.upenn.edu/~cis500/current/index.html and the book "Certified Programming with Dependent Types" by Adam Chlipala: http://adam.chlipala.net/cpdt/ Regards, Mark > Here's the situation: > > I start with an input stream. As I move through the input I will > either encounter something that can be parsed directly, or I will > encounter something that tells me to go to a table and substitute an > entire row of the table at the node where I currently am. This can > continue to happen recursively since each field from the substituted > row can again call for a substitution. > > Here's an example: > > Person table: > Identifier Name {Address} > Person1 Jon Jon's Address > > Address table: > Identifier HouseNumber StreetName > Jon's Address 3477 Blue Lane > > The {} around Address says to name the current node "Address" and > substitute the current value for whatever is at "Jon's Address" in > the Address table. > > Eventually this will become XML that would look like: > > <Person> > <Name>Jon</Name> > <Address> > <HouseNumber>3477</HouseNumber> > <StreetName>Blue Lane</StreetName> > </Address> > </Person> > > Any ideas would be appreciated. > > Thanks. > > -- alex > > > > > 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.
