abstract-syntax-tree

Eclipse create CompilationUnit from .java file

怎甘沉沦 提交于 2019-11-27 15:42:14
How can I load a .java file into a CompilationUnit? For example, lets say I have a A.java file in my current project. I would like to load it into a CompilationUnit and then pass it to the ASTParser. It is not an option just to load it as a plain text since it seems that in that case I will not get the binding information in the AST. You can load the projects using jdt and eclipse core libraries. Using the following code you can load all the projects in the workspace. IWorkspace workspace = ResourcesPlugin.getWorkspace(); IWorkspaceRoot root = workspace.getRoot(); // Get all projects in the

Can I get AST from live scala code?

南楼画角 提交于 2019-11-27 15:05:07
问题 I said "live code" because I mean not from text source files or source strings, but from partialFunctions / lambdas. (I know Ruby1.8's parseTree and C# linq can do it) consider a partialFunction f: val f = (i: Int, j: Int) => (i + j) * 2 I hope there is some tool works like this: getBodyAstFrom(f) //=> (Infix('*'), (Infix('+'), Id('i'), Id('j')), Val('2')) I don't care the semantic things (context parsing and implicits are too complex, and unnecessary for me), I just need the syntax tree from

How can I dump an abstract syntax tree generated by gcc into a .dot file?

痴心易碎 提交于 2019-11-27 13:07:33
问题 I think the question's title is self explanatory, I want to dump an abstract syntax tree generated by gcc into a .dot file (Those files generated by Graphviz) because then I want to view it in a .png file or similar. Is there any way I can do that? Thanks in advance :) 回答1: There are two methods, both including two steps Using GCC internal vcg support Compile your code (say test.c) with vcg dumps gcc -fdump-tree-vcg -g test.c Use any third party tool to get dot output from vcg graph-easy test

Scala AST in Scala [closed]

匆匆过客 提交于 2019-11-27 13:04:08
问题 Is there a Scala library that parses Scala and creates an Abstract Syntax Tree (AST)? Ideally I am interested in a Scala library. Plan B would be a Java library. (I know I could leverage the EBNF from the Scala Syntax Summary.) 回答1: I would think the best way to access the AST is with a compiler plugin. You should read a soft introduction before diving in deep. 回答2: A few existing parsers: The offical Scala compiler. The IntelliJ IDEA Scala plugin has a parser written in Scala against

How to traverse clang AST manually ?

别来无恙 提交于 2019-11-27 11:34:37
问题 I can traverse the specific subtrees of clang AST using the recursivevisitor class but what I want to do is to traverse the clang AST node by node. I'd be really grateful if anybody can help me with this. Thanks in advance. 回答1: RecursiveASTVisitor can do what you need. Implementing the member methods TraverseDecl(Decl *x) , TraverseStmt(Stmt *x) and TraverseType(QualType x) for your RecursiveASTVisitor`-derived class (e.g. MyClass) will do the trick. Combined, those three methods will take

What does Lambda Expression Compile() method do?

流过昼夜 提交于 2019-11-27 11:08:34
问题 I am trying to understand AST in C#. I wonder, what exactly Compile() method from this example does. // Some code skipped Expression<Func<string, int, int, string>> data = Expression.Lambda<Func<string, int, int, string>>( Expression.Call(s, typeof(string).GetMethod(“Substring”, new Type[] { typeof(int), typeof(int) }), a, b), s, a, b ); Func<string, int, int, string> fun = data.Compile(); To prevent misunderstandings, I understand the Expression.Lambda and Expression.Call constructs. What

Simple example of how to use ast.NodeVisitor?

喜你入骨 提交于 2019-11-27 11:02:11
Does anyone have a simple example using ast.NodeVisitor to walk the abstract syntax tree in Python 2.6? The difference between visit and generic_visit is unclear to me, and I cannot find any example using google codesearch or plain google. ast.visit -- unless you override it in a subclass, of course -- when called to visit an ast.Node of class foo , calls self.visit_foo if that method exists, otherwise self.generic_visit . The latter, again in its implementation in class ast itself, just calls self.visit on every child node (and performs no other action). So, consider, for example: >>> class v

javac.exe AST programmatic access example

∥☆過路亽.° 提交于 2019-11-27 10:03:05
问题 Is it possible to access the Abstract Syntax Tree(AST) inside the javac.exe programmatically? Could you provide an example? 回答1: Yes, it is possible, but only since Java 6. Peter von der Ahé talks about the two JSRs in this interview. Of JSR 199: The JSR 199 Compiler API consists of three things: The first one basically allows you to invoke a compiler via the API. Second, the API allows you to customize how the compiler finds and writes out files. I mean files in the abstract sense, since the

How can I build an AST using ANTLR4? [duplicate]

安稳与你 提交于 2019-11-27 09:29:36
This question already has an answer here: How to create AST with ANTLR4? 2 answers I have an ANTLR3 grammar that builds an abstract syntax tree. I'm looking into upgrading to ANTLR4. However, it appears that ANTLR4 only builds parse trees and not abstract syntax trees. For example, the output=AST option is no longer recognized. Furthermore neither "AST" nor "abstract syntax" appears in the text of "The Definitive ANTLR4 reference" . I'm wondering if I'm missing something. My application currently knows how to crawl over the AST produced by ANTLR3. Changing it to process a parse tree isn't

Python 3, Are there any known security holes in ast.literal_eval(node_or_string)?

℡╲_俬逩灬. 提交于 2019-11-27 07:58:56
Are there any known ways for ast.literal_eval(node_or_string) 's evaluation to not actually be safe? If yes, are patches available for them? (I already know about PyPy[sandbox], which is presumably more secure, but unless the answers are yes then no, my needs are minor enough that I won't be going that far.) The documentation states it is safe, and there is no bug relative to security of literal_eval in the bug tracker , so you can probably assume it is safe. Also, according to the source , literal_eval parses the string to a python AST (source tree), and returns only if it is a literal. The