Posted By:
James_Cerra
Posted On:
Tuesday, March 15, 2005 06:01 PM
I have a grammar that I broke up into two parts so it is easier to write. I wrote a lexer ("PatternLexer") and a parser ("PatternParser") for the first one and a lexer ("URILexer") and a parser ("URIParser") for the container grammar. I wanted to put the AST from the `Pattern` grammar as a child in the `URI` grammar. Eventually I came up with the following: rootExpr : (URIEXPR | patternExpr)* ; patternExpr : USEP! { PatternParser patternParser = new PatternParser(getInputState()); patternParser.rootExpr(); currentAST.root = patternParser.getAST(); } ; That seems to work; however, I am concerned about how much of a hack it seems to be. The v
More>>
I have a grammar that I broke up into two parts so it is easier to write. I wrote a lexer ("PatternLexer") and a parser ("PatternParser") for the first one and a lexer ("URILexer") and a parser ("URIParser") for the container grammar. I wanted to put the AST from the `Pattern` grammar as a child in the `URI` grammar. Eventually I came up with the following:
rootExpr : (URIEXPR | patternExpr)* ;
patternExpr : USEP! {
PatternParser patternParser = new PatternParser(getInputState());
patternParser.rootExpr();
currentAST.root = patternParser.getAST();
} ;
That seems to work; however, I am concerned about how much of a hack it seems to be. The variable `currentAST` is generated by Antlr and doesn't seem to be well documented. Also I don't like modifying automatically generated variables like this in case the next implementation of Antlr changes variables. (I'd rather use a documented method of Antlr's API.)
So, are my concerns unfounded? (I hope so.) Is there another way of making the AST generated from `PatternParser` a child of `patternExpr`?
P.S: I'm very new to Antlr - this is my first grammar and I've used Antlr for less than a week - so please excuse any faux pas by me (and explain it too).
<<Less