Created
April 7, 2014 18:10
-
-
Save RubenCordeiro/10026125 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** | |
* Excerpted from "The Definitive ANTLR 4 Reference", | |
* published by The Pragmatic Bookshelf. | |
* Copyrights apply to this code. It may not be used to create training material, | |
* courses, books, articles, and the like. Contact us if you are in doubt. | |
* We make no guarantees that this code is fit for any purpose. | |
* Visit http://www.pragmaticprogrammer.com/titles/tpantlr2 for more book information. | |
***/ | |
import org.antlr.v4.runtime.*; | |
import org.antlr.v4.runtime.tree.ParseTree; | |
import java.io.FileInputStream; | |
import java.io.InputStream; | |
public class Calc { | |
public static void main(String[] args) throws Exception { | |
String inputFile = null; | |
if ( args.length>0 ) inputFile = args[0]; | |
InputStream is = System.in; | |
if ( inputFile!=null ) is = new FileInputStream(inputFile); | |
ANTLRInputStream input = new ANTLRInputStream(is); | |
LabeledExprLexer lexer = new LabeledExprLexer(input); | |
CommonTokenStream tokens = new CommonTokenStream(lexer); | |
LabeledExprParser parser = new LabeledExprParser(tokens); | |
ParseTree tree = parser.prog(); // parse | |
EvalVisitor eval = new EvalVisitor(); | |
eval.visit(tree); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment