abstract-syntax-tree

Can't get ITranslationUnit for creating an AST of an C-File within a Eclipse Plugin

本秂侑毒 提交于 2019-12-12 03:53:44
问题 I'm trying to generate an AST with help of the CDT Eclipse Framework from an C-File of a generated project in my workspace. But every time i try to get an TranslationUnit through ICElement ice = CoreModel.getDefault().create(file); ITranslationUnit tu= (ITranslationUnit) ice; ice and tu are null and i get the following error java.lang.NullPointerException at org.eclipse.cdt.internal.core.pdom.TeamPDOMImportOperation.expandLocation(TeamPDOMImportOperation.java:135) at org.eclipse.cdt.internal

ANTLR4 AST Creation - How to create an AstVistor

杀马特。学长 韩版系。学妹 提交于 2019-12-12 03:52:44
问题 With the help of this SO question How to create AST with ANTLR4? I was able to create the AST Nodes, but I'm stuck at coding the BuildAstVisitor as depicted in the accepted answer's example. I have a grammar that starts like this: mini: (constDecl | varDef | funcDecl | funcDef)* ; And I can neither assign a label to the block (antlr4 says label X assigned to a block which is not a set ), and I have no idea how to visit the next node. public Expr visitMini(MiniCppParser.MiniContext ctx) {

Pattern matching AST nodes in Rascal

不问归期 提交于 2019-12-12 03:26:14
问题 I have the following AST definition: data Exp = app(Exp fun, Exp body) | var(str name) | nat(int nat) | func(list[str] formal, Exp body) | cond(Exp cond, Exp then, list[tuple[Exp,Exp]] elifs, Exp otherwise) | let(list[str] vars, list[Exp] exps, Exp body) | seq(Exp lhs, Exp rhs) | mul(Exp lhs, Exp rhs) | div(Exp lhs, Exp rhs) | md(Exp lhs, Exp rhs) | add(Exp lhs, Exp rhs) | sub(Exp lhs, Exp rhs) | eq(Exp lhs, Exp rhs) | gt(Exp lhs, Exp rhs) | lt(Exp lhs, Exp rhs) | geq(Exp lhs, Exp rhs) | leq

What is AST,CFG,CLANG, how can we use it in deadcode removal algorithm? [closed]

六眼飞鱼酱① 提交于 2019-12-12 03:21:40
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . I am about to write a dead-code removal algorithm using C language for an online event with our team. The requirements are..... To read a C program source file,Which has many forms of dead-codes. And our output

Exception while generating AST using Eclipse JDT SDK in a non-eclipse environment

不想你离开。 提交于 2019-12-12 03:08:27
问题 I'm trying to use the jdt's AST generation feature in a non-eclipse environment(as a plugin for another basic java ide). My program creates the AST correctly when I run it inside eclipse, but when I test the plugin it from the ide I get this exception: Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: ignoreMethodBodies at org.eclipse.jdt.core.dom.CompilationUnitResolver.parse(CompilationUnitResolver.java:491) at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser

Creating a syntax tree from tokens

大憨熊 提交于 2019-12-12 03:00:09
问题 I'm trying to create a tiny interpreter for TI-BASIC syntax. This is a snippet of TI-BASIC I'm trying to interpret A->(2+(3*3)) I've tokenized the code above into this sequence of tokens: Token{type=VARIABLE, content='A'} Token{type=ASSIGN, content='null'} Token{type=L_PAREN, content='null'} Token{type=NUM, content='2'} Token{type=ADD, content='null'} Token{type=L_PAREN, content='null'} Token{type=NUM, content='3'} Token{type=MULT, content='null'} Token{type=NUM, content='3'} Token{type=R

Get source script details, similar to inspect.getmembers() without importing the script

与世无争的帅哥 提交于 2019-12-11 17:48:27
问题 I'm trying to get the source, callee list, defaults, keywords, args and varargs of the functions in a python script. Currently, I'm importing the module and using the python inspect module's getmembers function and passing the isfunction parameter like so: members = inspect.getmembers(myModule, inspect.isfunction) However, this method doesn't work if myModule 's imports aren't available to me (since myModule has to be imported first). I tried using the python ast module to parse and dump the

python - is there no better way to get the expression in a debug function

拜拜、爱过 提交于 2019-12-11 16:08:42
问题 in c code I frequently use printf debugging macros like #define DPRINT_INT(i) fprintf(stderr,"%s has the value %i at line %i", #i,i, __LINE__) and then i can do things like DPRINT_INT(height) where it will print the variable or things like DPRINT_INT(from_cm_to_inch(get_average(heights))) and it will print out the whole expression for the name. To do this for python, since python doesn't have c-like macros I pass a string and use inspect to get the calling functions environment to call eval

Eclipse JDT: How to find JDK MethodInvocation and ClassInstanceCreation

懵懂的女人 提交于 2019-12-11 14:49:07
问题 I am using Eclipse JDT ASTVisitor to find Java method invocations and class instance creations from java source files. Now, I can find all of these. But I can not judge whether these method invocations and class instance creations is from JDK library or not . So, How can I get the JDK library method invocations (eg: InputStream.read()) and class instance (eg: new String())? The following is my code. JdtAstUtil.java import java.io.BufferedInputStream; import java.io.FileInputStream; import

ANTLR How to differentiate input arguments of the same type

我的梦境 提交于 2019-12-11 14:44:47
问题 If I have my input message: name IS (Jon, Ted) IS NOT (Peter); I want this AST: name | |-----| IS IS NOT | | | Peter |----| Jon Ted But I'm receiving: name | |-----------------| IS IS NOT | | | | |----|-----| |----|-----| Jon Ted Peter Jon Ted Peter My Grammar file has: ... expression | NAME 'IS' OParen Identifier (Comma Identifier)* CParen 'IS NOT' OParen Identifier (Comma Identifier)* CParen -> ^(NAME ^('IS' ^(Identifier)*) ^('IS NOT' ^(Identifier)*)) ; ... NAME : 'name' ; Identifier : ('a'