public override void printNode(ASTPrinter p) { string opString = op.ToString(); p.printText("op", opString); p.print("value", value); }
public override void printNode(ASTPrinter p) { p.print("initialization", initialization); p.print("condition", condition); p.print("increment", increment); p.print("Body", body); }
public override void printNode(ASTPrinter p) { p.print("RetType", retType); p.print("Name", name); p.printList("Parameters", parameters); p.print("Body", body); }
public override void printNode(ASTPrinter p) { p.print("Condition", condition); p.print("Body", body); p.printList("ElifBody", elif); p.print("ElseBody", elseBody); }
public override void printNode(ASTPrinter p) { string opString = op.ToString(); p.printText("op", opString); p.print("left", left); p.print("right", right); }
public override void printNode(ASTPrinter p) { string opkind = op.ToString(); p.printText("op", opkind); p.print("left", var); p.print("right", value); }
private static File BuildFileCFGAndExtractFileInformation(KeyValuePair <string, XmlDocument> parsedFile) { var traverser = new XmlTraverser(); var metricAnalyzer = new MetricVisitor(); var extractor = new ClassAndFunctionExtractor(); var printer = new ASTPrinter(Console.Out); var cfgcreator = new CFGCreator(); traverser.AddVisitor(extractor); traverser.AddVisitor(metricAnalyzer); traverser.AddVisitor(cfgcreator); //traverser.AddVisitor(printer); traverser.AddVisitors(_components.AstVisitors.ToArray()); traverser.Traverse(parsedFile.Value.FirstChild.NextSibling); foreach (var function in extractor.Functions) { function.File = parsedFile.Key; } foreach (var closure in extractor.Closures) { closure.File = parsedFile.Key; } _funcHandler.CustomFunctions.AddRange(extractor.Functions); foreach (var @class in extractor.Classes) { @class.File = parsedFile.Key; foreach (var method in @class.Methods) { //HACK: This is not a good way to handle this! Should we add a new derived function class called method that includes the class name //-||-: and make a special list for them in the function handler, or is this okay? method.Name = @class.Name + "->" + method.Name; method.File = parsedFile.Key; _funcHandler.CustomFunctions.Add(method); } } //cfgcreator.Graph.VisualizeGraph("graph", Program.Configuration.GraphSettings); var cfgPruner = new CFGPruner(); cfgPruner.Prune(cfgcreator.Graph); //cfgcreator.Graph.VisualizeGraph("graph-pruned", Configuration.GraphSettings); File file = new File(parsedFile.Value) { CFG = cfgcreator.Graph, FullPath = parsedFile.Key, Interfaces = extractor.Interfaces.GroupBy(i => i.Name, i => i).ToDictionary(i => i.Key, i => i.ToList()), Classes = extractor.Classes.GroupBy(c => c.Name, c => c).ToDictionary(c => c.Key, c => c.ToList()), Closures = extractor.Closures.ToArray(), Functions = extractor.Functions.GroupBy(i => i.Name, i => i).ToDictionary(i => i.Key, i => i.ToList()) }; return(file); }
static void Main(string[] args) { if (args.Length != 1) { System.Console.WriteLine("Please pass only one argument"); System.Environment.Exit(1); } Lexer lexer = new Lexer(args[0]); lexer.Lex(); lexer.Output(); Parser parser = new Parser(lexer.GetTokens()); TMProgram root = parser.parseProgram(); ASTPrinter printer = new ASTPrinter(); printer.print("root", root); }
static void Main(string[] args) { StreamReader astream = new StreamReader(args[0]); AntlrInputStream antlrStream = new AntlrInputStream(astream); MINICLexer lexer = new MINICLexer(antlrStream); CommonTokenStream tokens = new CommonTokenStream(lexer); MINICParser parser = new MINICParser(tokens); IParseTree tree = parser.compileUnit(); Console.WriteLine(tree.ToStringTree()); STPrinter ptPrinter = new STPrinter(); ptPrinter.Visit(tree); ASTGenerator astGenerator = new ASTGenerator(); astGenerator.Visit(tree); ASTPrinter astPrinter = new ASTPrinter("test.ast.dot"); astPrinter.Visit(astGenerator.M_Root); MINIC2CTranslation tr = new MINIC2CTranslation(); tr.VisitCOMPILEUNIT(astGenerator.M_Root as CASTCompileUnit, new TranslationParameters()); tr.M_TranslatedFile.EmmitStdout(); StreamWriter trFile = new StreamWriter(Path.GetFileName(args[0] + ".c")); tr.M_TranslatedFile.EmmitToFile(trFile); trFile.Close(); StreamWriter m_streamWriter = new StreamWriter("CodeStructure.dot"); tr.M_TranslatedFile.PrintStructure(m_streamWriter); }
public override void printNode(ASTPrinter p) { p.print("Type", retType); p.print("Name", name); }
public override void printNode(ASTPrinter p) { p.print("return_kw", returnKW); p.print("value", value); }
public override void printNode(ASTPrinter p) { p.print("Condition", condition); p.print("Body", body); }
public override void printNode(ASTPrinter p) { string strkind = kind.Type.ToString(); p.printText("kind", strkind); }
public override void printNode(ASTPrinter p) { p.print("break", token); }
/// <summary> This method filter a R file with "RFilter" and parse it with "R"</summary> /// <param name="loc"> The R file.</param> /// <returns> The number of errors in file (NumberOfSyntaxErrors) at filtering and parsing. </returns> static int Parse(string loc) { // Reads characters from a byte stream in a particular encoding. StreamReader reader = new StreamReader(loc); // Vacuum all input from a Reader/InputStream and then treat it like a char[] buffer. // Can also pass in a String or char[] to use. AntlrInputStream input = new AntlrInputStream(reader); /* A lexer is recognizer that draws input symbols from a character stream. lexer grammars result in a subclass of this object. * A Lexer object uses simplified match() and error recovery mechanisms in the interest of speed. */ RLexer lexer = new RLexer(input); /* This class extends BufferedTokenStream with functionality to filter token streams to tokens on a particular channel(tokens * where Token.getChannel() returns a particular value). This token stream provides access to all tokens by index or when calling * methods like BufferedTokenStream.getText(). The channel filtering is only used for code accessing tokens via the lookahead * methods BufferedTokenStream.LA(int), LT(int), and LB(int). By default, tokens are placed on the default channel(Token.DEFAULT_CHANNEL), * but may be reassigned by using the->channel(HIDDEN) lexer command, or by using an embedded action to call Lexer.setChannel(int). * Note: lexer rules which use the->skip lexer command or call Lexer.skip() do not produce tokens at all, so input text matched by such a * rule will not be available as part of the token stream, regardless of channel. * * A collection of all tokens fetched from the token source. The list is considered a complete view of the input once fetchedEOF is set to true. */ CommonTokenStream tokens = new CommonTokenStream(lexer); // Print tokens BEFORE filtering. //tokens.Fill(); // Get all tokens from lexer until EOF //Console.WriteLine("BEFORE"); //foreach (IToken tok in tokens.GetTokens()) //{ // Console.WriteLine(tok); // //Console.WriteLine(tok.Text); //} RFilter filter = new RFilter(tokens); // Parse with filter. filter.stream(); // Call start rule: stream . tokens.Reset(); // Reset all the token (actually use seek(0) for reuse) //Print tokens AFTER filtering. //Console.WriteLine("AFTER"); //foreach (IToken tok in tokens.GetTokens()) //{ // Console.WriteLine(tok); // Console.WriteLine(tok.Text); //} RParser parser = new RParser(tokens); // Parse with RParser. IParseTree tree = parser.prog(); // Call start rule: prog . PTPrinter PTvisitor = new PTPrinter(loc); PTvisitor.Visit(tree); ASTGenerator ast = new ASTGenerator(); ast.Visit(tree); ASTPrinter ASTVisitor = new ASTPrinter(loc); ASTVisitor.Visit(ast.M_Root); ASTScopeVisitor astScopeVisitor = new ASTScopeVisitor(loc); astScopeVisitor.Visit(ast.M_Root); return(parser.NumberOfSyntaxErrors + filter.NumberOfSyntaxErrors); }
public override void printNode(ASTPrinter p) { p.print("decls", this.decls); }
public override void printNode(ASTPrinter p) { p.print("type", type); p.print("name", name); p.print("statement", statement); }
public virtual void printNode(ASTPrinter p) { System.Console.WriteLine("Print node not implemented for {0}", this.GetType().Name); }
public override void printNode(ASTPrinter p) { p.print("Continue", token); }
public override void printNode(ASTPrinter p) { p.print("name", name); }
public override void printNode(ASTPrinter p) { p.print("lit", lit); }
public override void printNode(ASTPrinter p) { p.print("value", value); }
public override void printNode(ASTPrinter p) { p.print("Name", name); p.printList("Parameters", parameters); }
public override void printNode(ASTPrinter p) { p.printList("Statement", statements); }