public static void Main(string[] args) { if (args.Length == 1) { string fullpath; if ( Path.IsPathRooted(args[0]) ) fullpath = args[0]; else fullpath = Path.Combine(Environment.CurrentDirectory, args[0]); Console.Out.WriteLine("Processing file: {0}", fullpath); ICharStream input = new ANTLRFileStream(fullpath); LangLexer lex = new LangLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); LangParser parser = new LangParser(tokens); //LangParser.decl_return r = parser.decl(); LangParser.start_return r = parser.start(); Console.Out.WriteLine("tree: "+((ITree)r.Tree).ToStringTree()); CommonTree r0 = ((CommonTree)r.Tree); CommonTreeNodeStream nodes = new CommonTreeNodeStream(r0); nodes.TokenStream = tokens; LangDumpDecl walker = new LangDumpDecl(nodes); walker.decl(); } else Console.Error.WriteLine("Usage: TreeParser <input-file>"); }
/// <summary> /// Parses input stream to tokens and then according to CSS grammar. /// </summary> /// <param name="inp">file name of input stream.</param> public void Parse(string inp) { string fullpath; if (Path.IsPathRooted(inp)) fullpath = inp; else fullpath = Common.PathCombine(Environment.CurrentDirectory, inp); ICharStream input = new ANTLRFileStream(fullpath, Encoding.UTF8); csst3Lexer lex = new csst3Lexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); csst3Parser parser = new csst3Parser(tokens); // return results as parameters try { Root = (CommonTree)parser.stylesheet().Tree; Errors = parser.GetErrors(); } catch (Exception) { Errors = parser.GetErrors(); throw; } }
public static void Main(string[] args) { if (args.Length == 1) { string fullpath; if ( Path.IsPathRooted(args[0]) ) fullpath = args[0]; else fullpath = Path.Combine(Environment.CurrentDirectory, args[0]); Console.Out.WriteLine("Processing file: {0}", fullpath); ICharStream input = new ANTLRFileStream(fullpath); SimpleCLexer lex = new SimpleCLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); SimpleCParser parser = new SimpleCParser(tokens); SimpleCParser.program_return r = parser.program(); Console.Out.WriteLine("tree="+((ITree)r.Tree).ToStringTree()); if ( parser.NumberOfSyntaxErrors > 0 ) { // don't tree parse if has errors return; } CommonTreeNodeStream nodes = new CommonTreeNodeStream((ITree)r.Tree); nodes.TokenStream = tokens; SimpleCWalker walker = new SimpleCWalker(nodes); walker.program(); } else Console.Error.WriteLine("Usage: SimpleC <input-file>"); }
public Lexer(string fileName) { Antlr.Runtime.ANTLRFileStream fileStream = new Antlr.Runtime.ANTLRFileStream(fileName); MiniJavaLexer lexer = new MiniJavaLexer(fileStream); TokenStream = new Antlr.Runtime.CommonTokenStream(lexer); //SaveToFile("lexer1.txt"); }
private static CommonTree GetAst(FileInfo file) { var v = new ANTLRFileStream(file.FullName); var lex = new vguiLexer(v); var cts = new CommonTokenStream(lex); var prs = new vguiParser(cts) {TreeAdaptor = new CommonTreeAdaptor()}; return (CommonTree) prs.start().Tree; }
private static void ApiGen(string protoFile, string shimTemplate) { ANTLRFileStream input = new ANTLRFileStream(protoFile); FuncProtoToShimLexer lex = new FuncProtoToShimLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); FuncProtoToShimParser parser = new FuncProtoToShimParser(shimTemplate, tokens); parser.TraceDestination = Console.Error; parser.list(); System.Console.WriteLine(parser.ToISystemAPI()); }
public static void Main(string[] args) { // Use a try/catch block for parser exceptions try { string inputFileName; string templateFileName; if ((args.Length == 1) || (args.Length == 2)) { if (args.Length == 1) { templateFileName = "Java.stg"; inputFileName = args[0]; } else { templateFileName = args[0]; inputFileName = args[1]; } // Ensure full pathnames if (!Path.IsPathRooted(templateFileName)) { //templateFileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, templateFileName); templateFileName = Path.Combine(Environment.CurrentDirectory, templateFileName); } if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } templates = new StringTemplateGroup(new StreamReader(templateFileName), typeof(AngleBracketTemplateLexer)); ICharStream input = new ANTLRFileStream(inputFileName); CMinusLexer lexer = new CMinusLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); CMinusParser parser = new CMinusParser(tokens); parser.TemplateLib = templates; RuleReturnScope r = parser.program(); Console.Out.WriteLine(r.Template.ToString()); } else Console.Error.WriteLine("Usage: cminus [<output-template-file>] <input-file>"); } catch (System.Exception e) { Console.Error.WriteLine("exception: " + e); Console.Error.WriteLine(e.StackTrace); // so we can get stack trace } }
public static void Main(string[] args) { ICharStream input = new ANTLRFileStream(args[0]); SpicaMLLexer lex = new SpicaMLLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); SpicaMLParser parser = new SpicaMLParser(tokens); SpicaMLParser.model_return r = parser.model(); ITree t = (ITree)r.Tree; // Console.Out.WriteLine(t.ToStringTree()); DOTTreeGenerator gen = new DOTTreeGenerator(); StringTemplate st = gen.ToDOT(t); Console.Out.WriteLine(st); }
public static void Main(string[] args) { if (args.Length > 0) { ICharStream input = new ANTLRFileStream(args[0]); SimpleLexer lex = new SimpleLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); SimpleParser parser = new SimpleParser(tokens); parser.program(); } else Console.Error.WriteLine("Usage: island <input-file>"); }
public static void Main(string[] args) { ANTLRFileStream input = new ANTLRFileStream ("test.cpp"); cvartrackerLexer lexer = new cvartrackerLexer (input); CommonTokenStream stream = new CommonTokenStream (lexer); cvartrackerParser parser = new cvartrackerParser (stream); parser.greet (); Console.WriteLine ("The collected names are:"); foreach (string name in parser.Names) Console.WriteLine (name); }
private SourceEval createWalker(string file) { ANTLRFileStream stream = new ANTLRFileStream(file); SourceExprLexer lex = new SourceExprLexer(stream); CommonTokenStream tokens = new CommonTokenStream(lex); SourceExprParser parser = new SourceExprParser(tokens); SourceExprParser.prog_return r = parser.prog(_script); // WALK RESULTING TREE CommonTree t = (CommonTree)r.Tree; // get tree from parser // Create a tree node stream from resulting tree CommonTreeNodeStream nodes = new CommonTreeNodeStream(t); SourceEval walker = new SourceEval(nodes); // create a tree parser return walker; }
static void Main(string[] args) { ANTLRFileStream fs = new ANTLRFileStream("input.txt"); cLexer lxr = new cLexer(fs); CommonTokenStream cts = new CommonTokenStream(lxr); cParser psr = new cParser(cts); ITree tree = (ITree)psr.execute().Tree; AstNodePrinter.Print(tree); //Interpreter interpreter = new Interpreter(); //interpreter.Program(tree); Console.ReadKey(); }
public static void Main(string[] args) { if (args.Length == 1) { ICharStream input = new ANTLRFileStream(args[0]); TLexer lex = new TLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); //System.out.println("tokens="+tokens); TParser parser = new TParser(tokens); parser.stat(); } else Console.Error.WriteLine("Usage: hoisted <input-file>"); }
// アスペクトファイルを解析してその結果をフィールドに格納します public static void AnalizeAspect(string aspectPath) { //アスペクト情報を持つオブジェクトを生成する var aspect = new ANTLRFileStream(aspectPath); var lexer = new UniAspectLexer(aspect); var tokens = new CommonTokenStream(lexer); var parser = new UniAspectParser(tokens); //アスペクトファイルを解析してASTを生成する var result = parser.aspect(); var ast = (CommonTree)result.Tree; //ASTを走査してパース結果をアスペクトオブジェクトとしてvisitor内に格納する _visitor = new AstVisitor(); _visitor.Visit(ast, 0, null); }
public static void Main(string[] args) { if (args.Length > 0) { ICharStream input = new ANTLRFileStream(args[0]); PythonLexer lexer = new MyLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); PythonTokenSource indentedSource = new PythonTokenSource(tokens); tokens = new CommonTokenStream(indentedSource); //Console.Out.WriteLine("tokens="+tokens.GetTokens()); PythonParser parser = new PythonParser(tokens); parser.file_input(); } else Console.Error.WriteLine("Usage: dynscope <input-file>"); }
public void SetUp() { //アスペクトファイルのパスを取得 var input = new ANTLRFileStream(FixtureUtil.GetAspectPath("simple_advice_sample.apt")); //アスペクトファイルをパースして抽象構文木を生成する var lex = new UniAspectLexer(input); var tokens = new CommonTokenStream(lex); var parser = new UniAspectParser(tokens); var result = parser.aspect(); var ast = (CommonTree)result.Tree; //抽象構文木を走査して、ポイントカット・アドバイス情報を格納する _visitor = new AstVisitor(); _visitor.Visit(ast, 0, null); }
public static void Main(string[] args) { if (args.Length > 0) { string inputFileName = args[0]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); SymtabTestLexer lex = new SymtabTestLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); SymtabTestParser parser = new SymtabTestParser(tokens); parser.prog(); } else Console.Error.WriteLine("Usage: scopes <input-file>"); }
private static void _Main(string[] args) { // input "x = 2*(3+3)" ICharStream input; if (args.Length > 0) { if (args[0].Equals("-i")) { if (args.Length > 1) { input = new ANTLRFileStream(args[1]); } else { throw new Exception("No input file specified."); } } else { input = new ANTLRStringStream(args[0]); } } else { input = new ANTLRInputStream(Console.OpenStandardInput()); } var lex = new VecMathLexer(input); var tokens = new CommonTokenStream(lex); var g = new VecMathParser(tokens); IAstRuleReturnScope<CommonTree> r = g.prog(); CommonTree t = r.Tree; Console.WriteLine("Original tree: " + t.ToStringTree()); var simplify = new Simplify(new CommonTreeNodeStream(t)); t = (CommonTree)simplify.Downup(t); var reduce = new Reduce(new CommonTreeNodeStream(t)); t = (CommonTree)reduce.Downup(t); Console.WriteLine("Simplified tree: " + t.ToStringTree()); Console.ReadKey(); }
static void Main(string[] args) { bool archivoEncontrado = true; do { try { archivoEncontrado = true; Console.WriteLine("Ruta de archivo fuente a reconocer: "); ANTLRStringStream input = new ANTLRFileStream(Console.In.ReadLine()); ReptileLexer lex = new ReptileLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); ReptileParser parser = new ReptileParser(tokens); try { parser.program(); Console.WriteLine("Apropiado.\n"); } catch (SemanticException e) { Console.WriteLine(e.ToString()); Console.WriteLine("No apropiado.\n"); } catch(RecognitionException ex) { StringBuilder errorMsg = new StringBuilder("ERROR DE LEXICO O SINTAXIS: "); errorMsg.Append("\nlinea: " + ex.Line); //errorMsg.Append("\nposicion: " + ex.CharPositionInLine); errorMsg.Append("\nNo apropiado."); Console.WriteLine(errorMsg); } catch(Exception e) { Console.WriteLine("ERROR ENCONTRADO: " + e.ToString()); } } catch (Exception fnfe) { archivoEncontrado = false; Console.WriteLine("No se puede leer archivo, verifique la ruta proporcionada.\n"); } } while (!archivoEncontrado); Console.In.ReadLine(); }
public static void Main(string[] args) { if (args.Length > 0) { string inputFileName = args[0]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); TLexer lex = new TLexer(input); ITokenStream tokens = new TokenRewriteStream(lex); TParser parser = new TParser(tokens); parser.program(); Console.Out.WriteLine(tokens); } else Console.Error.WriteLine("Usage: tweak <input-file>"); }
public static void Main(string[] args) { if (args.Length == 1) { string inputFileName = args[0]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); TLexer lex = new TLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); //System.out.println("tokens="+tokens); TParser parser = new TParser(tokens); parser.program(); } else Console.Error.WriteLine("Usage: dynscope <input-file>"); }
static string createRewriter(string file, Script script) { ANTLRFileStream stream = new ANTLRFileStream(file); SourceExprLexer lex = new SourceExprLexer(stream); // create a buffer of tokens pulled from the lexer // Must use TokenRewriteStream not CommonTokenStream! TokenRewriteStream tokens = new TokenRewriteStream(lex); SourceExprParser parser = new SourceExprParser(tokens); SourceExprParser.prog_return r = parser.prog(script); // WALK TREE AND REWRITE TOKEN BUFFER CommonTree t = (CommonTree)r.Tree; // get tree from parser // create a stream of tree nodes from AST built by parser CommonTreeNodeStream nodes = new CommonTreeNodeStream(t); // tell it where it can find the token objects nodes.TokenStream = tokens; //SourceRewrite rewriter = new SourceRewrite(nodes); //rewriter.prog(script); return tokens.ToString(); // return tweaked token buffer }
public static void Main(string[] args) { try { if (args.Length < 1) { System.Console.WriteLine("Usage : JSMinus file"); return; } ICharStream input = new ANTLRFileStream(args[0]); JSMinusLexer lexer = new JSMinusLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); JSMinusParser parser = new JSMinusParser(tokens); CodeEmitor emitor = new CodeEmitor("JSMinus", parser.program()); emitor.save(); emitor.run(); } catch (System.Exception e) { Console.Error.WriteLine(e.StackTrace); Console.Error.WriteLine("Exception: " + e); } }
static void Main(string[] args) { if (args.Length == 2) { Antlr.Runtime.ANTLRFileStream inStream = new Antlr.Runtime.ANTLRFileStream(args[0]); testLexer lexer = new testLexer(inStream); Emitter emitter = new Emitter(); Antlr.Runtime.CommonTokenStream tokenStream = new Antlr.Runtime.CommonTokenStream(lexer); testParser parser = new testParser(tokenStream, emitter); //вызываем разбор правил programm parser.program(); emitter.SaveMSIL(args[1]); } else { Console.WriteLine("usege: <program> <inputfile> <outputfile>"); Console.ReadKey(); } }
public static void Main(string[] args) { var inputFile = args[0]; var outputFile = args[2]; var antlrStringStream = new ANTLRFileStream(inputFile); var lexter = new CFlatLexer(antlrStringStream); var tokens = new CommonTokenStream(lexter); var parser = new CFlatParser(tokens); var tree = parser.prog().Tree; var nodes = new CommonTreeNodeStream(tree); var walker = new CFlatTree(nodes, new ErrorSet()); var prog = walker.prog(); var context = new CompilerContext(new ClrCodeGenerator(outputFile), new ErrorSet()); prog.Compile(context); context.Save(true); }
private static void Debug() { string[] files = Directory.GetFiles(@"C:\HERE\School\!4to\Complementos de Compilacion\Compilador\Test cases\Others", "*.tig"); syntax_error = new List<string>(); syntax_error.Add("appel_test49.tig"); syntax_error.Add("comment_not_ended_before_program.tig"); syntax_error.Add("break_out_of_for"); //No ponen nada dentro del let-in int errorsCount = 0; foreach (string file in files) { if (HasSyntaxError(file)) { continue; } // Console.WriteLine(string.Format("Testing file: {0}", file)); var input = new ANTLRFileStream(file); var lexer = new TigerLexer(input); var tokens = new CommonTokenStream(lexer); var parser = new TigerParser(tokens); ExpressionNode x = parser.prog(); if (parser.Errors.Count > 0) { Console.WriteLine(string.Format("Error in file: {0}", file)); errorsCount++; foreach (string error in parser.Errors) { Console.WriteLine(string.Format("Error: {0}", error)); } // Console.ReadLine(); } // else // { // Console.WriteLine("OK!"); // } } Console.WriteLine(string.Format("Done. Errors: {0}", errorsCount)); Console.ReadLine(); }
public static void Main(string[] args) { if (args.Length == 1) { string fullpath; if ( Path.IsPathRooted(args[0]) ) fullpath = args[0]; else fullpath = Path.Combine(Environment.CurrentDirectory, args[0]); Console.Out.WriteLine("Processing file: {0}", fullpath); ICharStream input = new ANTLRFileStream(fullpath); SimpleCLexer lex = new SimpleCLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); //System.out.println("tokens="+tokens); SimpleCParser parser = new SimpleCParser(tokens); parser.program(); Console.Out.WriteLine("Finished processing file: {0}", fullpath); } else Console.Error.WriteLine("Usage: llstar <input-filename>"); }
public static void Main(string[] args) { if (args.Length > 1) { string inputFileName = args[0]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); // BUILD AST ANTLRv3Lexer lex = new ANTLRv3Lexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); ANTLRv3Parser g = new ANTLRv3Parser(tokens); ANTLRv3Parser.grammarDef_return r = g.grammarDef(); CommonTree t = (CommonTree)r.Tree; System.Console.Out.WriteLine(t.ToStringTree()); /* // BUILD AST + PARSE TREES (needs ANTLR -debug option) ANTLRv3Lexer lex = new ANTLRv3Lexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); ParseTreeBuilder builder = new ParseTreeBuilder(inputName); ANTLRv3Parser g = new ANTLRv3Parser(tokens, builder); ANTLRv3Parser.grammarDef_return r = g.grammarDef(); CommonTree t = (CommonTree)r.Tree; // not used here System.Console.Out.WriteLine("parse tree: "+builder.Tree.ToStringTree()); System.Console.Out.Write("input:\n"+builder.Tree.ToInputString()); */ // WALK AST CommonTreeNodeStream nodes = new CommonTreeNodeStream(t); ANTLRv3Tree walker = new ANTLRv3Tree(nodes); walker.grammarDef(); } else Console.Error.WriteLine("Usage: ANTLRv3 <input-file>"); }
public static void Main(string[] args) { if (args.Length > 0 ) { for (int i = 0; i < args.Length; i++) { string inputFileName = args[i]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); FuzzyJava lex = new FuzzyJava(input); ITokenStream tokens = new CommonTokenStream(lex); tokens.ToString(); //System.out.println(tokens); } } else Console.Error.WriteLine("Usage: fuzzy <input-file-list>"); }
public static void Main(string[] args) { if (args.Length > 0) { try { string inputFileName = args[0]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); XML lexer = new XML(input); while (lexer.NextToken() != Token.EOF_TOKEN) ; } catch (Exception ex) { Console.Out.WriteLine("exception: " + ex); Console.Out.WriteLine(ex.StackTrace); } } else Console.Error.WriteLine("Usage: xmlLexer <input-file>"); }
public static void Main(string[] args) { if (args.Length > 0) { string inputFileName = args[0]; if (!Path.IsPathRooted(inputFileName)) { inputFileName = Path.Combine(Environment.CurrentDirectory, inputFileName); } ICharStream input = new ANTLRFileStream(inputFileName); CLexer lex = new CLexer(input); CommonTokenStream tokens = new CommonTokenStream(lex); CParser parser = new CParser(tokens); try { parser.translation_unit(); } catch(RecognitionException re) { Console.Out.WriteLine(re.StackTrace); } } else Console.Error.WriteLine("Usage: cparse <input-file>"); }
public static MAst CompileFile(AstHelper runtime, string fileName) { var stream = new ANTLRFileStream(fileName); return Compile(runtime, stream); }