abstract-syntax-tree

javac.exe AST programmatic access example

Is it possible to access the Abstract Syntax Tree(AST) inside the javac.exe programmatically? Could you provide an example? ...

Translate C# code into AST?

Is it currently possible to translate C# code into an Abstract Syntax Tree? Edit: some clarification; I don't necessarily expect the compiler to generate the AST for me - a parser would be fine, although I'd like to use something "official." Lambda expressions are unfortunately not going to be sufficient given they don't allow me to use...

Standard format for concrete and abstract syntax trees

I have an idea for a hobby project which performs some code analysis and manipulation. This project will require both the concrete and abstract syntax trees of a given source file. Additionally, bi-directional references between the two trees would be helpful. I would like to avoid the work of transcribing a grammar to construct my own l...

Get code file version diff showing methods (names) impacted

I want to get a diff between two versions of a code file (of the Java/C#) variety - and from that get a list of methods (names) impacted. Has this been implemented? I presume this would require an AST Analysis of the lines that come back from the diff. The point of this would be to refine checkstyle/findbugs to just work on the method...

Python Best Practices: Abstract Syntax Trees

Modifying Abstract Syntax Trees I would like to be able to build and modify an ast and then optionally write it out as python byte code for execution later without overhead. I have been hacking around with the ast docs for python3.0 and python2.6, but I can't seem to find any good sources on best practices for this type of code. Quest...

How can I use the java Eclipse Abtract Syntax Tree in a project outside Eclipse? (ie not an eclipse plugin)

How can I use the java Eclipse Abtract Syntax Tree in a project outside Eclipse? (ie not an eclipse plugin) All the Eclipse AST examples that I've seen are for eclipse plugins. Is there a way (ie an example) of a project that uses the eclipse AST for a non-eclipse project. ...

Eclipse Abstract Syntax Tree Diff

Given the following code in Eclipse: import org.eclipse.jdt.core.dom.AST; import org.eclipse.jdt.core.dom.ASTParser; import org.eclipse.jdt.core.dom.CompilationUnit; public class Question { public static void main(String[] args) { String source = "class Bob {}"; ASTParser parser = ASTParser.newParser(AST.JLS3); ...

Method name from line number

Given a line number of a particular class source code (Java/C#) - is there an easy way to get the name of the method it falls within? (If it falls within one) (Presumably using an Abstract Syntax Tree) (This would be useful in limiting the output of checkstyle to just the method touched). I'm assuming you'd have to use an Abstract Syn...

Building own C# compiler using ANTLR: Compilation Unit

Hi, // Create a scanner that reads from the input stream passed to us CSLexer lexer = new CSLexer(new ANTLRFileStream(f)); tokens.TokenSource = lexer; // Create a parser that reads from the scanner CSParser parser = new CSParser(tokens); // start parsing at the compilationUnit rule CSParser.compilation_unit_return x = parser.compilat...

ANTLR Grammar for expressions

I'm trying to implement a expression handling grammar (that deals with nested parenthesis and stuff). I have the following so far, but they can't deal with some cases (successful/failure cases appear after the following code block). Anyone know what's going on? Note: The varname += and varname = stuff are just some additional AST genera...

How do you turn an unquoted Python function/lambda into AST? 2.6

This seems like it should be easy, but I can't find the answer anywhere - nor able to derive one myself. How do you turn an unquoted python function/lambda into an AST? Here is what I'd like to be able to do. import ast class Walker(ast.NodeVisitor): pass # ... # note, this doesnt work as ast.parse wants a string tree = ast...

Is there any way to programmatically generate Python bytecode?

I want to hack around with the Python interpreter and try creating a small DSL . Is there any module where I can do something like this theoretical code (similar to LINQ expression trees)? expression_tree = Function( Print( String('Hello world!') ) ) compile_to_bytecode(expression_tree) Or would it just be easier t...

Best/fastest way to write a parser in c#

What is the best way to build a parser in c# to parse my own language? Ideally I'd like to provide a grammar, and get Abstract Syntax Trees as an output. Many thanks, Nestor ...

Simple example of how to use ast.NodeVisitor?

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. ...

What are the following constructs in Mono.Cecil referring to in C#?

Can someone explain what are these referring to? MemberReference, TypeReference, ExternType, Override, NestedType, PInvokeInfo, SecurityDeclaration and CustomAttribute and MarshalSpec Best if can illustrate with examples. Will appreciate even if u don't know all, but still help me in understanding those u know. Cos I am trying to write ...

Eclipse JDT ASTVisitor - how to tell if a field is read or written in a method?

I am writing a Eclipse ASTVisitor. How to tell if a field is read or written in a method? The idea provided was "You need to vist Assignment node. Field on the LHS is written, while fields on the RHS expression is read." After I visit the assignment and get the LHS and RHS which are both of Expression, how do I tell if the Expression c...

What approaches have been used for searching computer code?

I'm interested in natural language processing and wondering what approaches have been used to search for programming constructs and idioms in code. Assuming we can generate an abstract syntax tree for the program it should be possible to identify common constructs and perhaps deduce something about the motivation of the program(mmer). Fo...

How to construct an abstract syntax tree

I have a general idea of what an AST is, but I want to know how to construct one. If you're given a grammar and a parse tree, how do you construct the AST? How do you do it if you're given a grammar and an expression? ...

Scala AST in Scala

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.) ...

Your favourite Abstract Syntax Tree optimization

Hi If you were constructing a compiler, what optimization at the AST level would be the nicest to have? ...