abstract-syntax-tree

AST from C code [closed]

自作多情 提交于 2019-11-29 21:36:22
I want to perform some transformations on C source code. I need a tool on linux that generates a complete AST from the source code so that I can apply my transformations on this AST and then convert it back to the C source code. I tried ELSA but it is not getting compiled. (I am using Ubuntu 8.4). Can anyone suggest a better tool/application? I would recommend clang . It has a fairly complete C implementation with most gcc extensions, and the code is very understandable. Their C++ implementation is incomplete, but if you only care about generating ASTs from C code that should be fine.

How to construct an abstract syntax tree

試著忘記壹切 提交于 2019-11-29 19:39:52
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? HS. Well, first off, the grammar is used to construct a parse tree from an expression. So if you already have a parse tree, you don't need the grammar. Depending on how much work your parser does, the resulting tree that is formed from parsing an expression could already be an abstract syntax tree. Or it could be a simple parse tree which requires a second pass to construct the

Boost::spirit::qi defining a calculator for nullaries

耗尽温柔 提交于 2019-11-29 15:14:19
I'm trying to write a parser for math expressions where named variables are nullaries in boost::spirit (version 1_51_0), to which I'm completely new. I define typedef boost::function<double()> Value and my rules will be declared like so: qi::rule<Iterator, Value()> expression, term, others, ...; I define binary operators on nullaries with this macro #define BINARY_FUNCTOR(name, op) \ struct name \ { \ name(Value x, Value y): x_(x), y_(y) {} \ double operator()() { return x_() op y_(); } \ Value x_, y_; \ }; and have ADD , SUB , etc. From the examples I've seen, I'd expect the rules to be

ANTLR Grammar for expressions

牧云@^-^@ 提交于 2019-11-29 15:10:17
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 generation helper stuff in XText. Don't worry about them for now. ... NilExpression returns Expression: 'nil'; FalseExpression returns Expression: 'false'; TrueExpression returns Expression: 'true'; NumberExpression returns Expression: value=Number; StringExpression

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

大憨熊 提交于 2019-11-29 10:22:56
问题 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 ? 回答1: Our SD Java Front End is a Java parser that builds ASTs (and optionally symbol tables). It captures comments directly on tree nodes. The Java Front End is a member of a family of compiler langauge front ends (C,

Microsoft CCI - resources, references for writing compilers

好久不见. 提交于 2019-11-29 10:22:18
问题 Some time ago, I was working on compiler, I've used System.Reflection to generate code (IL) from my AST. Now, I've an idea for another compiler that I'd like to work on (it will be another pet project, nothing that will be used in production code, at least, not now). As you know, pet projects have one big advantage over production code: you can experiment and fail. So, I've decided to try to write compiler using Microsoft's CCI. The only good reference I've found is a sample compiler of basic

Getting AST for C++?

爷,独闯天下 提交于 2019-11-29 09:27:31
I'm looking to get an AST for C++ that I can then parse with an external program. What programs are out there that are good for generating an AST for C++? I don't care what language it is implemented in or the output format (so long as it is readily parseable). My overall goal is to transform a C++ unit test bed to its corresponding C# wrapper test bed. You can use clang and especially libclang to parse C++ code. It's a very high quality, hand written library for lexing, parsing and compiling C++ code but it can also generate an AST. Clang also supports C, Objective-C and Objective-C++. Clang

Language parser library written in PHP

不打扰是莪最后的温柔 提交于 2019-11-29 09:25:31
问题 I am looking for a language parser written in PHP . The goal is to read a custom language , not read PHP code. Basically, I want to specify a language syntax, give a code snippet and get back a structure representing it. Then I can traverse that structure to execute the code snippet. I believe the structure will be an AST , but I don't know if this is the only option (I am not intimate with parsers and their vocabulary). I had a look at the Doctrine DQL parser but it doesn't seem like a

build AST in antlr4

人盡茶涼 提交于 2019-11-29 07:51:32
I was wondering whether we could build an AST using Antlr version 4. I couldn't find any reference on building it using antlr4. One SO answer says that it would be easy to use antlr4 which produces only parse tree but my question is what about the efficiency ? It forces us to crawl whole parse tree instead of an abstract syntax tree which is not efficient way to walk through the whole tree and perform task using visitors. There are two key items I'd like to point out first: Efficiency covers more than simple speed of execution. It can also apply to memory overhead, maintainability, and the

How to extract AST from Objective-C code?

十年热恋 提交于 2019-11-29 06:49:07
I need to analyze Objective-C static code, mainly AST, after looking into the possible tools I found out that Clang tool from LLVM can dump the AST, so I used the terminal to test it using this command: clang -cc1 -ast-dump ~/SomeTest.m but I'm getting this error: In file included from /Users/myusername/SomeTest.m:9: /Users/myusername/SomeTest.h:9:9: fatal error: 'UIKit/UIKit.h' file not found #import <UIKit/UIKit.h> ^ typedef __int128_t __int128_t; typedef __uint128_t __uint128_t; typedef SEL *SEL; typedef id id; typedef Class *Class; struct __va_list_tag { unsigned int gp_offset; unsigned