Antlr’s testRig
spits out Lisp
trees which are nice, but so are ASCII trees. Here’s an example:
Build:
$ clone https://github.com/venkatperi/antlr-testrig
$ cd antlr-testrig
$ ./gradlew build #creates JAR in build/libs
Usage (like grun
):
$ CLASSPATH = :/path/to/above/jar:$CLASSPATH:
$ java org.antlr.v4.gui2.TestRig2 <grammar> <start rule> -tree input-file(s)
From the examples.
Input
y=x^1+2
Lisp Tree
(equation (expression (multiplyingExpression (powExpression (atom (variable y)))))
(relop =) (expression (multiplyingExpression (powExpression (atom (variable x)) ^
(atom (scientific (number 1))))) + (multiplyingExpression (powExpression (atom
(scientific (number 2)))))))
ASCII Tree
└─equation
├─expression
│ └─multiplyingExpression
│ └─powExpression
│ └─atom
│ └─variable
│ └─[LETTER] y
├─relop
│ └─[EQ] =
└─expression
├─multiplyingExpression
│ └─powExpression
│ ├─atom
│ │ └─variable
│ │ └─[LETTER] x
│ ├─[POW] ^
│ └─atom
│ └─scientific
│ └─number
│ └─[DIGIT] 1
├─[PLUS] +
└─multiplyingExpression
└─powExpression
└─atom
└─scientific
└─number
└─[DIGIT] 2