[antlr-interest] unbalanced parenthesis
yushang
yusunn at gmail.com
Fri Nov 11 21:45:18 PST 2011
Hi everyone,
I'm writing following code to test the ANTLRParser AST
import java.util.List;
import org.antlr.runtime.*;
import org.antlr.runtime.tree.*;
import org.antlr.grammar.v3.*;
import org.antlr.tool.*;
//javac -classpath E:\SRC\ANTLR\antlr-3.4-complete.jar;. ANTLRTest.java
//java -classpath E:\SRC\ANTLR\antlr-3.4-complete.jar;. ANTLRTest
public class ANTLRTest
{
public static void main(String args[])
{
testANTLRParser();
}
public static void testANTLRParser()
{
try
{
ANTLRParser.grammar__return rt;
ANTLRFileStream fs = new ANTLRFileStream("ANTLR.g");
ANTLRLexer lex = new ANTLRLexer(fs);
CommonTokenStream token = new CommonTokenStream(lex);
ANTLRParser par = ANTLRParser.createParser(token);
Grammar gmr = new Grammar();
gmr.setFileName("ANTLR.g");
rt = par.grammar_(gmr);
GrammarAST t =(GrammarAST)rt.getTree();
System.out.println( t.toStringTree());
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
when I'm trying to indent the tree I find the parenthesis unbalanced in
following text
...
(rule
grammar_ public (ARG Grammar g) RET scope
(@ init this.grammar = g; Map<String, Object> opts;)
(@ after cleanup( $tree );)
(BLOCK
(ALT
(? (BLOCK (ALT ACTION <end-of-alt>) <end-of-block>))
(? (BLOCK (ALT (= cmt DOC_COMMENT) <end-of-alt>)
<end-of-block>))
(= gr grammarType)
(= gid id) grammar.setName($gid.text); SEMI
(? (BLOCK (ALT optionsSpec opts = $optionsSpec.opts;
grammar.setOptions(opts, $optionsSpec.start); <end-of-alt>)
<end-of-block>))
(? (BLOCK (ALT (= ig delegateGrammars) <end-of-alt>)
<end-of-block>))
(? (BLOCK (ALT (= ts tokensSpec) <end-of-alt>) <end-of-block>))
(= scopes attrScopes)
(? (BLOCK (ALT (= a actions) <end-of-alt>) <end-of-block>))
(= r rules)
EOF
<end-of-alt>)
(REWRITES
(-> (ALT (^( gr gid
(? (BLOCK (ALT cmt <end-of-alt>)
<end-of-block>))
(? (BLOCK (ALT optionsSpec <end-of-alt>)
<end-of-block>))
(? (BLOCK (ALT ig <end-of-alt>)
<end-of-block>))
(? (BLOCK (ALT ts <end-of-alt>)
<end-of-block>))
(? (BLOCK (ALT scopes <end-of-alt>)
<end-of-block>))
(? (BLOCK (ALT a <end-of-alt>) <end-of-block>))
r) <end-of-alt>)))
<end-of-block>) <end-of-rule>)
...
the last parenthesis does not match with the first one but the parenthesis
before the first BLOCK . Could someone verify this for me ? Many thanks.
More information about the antlr-interest
mailing list