ast

Interrogating Java source code

I have a Java source code that I need to interrogate and apply security policies [for e.g. applying CWE] I have couple of ideas, for starters using AST and then travel thru the tree. Others include using regular expression. Are there any options other than AST or regex that I could use for such process. ...

How to access comments from the java compiler tree api generated ast ?

Hi, I've used the java compiler tree api to generate the ast for java source files. However, i'm unable to access th comments in the source files. So far, i've been unable to find a way to extract comments from source file .. is there a way using the compiler api or some other tool ? ...

Could we access to the Qt creator internal parser from a plugin ?

Hi, I would like to make a plugin for Qt Creator, and I want access to the parsing files (AST) in Qt Creator. For example if you right click on a variable, retrieve its type. I just looked at the doc and I have not found something very significant. And I fear myself having to parse the page. Anyone have tried it and succeeded? :p ...

How do I extract the names from a simple function?

I've got this piece of code: import inspect import ast def func(foo): return foo.bar - foo.baz s = inspect.getsource(func) xx = ast.parse(s) class VisitCalls(ast.NodeVisitor): def visit_Name(self, what): if what.id == 'foo': print ast.dump(what.ctx) VisitCalls().visit(xx) From function 'func' I'd like t...

elegant way to test python ASTs for equality (not reference or object identity)

Not sure of the terminology here, but this would be difference between eq? and equal? in scheme, or the difference between == and strncmp with C strings; where in each case the first would return false for two different strings that actually have the same content and the second would return true. I'm looking for the latter operation, f...

Using the Eclipse AST

I have recently come into the need of modifying some Java code (adding methods, changing the signatures of some fields and removing methods) and I think that all of this can be accomplished though the use of the Eclipse SDK's AST. I know from some research how to parse in a source file but I don't know how to do the things mentioned abo...

How to translate between programming languages

I am setting out to do a side project that has the goal of translating code from one programming language to another. The languages I am starting with are PHP and Python (Python to PHP should be easier to start with), but ideally I would be able to add other languages with (relative) ease. The plan is: This is geared towards web develo...

How do I see where in the Class Hierarchy a Method was defined and Overridden in Ruby?

Is there a way to know whether or not a method has been overridden by a subclass programmatically? Something that works like this: class BaseModel def create puts "superclass" end end class SomeModel < BaseModel def create puts "subclass" end end puts SomeModel.overridden_instance_methods #=> [:create] Any ideas? ...

Ruby (MRI) Syntax Tree nodes documentation

The meaning of most nodes from mri's syntax tree can be easily infered. However the list is quite long (source: bin/parse_tree_abc): :attrasgn, :attrset, :dasgn_curr, :iasgn, :lasgn, :masgn, :and, :case, :else, :if, :iter, :or, :rescue, :until, :when, :while, :call, :fcall, :super, :vcall, :yield, :args, :argscat, :array, :begin, :block...

AST for any arbitrary programming language or IR

Hi All, Is it possible to create an AST for any arbitrary programming language or IR using C or C++ alone (without the help of tools like YACC and LEX )? If so, how to implement the lexical and syntactic analysis ? If not, what are the tools that have to augmented to C or C++ to successfully create an AST ? Hope I made my doubt clear...

ANTLR AST building: root node as string instead of character

I might be asking a stupid/basic question but i had been confused about ANTLR AST building. What i want to made is a kind of Boolean expression parser such that on parent nodes i have operator and its operands as children. for instance, a sentence ( ( A B C & D ) | ( E & ( F | G ) ) ) should ideally be representing |...

Javac AST Symbol Resolving for JavacTask.parse()

As I posted on the official Java support forum several days ago, I want to know, if JCTree Symbols can be resolved from own code with the original javac implementation. http://forums.oracle.com/forums/thread.jspa?threadID=1774807&amp;tstart=0 JCMethodInvocation object1 = (JCMethodInvocation) objectRef.ref; Resolve resolve = Resolve.i...