Skip to content

Instantly share code, notes, and snippets.

@GaryPickrell
Created December 2, 2014 14:37
Show Gist options
  • Save GaryPickrell/06f4ae5d6e4a5d7596c7 to your computer and use it in GitHub Desktop.
Save GaryPickrell/06f4ae5d6e4a5d7596c7 to your computer and use it in GitHub Desktop.
Code for Antlr problem
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();
}
}
grammar PreParse;
import PreParseLex;
r: 'hello' ID;
lexer grammar PreParseLex;
ID: [a-z]+;
WS: [ \t\r\n]+ -> skip ;
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