abstract-syntax-tree

How can I parse a typedef for a function pointer using clang API to get the function pointer name?

徘徊边缘 提交于 2019-12-24 11:29:05
问题 I am currently building a parser for C++ code using the clang C API. The parser will process a header file and generate a list of defined and missing symbols for it (it ignores include directives, so it will parse strictly the contents of the header). My problem is, if I have a typedef for a function pointer which takes an argument of an undefined type, such as: typedef SOME_TYPE (* funcPtrName)(SOME_UNDEF_TYPE x); the AST parses SOME_TYPE as the typedef instead of funcPtrName . If I replace

Virtual classes as AST nodes with Spirit

旧街凉风 提交于 2019-12-24 10:22:09
问题 i was working on an interpreter for a language with a friend, and we started with a decision I'm guessing wasn't that wise: we made all the elements for execution first (practically a tree made of different classes); but now looking at boost examples i get a lot confused about how to merge the two. I know what to start from (the grammar), i know what to reach (instantiated classes owning each other), i don't know how to reach it. We started with expressions without variables, hence we looked

Clang AST dump doesn't show #defines

最后都变了- 提交于 2019-12-24 02:58:40
问题 I'm dumping the AST of some headers like this: clang -cc1 -ast-dump -fblocks header.h However, any #define s on the header are not showing on the dump. Is there a way of adding them? 回答1: It's true, #defines are handled by the preprocessor, not the compiler. So you need a preprocessor parser stage. I know of two: Boost Wave can preprocess the input for you, and/or give you hooks to trigger on macro definitions or uses. The Clang tool pp-trace uses a Clang library that can do callbacks on many

Clang AST dump doesn't show #defines

邮差的信 提交于 2019-12-24 02:58:07
问题 I'm dumping the AST of some headers like this: clang -cc1 -ast-dump -fblocks header.h However, any #define s on the header are not showing on the dump. Is there a way of adding them? 回答1: It's true, #defines are handled by the preprocessor, not the compiler. So you need a preprocessor parser stage. I know of two: Boost Wave can preprocess the input for you, and/or give you hooks to trigger on macro definitions or uses. The Clang tool pp-trace uses a Clang library that can do callbacks on many

Boost Spirit and abstract syntax tree design

…衆ロ難τιáo~ 提交于 2019-12-24 02:39:29
问题 I'm using Qi from Boost Spirit to parse VRML 1.0. There is a group node called Separator and immediately under Separator, many different types of nodes can be held. The AST is based upon Boost.Variant and so far is looking lengthy. I'm close to hitting the limit of 20 types in the variant. I know I can extend number of types a variant has, but I'm sure there must be a better way to design this. Ideas welcome. typedef boost::variant< Nil, Coordinate3, Info, Material, MaterialBinding, Normal,

How to build a AST for a proprietary language?

拈花ヽ惹草 提交于 2019-12-24 00:45:27
问题 I m trying to understand how to build a AST for a proprietary language. I need to build a AST so I can feed in my rules and guidelines to check for the possible errors in the source code. How does one go about building a AST? Are there any books, articles that may help me get started. Will the dragon book on compilers help?. Please note i'm from a non-CS background. Thanks 回答1: This is a pretty large question. I do feel your pain, as I also tackled this problem from a non-CS background. It

Spirit qi parsing to an Abstract Syntax Tree for nested functions

别等时光非礼了梦想. 提交于 2019-12-23 22:07:11
问题 I am trying to create a parser using boost's spirit qi parser. It is parsing a string that contains three types of values. A constant, a variable, or a function. The functions can be nested inside of each other. The test string is f(a, b) = f(g(z, x), g(x, h(x)), c) , where a-e are constants, f-r are functions, and s-z are variables. I successfully created a rule that can correctly parse the expression. The trouble arose when I changed the function parsing the rule into a grammar. There were

What syntax is represented by an ExtSlice node in Python's AST?

佐手、 提交于 2019-12-23 17:22:33
问题 I'm wading through Python's ast module and can't figure out the slices definition: slice = Ellipsis | Slice(expr? lower, expr? upper, expr? step) | ExtSlice(slice* dims) | Index(expr value) So far, I know that Ellipsis is [...] , Slice is the usual [start:end:step] notation, Index is [index] , but which notation is ExtSlice ? 回答1: An extended slice is a slice with multiple parts which uses some slice-specific feature. A slice specific feature is something like ... (a literal ellipsis) or a :

Recursive parsing based on level numbers

僤鯓⒐⒋嵵緔 提交于 2019-12-23 16:11:29
问题 I have a tricky question (at least in my perspective), regarding Scalas parser combinators and recursive parsing. I currently building a small parser which should be able to parse PL/1 structures like this: dcl 1 data, 3 subData, 5 tmp char(15), 5 tmp1 char(15), 3 subData2, 5 tmp2 char(10), 5 tmp3 char(5); In this scenario I want to build a AST as follows: Record(data) -> (Record(subData),Record(subData2)) Record(subData) -> (Char(tmp),Char(tmp1)) Record(subData2) -> (Char(tmp2),Char(tmp3))

Why are multiple, consecutive plusses allowable syntax in MATLAB?

杀马特。学长 韩版系。学妹 提交于 2019-12-23 13:04:55
问题 Does anyone know why this works in MATLAB? >> 1 ++ 2 ans = 3 Coming from coding in C, python, Java etc, I find it most counterintuitive that this should work at all. Presumably there's something important about the parser that I don't understand? 回答1: There's a difference between plus and uplus. I suspect MATLAB takes the first + as plus , and all the others as uplus . Since uplus is by default just "return what's behind", you add 1 and 2 , and use a lot of "return what's behind" in between.