abstract-syntax-tree

Handle into eclipse's parsing of java code?

How does eclipse internally build its internal representation of java code in order to be able to detect things like unreferenced methods, or to find method references in a project? And is there any way to get a hook into that information to build tools based on eclipse's internal parsing, Whether as an eclipse plug-in or as a standalone...

What is the difference between an Abstract Syntax Tree and a Concrete Syntax Tree?

I've been reading a bit about how interpreters/compilers work, and one area where I'm getting confused is the difference between an AST and a CST. My understanding is that the parser makes a CST, hands it to the semantic analyzer which turns it into an AST. However, my understanding is that the semantic analyzer simply ensures that rul...

Tree Transformations Using Visitor Pattern

(Disclaimer: these examples are given in the context of building a compiler, but this question is all about the Visitor pattern and does not require any knowledge of compiler theory.) I'm going through Andrew Appel's Modern Compiler Implementation in Java to try to teach myself compiler theory (so no, this isn't homework) and I'm havin...

Library for programming Abstract Syntax Trees in Python.

I'm creating a tree to represent a simple language. I'm very familiar with Abstract Syntax Trees, and have worked on frameworks for building and using them in C++. Is there a standard python library for specifying or manipulating arbitrary ASTs? Failing that, is there a tree library which is useful for the same purpose? Note, I am not m...

How to get ANTLR to output hierarchical ASTs?

I have a Lua grammar, (minor modifications to get it to output for C#, just namespace directives and a couple of option changes) and when I run it on some sample input, it gives me back a tree with a root "nil" node and as childs what looks to be a tokenized version of the input code. It looks like ANTLR's tree grammars operate on hierar...

Abstract syntax tree question

I am currently working on a compiler under C and I am abit lost at the part where we construct the data structure for AST, especially for the part where we construct stucture for IDs, it is called "Symbol Table Entry" I see structures over net such as: struct ste { struct id *name; /* pointer into hash table for assoc. id */ st...

Can I get AST from live scala code ?

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

string to abstract syntax tree

I would like to convert a string containing a valid Erlang expression to its abstract syntax tree representation, without any success so far. Below is an example of what I would like to do. After compiling, alling z:z(). generates module zed, which by calling zed:zed(). returns the result of applying lists:reverse on the given list. -m...

F# parsing Abstract Syntax Trees

What is the best way to use F# to parse an AST to build an interpreter? There are plenty of F# examples for trivial syntax (basic arithmatical operations) but I can't seem to find anything for languages with much larger ranges of features. Discriminated unions look to be incrediably useful but how would you go about constructing one wit...

Recommend C front-end that preserves preprocessor directives.

I'd like to start a project that involves transforming C code, but I'd like to include the preprocessor directives. I don't want to reinvent the wheel by writing my own C parser, so does anyone know of a front-end that can parse C preprocessor and C code, and produce an AST that can be used to re-generate (or pretty-print) the original ...

ANTLR3 inject an int into my tree

Is it possible to do what I'm attempting here? Or, perhaps I'm approaching it wrong? arrayDef : { int c = 0; } ('['']' {c++;})+ -> ARRAY /* somehow inject c here */ ; ...

Best design for generating code from an AST?

I'm working on a pretty complex DSL that I want to compile down into a few high level languages. The whole process has been a learning experience. The compiler is written in java. I was wondering if anyone knew a best practice for the design of the code generator portion. I currently have everything parsed into an abstract syntax tre...

AST-based search for Eclipse

Is there a plug-in for Eclipse that lets you search based on the Java AST (Abstract Syntax Tree) of your project files? The "Java Search" feature doesn't seem to cover cases like: "Get me all the fields declared as type 'X' in all classes" I can imagine many more possibilities that would open up with an AST-based search, but I don't e...

Using antlr and the DLR together -- AST conversion

I have an AST generated via ANTLR, and I need to convert it to a DLR-compatible one (Expression Trees). However, it would seem that i can't use tree pattern matchers for this as expression trees need their subtrees at instantiation (which i can't get). What solution would be best for me to use? ...

How to write the Visitor Pattern for Abstract Syntax Tree in Python?

My collegue suggested me to write a visitor pattern to navigate the AST. Can anyone tell me more how would I start writing it? As far as I understand, each Node in AST would have visit() method (?) that would somehow get called (from where?). That about concludes my understanding. To simplify everything, suppose I have nodes Root, Expr...

What file should CUP builder location field be set to?

I am writing a compiler for a class and the teacher told us to "edit the CUP_Builder, and make sure the Location field is correct". What is the function of the location field? Should it be set to the main source file? ...

When I'm looking at ASTNodes in Eclipse, how can I tell if one is in a valid state?

When I'm going through the abstract syntax tree of a project in Eclipse how can I tell if a TypeDeclaration is in a valid state (ie, will compile)? I have tried calling type.getFlags() but it always returns 2 (ASTNode.ORIGINAL) even when it's a type I know is not valid (ie it implements an interface that doesn't exist). Is there a way t...

AST generation for a an application developed both in visual basic and c#

Hi, I'm currently understanding one application developed both in visual basic and c#. Running through the code is getting tough as code is around 50KLOC. So I'm planning for generation of AST (abstract syntax tree). Will it be possible to generate for both language together. At least a call graph generation will be helpful (but can't f...

Java library for code analysis

Is there any Java library, that can help in building AST from the specified java source file and vice versa (generate code from the ASTree object)? I need something like this, but with an API, allowing to access the generated tree programmatically. ...

Creating simple calculator with bison & flex in C++ (not C)

Hey, I would like to create simple C++ calculator using bison and flex. Please note I'm new to the creating parsers. I already found few examples in bison/flex but they were all written in C. My goal is to create C++ code, where classes would contain nodes of values, operations, funcs - to create AST (evaluation would be done just afte...