abstract-syntax-tree

Can I use JDT search engine while parsing a source from JDT AST

為{幸葍}努か 提交于 2019-12-11 05:55:48
问题 I'm using JDT AST to parse a given source. I want to find the references of a given object/variable when it triggers the relavant visitor when using AST. E.g.: Consider the following code: public class SampleClass { public void printMe(){ System.out.println("hello"); } public static void main(String a[]){ SampleClass s =new SampleClass(); // do some other work s.printMe(); } } When I'm parsing the above code, when it comes to the variable declaration of "s", it will call the visitor method of

Extract all variables from a string of Python code (regex or AST)

夙愿已清 提交于 2019-12-11 05:22:54
问题 I want to find and extract all the variables in a string that contains Python code. I only want to extract the variables (and variables with subscripts) but not function calls. For example, from the following string: code = 'foo + bar[1] + baz[1:10:var1[2+1]] + qux[[1,2,int(var2)]] + bob[len("foobar")] + func() + func2 (var3[0])' I want to extract: foo , bar[1] , baz[1:10:var1[2+1]] , var1[2+1] , qux[[1,2,int(var2)]] , var2 , bob[len("foobar")] , var3[0] . Please note that some variables may

Edit java source files programmatically

Deadly 提交于 2019-12-11 04:05:56
问题 I'm looking for a way to edit .java files programmatically without resorting to unstable RegExes. Since I'm editing .java files, not .class files I do not want any Byte-code manipulation tools. I need something that: Is IDE-independent (hence no ASTParser. I want to automate it on CI, so AST is out unless there's a standalone version) Allows me to read a .java file, add an annotation to a method and save it - hence pure source code generation tools (CodeModel comes to mind) are not enough Is

ANTLR3 C Target - parser return 'misses' out root element

≡放荡痞女 提交于 2019-12-11 03:45:35
问题 I'm trying to use the ANTLR3 C Target to make sense of an AST, but am running into some difficulties. I have a simple SQL-like grammar file: grammar sql; options { language = C; output=AST; ASTLabelType=pANTLR3_BASE_TREE; } sql : VERB fields; fields : FIELD (',' FIELD)*; VERB : 'SELECT' | 'UPDATE' | 'INSERT'; FIELD : CHAR+; fragment CHAR : 'a'..'z'; and this works as expected within ANTLRWorks. In my C code I have: const char pInput[] = "SELECT one,two,three"; pANTLR3_INPUT_STREAM pNewStrm =

Using ast.literal_eval on a nested dictionary

时光总嘲笑我的痴心妄想 提交于 2019-12-11 03:18:09
问题 I'm using ast.literal_eval to change the data I receive from json.loads() into a Python dictionary; however if I should just be going about this an entirely different way - feel free to point that out as well. # Authentication buf = StringIO.StringIO() c = pycurl.Curl() c.setopt(c.URL, "https://kippt.com/api/account") c.setopt(c.WRITEFUNCTION, buf.write) c.setopt(c.HTTPHEADER, header) c.perform() result = buf.getvalue() buf.close() print result # Printing Output data_string = json.dumps

How do I translate LR(1) Parse into a Abstract syntax tree?

瘦欲@ 提交于 2019-12-11 03:17:51
问题 I have coded a table driven LR(1) parser and it is working very well however I am having a bit of a disconnect on the stage of turing a parse into a syntax tree/abstract syntax tree. This is a project that I m very passionate about but I have really just hit a dead end here. Thank you for your help in advance. Edit: Also my parser just uses a 2d array and an action object that tells it where to go next or if its a reduction where to go and how many items to pop. I noticed that many people use

Evaluate IF subtree in homogeneus AST

别来无恙 提交于 2019-12-11 03:16:27
问题 I'm building a tree walker for an homogeneus AST (all nodes have same class), what's the correct way to evaluate an if statement? My AST for if are like this: I would something that when parses an IF block, evaluates sequentially his CONDBLOCK children and if one of them is true, the tree walker doesn't evaluate the remaining. More clearly, my tree walker is something like: ifStat : ^(IF { jump=false; } condition* defcond?) condition : { if (jump) return retval; } ^(CONDBLOCK exp block) {

How do you compile an ast.Expt?

谁都会走 提交于 2019-12-11 03:14:56
问题 code='1+1' import ast expr = ast.parse(code).body[0] print(type(expr)) compile(ast.Expression(expr), 'string', "eval") gets me class '_ast.Expr' Traceback (most recent call last): File "test_ast.py", line 6, in compile(ast.Expression(expr), '', "eval") TypeError: expected some sort of expr, but got <_ast.Expr object at> 0x7fe89442d9e8> compile(expr, '<string>', "eval") does not works either: TypeError: expected Expression node, got Expr 回答1: An interesting explanation about Expressions can be

Scala presentation compiler locateTree method

[亡魂溺海] 提交于 2019-12-11 01:24:38
问题 I've been using scala presentation compiler API, or to be more exact it's locateTree method to get AST of some piece of source code, and then get its raw representation via showRaw(ast) call, but the result seems to be different compared to what I expected. For instance val tree = q"final def x = 1" println(showRaw(tree)) Outputs DefDef(Modifiers(FINAL), TermName("x"), List(), List(), TypeTree(), Literal(Constant(1))) , while a call to presentation compiler on the same source produces DefDef

clang not identifying 'ptrdiff_t', 'size_t', 'wchar_t' while parsing AST

倖福魔咒の 提交于 2019-12-11 00:28:46
问题 For the question raised in the below link, clang getting include files while parsing AST I used the 'parsing example file' for my input file with my system specific header paths, but I get errors for 'ptrdiff_t', 'size_t', 'wchar_t' types not defined. I am using below header path: /usr/include /usr/include/bits /usr/include/linux /usr/include/c++/4.1.2 /usr/include/c++/4.1.2/bits /usr/include/c++/4.1.2/tr1 /usr/include/c++/4.1.2/i386-redhat-linux/bits /usr/include/c++/4.1.2/i386-redhat-linux