[antlr-interest] aspectANTLR sketch

Bogdan Mitu bogdan_mt at yahoo.com
Wed Jun 19 03:38:03 PDT 2002


--- mzukowski at yci.com wrote:
> Pointcuts for inserting actions:
> 	rules
> 		initialization
> 		specific alternatives
> 		finalization
> 		exception handling
> 		tree construction
> 		options?

Yes, options: defaultErrorHandler, paraphrase ...
Not really actions, but in the same line: tailoring the parser for
particular usages, without any changes to the grammar itself.
Also for rules: return type, arguments.

> 	grammar
> 		header (includes variables and methods)

The package and import statements come before the class declaration,
variable and methods after. Unless the tool is very smart (and understands
all languages) I see the need for both a header and a code section for each
grammar.

> 		options
> extesions:
> 	tokens:
> 		regular tokens
> 		literal table
> 		tree node tokens (so called imaginary tokens)
> 	rules:
> 		adding alternatives
>
> It seems like some concept of a grammar namespace would be appropriate if
> we
> are serious about composing a grammar from multiple rule sets.  Likewise
> token management could improve through composition.
> 
> Proof of concept for some of this should be possible through a
> preprocessor.
> I would write:
> 
> 1. an antlr parser that parses .g files without actions (and without
> grammar
> subclassing for simplicity)

A very simple solution (that I used) is to remove actions from antlr.g, set
buildAST to true and replace all (rule)? with:

rule: ....
    | /*nothing*/ { ## = [DUMMY_NODE_<RULE>,"", ##).

so that the parser produces a flat list of tokens (AST, of course) with all
potential insertion points existing (some of them with empty text). Then I
use a tree parser (which is identical to the parser, due to the flat list)
with function calls when potential insertion points are reached. The
functions called would look in a HashMap to see if something is defined for
the current point. If yes, the text of the current AST is set to the value
of the key in the HashMap. Insertion points for which nothing is defined
will remain with empty text, so in the end all I have to do is to print the
AST chain in order.

Bogdan



> 2. an aspectANTLR parser and weaver that would parse some sort of aspect
> syntax for recognizing the above pointcuts and would generate a .g file
> with
> actions for input to ANTLR.  It would also allow an extension syntax
> similar
> to Metamorphic Syntactic Macros to extend the grammar, but wouldn't have
> any
> fancy analysis.
> 
> It wouldn't have any hooks for the code generation stuff, but would at
> least
> be a proof of concept for handling actions and extensions for grammars. 
> It
> would be nice for refactoring the GCC grammar too.  
> 
> Anything I'm forgetting?
> 
> Monty
> 
>  
> 
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 
> 
> 
> 




__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list