Created
December 2, 2014 14:37
-
-
Save GaryPickrell/06f4ae5d6e4a5d7596c7 to your computer and use it in GitHub Desktop.
Code for Antlr problem
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 org.antlr.v4.runtime.*; | |
import org.antlr.v4.runtime.tree.*; | |
import java.io.FileInputStream; | |
import java.io.InputStream; | |
public class Main { | |
public static void main(String[] args) throws Exception { | |
String expression = "hello parr"; | |
ANTLRInputStream input = new ANTLRInputStream(expression); | |
PreParseLexer lexer = new PreParseLexer(input); | |
CommonTokenStream tokens = new CommonTokenStream(lexer); | |
PreParseParser parser = new PreParseParser(tokens); | |
ParseTree tree = parser.r(); | |
} | |
} |
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
grammar PreParse; | |
import PreParseLex; | |
r: 'hello' ID; |
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
lexer grammar PreParseLex; | |
ID: [a-z]+; | |
WS: [ \t\r\n]+ -> skip ; |
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
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.IO; | |
using Antlr4.Runtime; | |
using Antlr4.Runtime.Misc; | |
using Antlr4.Runtime.Tree; | |
namespace PreparseApp | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string expression = "hello parr"; | |
AntlrInputStream input = new AntlrInputStream(expression); | |
PreParseLex lexer = new PreParseLex(input); | |
CommonTokenStream tokens = new CommonTokenStream(lexer); | |
PreParseParser parser = new PreParseParser(tokens); | |
IParseTree tree = parser.r(); | |
Console.WriteLine("Done"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment