public void ParseClojure() { var inputStream = new AntlrInputStream("(def lst '(a b c))"); var lexer = new ClojureLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new ClojureParser(commonTokenStream); var visitor = new CstBuilderForAntlr4(parser); visitor.Visit(parser.file()); Console.WriteLine(visitor.FinishParsing()); }
public void Test() { var inputStream = new AntlrInputStream("public /*aa*/ class Klass { }"); var javaLexer = new JavaLexer(inputStream); var commonTokenStream = new CommonTokenStream(javaLexer); var javaParser = new JavaParser(commonTokenStream); var context = javaParser.compilationUnit(); var visitor = new CstBuilderForAntlr4(javaParser); visitor.Visit(context); Console.WriteLine(visitor.FinishParsing().ToXml()); }
public void ParseC() { var inputStream = new AntlrInputStream(@" int main(int argc, char **args) { printf(args[0]); return 0; }"); var lexer = new CLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new CParser(commonTokenStream); var visitor = new CstBuilderForAntlr4(parser); visitor.Visit(parser.compilationUnit()); Console.WriteLine(visitor.FinishParsing()); }
public void ParseR() { var inputStream = new AntlrInputStream(@" x <- 1:3 y <- 2:4 z <- call('plot', x, y) eval(z) "); var lexer = new RLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new RParser(commonTokenStream); var visitor = new CstBuilderForAntlr4(parser); visitor.Visit(parser.prog()); Console.WriteLine(visitor.FinishParsing()); }
public void ParseObjectiveC() { var inputStream = new AntlrInputStream( @"@interface MyObject : NSObject { int val; id obj; } + (void)classMethod:(id)arg; - (id)method:(NSObject*)arg1 with:(int)arg2; @end"); var lexer = new ObjectiveCLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new ObjectiveCParser(commonTokenStream); var visitor = new CstBuilderForAntlr4(parser); visitor.Visit(parser.translationUnit()); Console.WriteLine(visitor.FinishParsing()); }
public void ParseJava() { var inputStream = new AntlrInputStream(@" import javax.swing.*; public class Hello extends JFrame { Hello() { setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); pack(); } public static void main(String[] args) { new Hello().setVisible(true); } }"); var lexer = new JavaLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new JavaParser(commonTokenStream); var visitor = new CstBuilderForAntlr4(parser); visitor.Visit(parser.compilationUnit()); Console.WriteLine(visitor.FinishParsing()); }
public void ParseVerilog2001() { var inputStream = new AntlrInputStream(@" module generate_example(); reg read,write = 0; reg [31:0] data_in = 0; reg [3:0] address = 0; wire [31:0] data_out; initial begin $monitor ($time, read, write, address, data_in, data_out); #1 read = 0; // why only for read #3 repeat (16) begin data_in = $random; write = 1; #1 address = address + 1; end write = 0; address = 0; #3 repeat (16) begin read = 1; #1 address = address + 1; end read = 0; #1 $finish; end endmodule "); var lexer = new Verilog2001Lexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new Verilog2001Parser(commonTokenStream); var visitor = new CstBuilderForAntlr4(parser); visitor.Visit(parser.source_text()); Console.WriteLine(visitor.FinishParsing()); }
public void ParseLua() { var inputStream = new AntlrInputStream(@" do local t = {} t[f(1)] = g t[1] = 5 -- 1st exp t[2] = 2 -- 2nd exp t.x = 1 t[3] = f(x) -- 3rd exp t[30] = 23 t[4] = 45 -- 4th exp a = t end "); var lexer = new LuaLexer(inputStream); var commonTokenStream = new CommonTokenStream(lexer); var parser = new LuaParser(commonTokenStream); var visitor = new CstBuilderForAntlr4(parser); visitor.Visit(parser.chunk()); Console.WriteLine(visitor.FinishParsing()); }