Created
February 17, 2017 16:35
-
-
Save imjching/9d70ba6ff5c0d16c1955c727b2640819 to your computer and use it in GitHub Desktop.
TestLexer.java
This file contains 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
import java.io.File; | |
import java.io.FileInputStream; | |
import org.antlr.v4.runtime.ANTLRInputStream; | |
import org.antlr.v4.runtime.Token; | |
public class TestLexer { | |
public static void main(String[] args) throws Exception { | |
System.out.println("Parsing: " + args[0]); | |
FileInputStream fis = new FileInputStream(new File(args[0])); | |
ANTLRInputStream input = new ANTLRInputStream(fis); | |
ScriptLexer lexer = new ScriptLexer(input); | |
Token token = lexer.nextToken(); | |
while (token.getType() != ScriptLexer.EOF) { | |
System.out.println("\t" + getTokenType(token.getType()) + "\t\t" + token.getText()); | |
token = lexer.nextToken(); | |
} | |
} | |
private static String getTokenType(int tokenType) { | |
switch (tokenType) { | |
case ScriptLexer.STRING: | |
return "STRING"; | |
case ScriptLexer.LPAREN: | |
return "LPAREN"; | |
case ScriptLexer.RPAREN: | |
return "RPAREN"; | |
case ScriptLexer.EQUALS: | |
return "EQUALS"; | |
case ScriptLexer.SEMICO: | |
return "SEMICO"; | |
case ScriptLexer.ASSIGN: | |
return "ASSIGN"; | |
default: | |
return "OTHER"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment