abstract-syntax-tree

Parsing MathML Operators using ANTLR

空扰寡人 提交于 2019-12-11 12:46:27
问题 I'm trying to parse Presentation MathML and build an AST using ANTLR. I have most of the tags supported and I can build nodes for specific constructs. I'm having trouble with the operators. On this page; http://www.w3.org/TR/MathML3/appendixc.html There is a list of the operators, the form they appear in by default (prefix, infix or postifx) and a priority value, which gives the precedence of the operator. I could take each operator code and add it to my lexer and then write rules for unary,

Why does Scala reify not work as according to the docs?

穿精又带淫゛_ 提交于 2019-12-11 12:06:21
问题 The Scala API docs for 2.10.3 say that I can, "Use refiy to produce the abstract syntax tree representing a given Scala expression." Accordingly, I can do: scala> val uni = scala.reflect.runtime.universe uni: scala.reflect.api.JavaUniverse = scala.reflect.runtime.JavaUniverse@4e42766 scala> uni reify { 1 to 3 } res2: uni.Expr[scala.collection.immutable.Range.Inclusive] = Expr[scala.collection.immutable.Range.Inclusive](Predef.intWrapper(1).to(3)) In the example above, I get what I am looking

Method to create LLVM IR

只愿长相守 提交于 2019-12-11 11:42:36
问题 I am creating clang tool and I want to generate LLVM IR from clang AST. I am aware of -emit-llvm option that I can use to get *.ll file, but is there way to generate IR inside code? Some method that I can call that takes clang AST or AST context and returns llvm::Module ? I cannot find any example that shows this. Edited: So I tried using CodeGenAction for this, but I can't get it to work. I end up with unresolved external symbol error. Am I missing something? #include <clang/CodeGen

Z3 API: Is inspection of AST possible

蓝咒 提交于 2019-12-11 11:14:46
问题 There is no direct way in Z3 to traverse an already existing Z3_ast for an expression, that much seems clear to me from the API. Is there however an indirect way how to, e.g., split a conjunction, substitute a term for a term in a Z3_ast obtained for example by Z3_parse_smtlib2_string or as an interpolant obtained with Z3_get_interpolant (these are output from Z3, so it makes sense to be able to examine them). 回答1: Traversal is possible, in the C API the functions for that are Z3_get_app_num

Printing Abstract Syntax Tree, infinite recursion issue

╄→尐↘猪︶ㄣ 提交于 2019-12-11 10:39:58
问题 For the final project in my C programming class, we are implementing a reverse polish notation calculator which can either evaluate an expression for correctness, return the corresponding infix expression, or print out mock assembly code. To do so, we are to implement both a stack and a Abstract Syntax Tree. struct snode /*stack data structure */ { int datum; struct snode* bottom; }; struct tnode /*tree data structure */ { int datum; struct tnode* left; struct tnode* right; }; Currently, I've

What's the best way to implement AST using visitor pattern with return value?

自作多情 提交于 2019-12-11 10:36:45
问题 I'm trying to implement a simple abstract syntax tree (AST) in C++ using the visitor pattern. Usually a visitor pattern does not handle return value. But in my AST there are expressions nodes which care about the return type and value of its children node. For example, I have a Node structure like this: class AstNode { public: virtual void accept(AstNodeVisitor&) = 0; void addChild(AstNode* child); AstNode* left() { return m_left; } AstNode* right() { return m_right; } ... private: AstNode* m

How to avoid down-casting when return types are not known at compile time?

送分小仙女□ 提交于 2019-12-11 09:54:37
问题 Suppose I have a abstract base class called Node . class Node { public: Node() { leftChild = NULL; rightChild = NULL; }; Node * leftChild, *rightChild; void attach(Node * LC, Node * RC) { leftChild = LC; rightChild = RC; }; }; I also have multiple functions (of which I'll include two for simplicity but in reality this could be any number). float add(float a, float b){return a+b;} bool gt(float a, float b){return a>b;} For each function there is an associated class. The first is as follows.

Flatten randomly nested list into a non nested list using Haskell

时光总嘲笑我的痴心妄想 提交于 2019-12-11 08:30:30
问题 I have an imaginary list with different levels of nesting, or ignoring the ugly types a API response ie: a ::(Num a, Num [a], Num [[a]]) => [[a]] a = [1, 2, [3, 4]] b :: (Num a, Num [a], Num [[a]], Num [[[a]]]) => [[[[a]]]] b = [[1,2,[3]],4] The function I'm trying to create should do the following: myFunc a == [1,2,3,4] myFunc b == [1,2,3,4] My initial thought was I'd have to parse the list into an AST (Abstract syntax tree) --> use recursion to flatten all the branches & leaves into a

goto statement in antlr?

橙三吉。 提交于 2019-12-11 07:01:43
问题 I would really appreciate if someone could give me advice,or point me to tutorial, or sample implementation, anything that could help me implement basic goto statement in ANTLR? Thanks for any help edit. ver2 of question: Say I have this tree structure: (BLOCK (PRINT 1) (PRINT 2) (PRINT 3) (PRINT 4) ) Now, I'm interested to know is there a way to select, say, node (PRINT 2) and all nodes that follow that node ((PRINT 2) (PRINT 3) (PRINT 4)) ? I'm asking this because I'm trying to implement

How to convert unpreprocessed C/C++ source to syntax tree (and back)?

送分小仙女□ 提交于 2019-12-11 06:34:21
问题 I want to have a converter between this #include <ololo.h> #ifdef HAVE_QQQ #include <qqq.h> #endif char* ololize(char* s) { #ifdef HAVE_QQQ return qqq(s); #else return ololo(s); #endif } and something like this (include_angular "ololo.h") (p_ifdef "HAVE_QQQ" (include_angular "qqq.h")) (define_function "ololize" [(ptr char) "s"] (ptr char) (p_ifdef "HAVE_QQQ" (return (qqq s)) :else (return (ololo s))))) I.e. representation of a source code as a easily manageable tree, not from compiler's point