Skip to content

venkatperi/antlr-testrig

Repository files navigation

Antlr’s TestRig with ASCII Trees

Antlr’s testRig spits out Lisp trees which are nice, but so are ASCII trees. Here’s an example:

Usage

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)

Calculator Grammar

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

About

ASCII tree output from Antlr TestRig

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages