[antlr-interest] Implementing Nested Scopes in C#

Rob Dougan rob_dougan at sympatico.ca
Mon Jul 27 08:17:23 PDT 2009


I am writing a simple C-like interpreter (blocks, expressions, variable declarations, function calls). I would like to use a tree-grammar to generate the walker.

The target language is c# (csharp2), i am using ANTLR 3.1.3. ANTLRWorks 1.2.3.

 

I bought a copy of Terrence's book on Language design patterns, and i was working through the "Symbol Table for Nested Scopes" example and I realized that the current version of the c# target doesn't have tree filters.

 

I would like to create a scope tree, and push a local scope when I enter a block ("{" ), declare vars, resolve refs etc, in that scope, then pop the scope  when i leave the block("}") in accordance with the pattern.

 

In the absence of the filter capability, do I use the classical way of deriving a tree grammar from the lex/parser grammar (via rewrites)? I am working on this now and i seem to be able to recognize the BLOCK on the way down, but not on the way up (but that could just be my rule writing, i am a newbie).

 

Is this the right approach? 

 

any help/suggestions/experiences would be appreciated, thank-you.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090727/dc82fb7c/attachment.html 


More information about the antlr-interest mailing list