[antlr-interest] detecting scope

rkevinburton at charter.net rkevinburton at charter.net
Sat Aug 2 13:44:37 PDT 2008


I would like to implement a grammar that basically does what languages like C++ and C# do. They "know" about the context. For example within a classit is perfectly legal to have a statement like: private 'int a;'. But within a function the 'private' is not allowed. C++ allows 'static' with in a function (local) but C# does not. When defining a function within a class it is just another function (method) unless it is the same name as the enclosing class then it is a constructor. Etc. Using ANTLR how do I "detect" the "context" in which a statement is evaluated in. My first incination would be to define some variable when entering such an environment then recognize using that and the current tokens to fully parse the stream. But I was wondering if there was a better way. Maybe if I knew how to access the AST tree within a custom action I could "walk" up the tree to detect the environment? Any suggestions?

Thank you.

Kevin


More information about the antlr-interest mailing list