abstract-syntax-tree

How to get names of all the variables defined in methods of a class

↘锁芯ラ 提交于 2021-02-19 02:36:06
问题 I have the following class: class Foo(object): def setUp(self): self.var1 = "some value" self.var2 = something def bar(self): var3 = some value def baz(self, var): var4 = some value I want to print the names of all variables defined inside the methods, like: setUp, bar, baz, var1, var2, var3, var4 I have tried using locals(), vars(), globals() but I am getting only the names of method and not variable names. I also tried using ast module, but no success. 回答1: class Foo(object): def setUp(self

Python AST: several semantics unclear, e.g. expr_context

穿精又带淫゛_ 提交于 2021-02-19 02:05:24
问题 Is there any more than the ast documentation about the ast module? Esp., I am wondering what expr_context (and all its possible values) exactly means. Also, what is the difference between Assign and AugAssign ? Also, it is possible to reference to a real Python object instead of its name when doing an assignment to a local variable? I am building an AST myself and I have some Python objects which I want to access to in the AST. The alternative would be to introduce some dummy temp var name

Python AST: several semantics unclear, e.g. expr_context

旧时模样 提交于 2021-02-19 02:04:59
问题 Is there any more than the ast documentation about the ast module? Esp., I am wondering what expr_context (and all its possible values) exactly means. Also, what is the difference between Assign and AugAssign ? Also, it is possible to reference to a real Python object instead of its name when doing an assignment to a local variable? I am building an AST myself and I have some Python objects which I want to access to in the AST. The alternative would be to introduce some dummy temp var name

What language is used to describe an Abstract Syntax Tree in ESTree?

陌路散爱 提交于 2021-02-11 15:44:48
问题 I am referring the ESTree documentation for ECMAScript 2015 here. For instance, it uses the following syntax: extend interface Program { sourceType: "script" | "module"; body: [ Statement | ModuleDeclaration ]; } interface ForOfStatement <: ForInStatement { type: "ForOfStatement"; } What language is this representation of the AST? Where can we read about the specification used to describe an AST or explanation of the custom format used? 回答1: As also pointed out by Bergi, the README states The

What language is used to describe an Abstract Syntax Tree in ESTree?

吃可爱长大的小学妹 提交于 2021-02-11 15:44:11
问题 I am referring the ESTree documentation for ECMAScript 2015 here. For instance, it uses the following syntax: extend interface Program { sourceType: "script" | "module"; body: [ Statement | ModuleDeclaration ]; } interface ForOfStatement <: ForInStatement { type: "ForOfStatement"; } What language is this representation of the AST? Where can we read about the specification used to describe an AST or explanation of the custom format used? 回答1: As also pointed out by Bergi, the README states The

Using Eclipse JDT to find all identifiers visible within a specific node

心不动则不痛 提交于 2021-02-07 21:55:44
问题 I'm working on a plug-in to Eclipse JDT that parses Java files and offers automatic corrections to them. I'm doing so using Eclipse's API for analyzing the AST. I'm trying to write a method that calculates the environment of a method - a list of all the identifiers that are visible within the scope of the method. Another way to look at this is the list of identifiers that can be auto-completed from a specific point in Eclipse. For example: import ... public class MyClass { private static

Using Eclipse JDT to find all identifiers visible within a specific node

℡╲_俬逩灬. 提交于 2021-02-07 21:55:18
问题 I'm working on a plug-in to Eclipse JDT that parses Java files and offers automatic corrections to them. I'm doing so using Eclipse's API for analyzing the AST. I'm trying to write a method that calculates the environment of a method - a list of all the identifiers that are visible within the scope of the method. Another way to look at this is the list of identifiers that can be auto-completed from a specific point in Eclipse. For example: import ... public class MyClass { private static

Using Eclipse JDT to find all identifiers visible within a specific node

二次信任 提交于 2021-02-07 21:55:16
问题 I'm working on a plug-in to Eclipse JDT that parses Java files and offers automatic corrections to them. I'm doing so using Eclipse's API for analyzing the AST. I'm trying to write a method that calculates the environment of a method - a list of all the identifiers that are visible within the scope of the method. Another way to look at this is the list of identifiers that can be auto-completed from a specific point in Eclipse. For example: import ... public class MyClass { private static

Correct way of getting type for a variable declaration in a typescript AST?

非 Y 不嫁゛ 提交于 2021-02-07 19:46:07
问题 Took a look at the declarationEmitter and for variable declarations, it has the function #emitVariableDeclaration which eventually calls #writeTypeOfDeclaration . This code does what is says---it takes a variable declaration and prints the variable and its type---this is exactly what I want to do. The problem is that when I replicate this code, the VariableDeclaration node has no symbol property...and thus, the type is always "any". Is there a missing step to initialize "symbols"? //sample

Understanding -fdump-tree output gcc with GraphViz

泄露秘密 提交于 2021-02-07 03:11:01
问题 I've created a tree dump how described here: How can I dump an abstract syntax tree generated by gcc into a .dot file? for this dummy script: int fact(int n) { if (n<=1) { return 1; } return n * fact(n-1); } int main(void) { int a = 4; int res = fact(a); return res; } And the image what I've got: As I know gcc is not the best way to learn AST representation. But anyway it would be nice to understand what image's content means. Especially what % sign here means and a FREQ:0 statement? 回答1: The