playground stuff

This commit is contained in:
Terence Parr 2012-11-18 09:57:05 -08:00
parent 468c791267
commit 3e5a976599
2 changed files with 34 additions and 4 deletions

View File

@ -1,7 +1,6 @@
grammar T;
s : A # X
| x
;
s : rule ;
A : C ;
rule : A # X
;

View File

@ -0,0 +1,31 @@
import org.antlr.v4.runtime.ANTLRInputStream;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.CommonTokenFactory;
import org.antlr.v4.runtime.CommonTokenStream;
import org.antlr.v4.runtime.DiagnosticErrorListener;
import org.antlr.v4.runtime.ParserRuleContext;
import java.io.FileInputStream;
import java.io.InputStream;
public class TransformEType {
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);
}
CharStream input = new ANTLRInputStream(is);
JavaLRLexer lex = new JavaLRLexer(input);
lex.setTokenFactory(new CommonTokenFactory(true));
CommonTokenStream tokens = new CommonTokenStream(lex);
JavaLRParser parser = new JavaLRParser(tokens);
parser.addErrorListener(new DiagnosticErrorListener());
ParserRuleContext tree = parser.compilationUnit();
}
}