abstract-syntax-tree

Why is the expression `super()` in the Java AST in Rascal?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-10 21:46:33
问题 One of the expressions in the Java AST declaration is Expression::super() . For which Java expression(s) is super() used? Take this example class: import java.util.ArrayList; import java.util.List; public class SuperTests<T> extends ArrayList<T> { public SuperTests() { super(); } public SuperTests(int capacity) { super(capacity); } @Override public void clear() { super.clear(); } public <T extends Integer> void addSupers(List<? super T> list) { } } The AST in rascal is: compilationUnit( [

Check if MethodDeclaration similar to an IMethod

徘徊边缘 提交于 2019-12-10 20:26:34
问题 Is there any way by which i can compare a MethodDeclaration object and IMethod object and check whether they are similar? Or is there any way by whcih a MethodDeclaration object can be converted to an IMethod object (IMethod provides a isSimilar function)? Update : Similarily i would like to know if a FieldDeclaration can be converted to a IField. 回答1: MethodDeclaration is an ASTNode, and IMethod is a JavaElement. The definitive way to check if these two objects correspond to the same method

Eclipse JDT ASTParser - Issue with MethodVisitor

拟墨画扇 提交于 2019-12-10 20:01:59
问题 I am writing some code to parse java source code. I am experimenting with Eclipse JDT AST Parser. My code is given below. (Parsing code). I am testing the parser against a Mailer application that I wrote in Java (second code snippet). My parser is visiting all methods except the generateEmail() and the debug() methods. I have looked all over the place but I am not able to understand for the life of me why its happening. Can anyone tell me what I am doing wrong? Is it a memory issue? I am not

Associativity and Precedence of Expressions when Generating C / C++ Code?

試著忘記壹切 提交于 2019-12-10 19:59:55
问题 I have written a basic compiler which generates an AST, correctly taking account of the operator precedence in expressions. However, when performing code generation to produce C++ code, I'm unsure of how to handle the use of brackets. For this expression: A - (B - c) The AST below: - / \ A - / \ B C Should correctly generate the previous expression including the parentheses, however if the second operator was an addition operator (for example), the parentheses would be unecessary. I would

Evaluating a math expression with variables. (java 8)

…衆ロ難τιáo~ 提交于 2019-12-10 18:07:36
问题 I would like additional help on a answer to this question, Evaluating a math expression given in string form. The user @Boann answered the question with a very interesting algorithm that he also points out can be altered to accept variables. I've managed to alter it and get it to work, but dont know how he separates the compilation and evaluation . Here's my code: import java.util.HashMap; import java.util.Map; public class EvaluateExpressionWithVariabels { @FunctionalInterface interface

FieldDeclaration to IField - Getting IBinding from FieldDeclaration

梦想与她 提交于 2019-12-10 17:10:25
问题 How can a FieldDeclaration (type: ASTNode) be converted to an IField (type: JavaElement). Is it possible to get the binding from the FieldDeclaration ASTNode, just like node.resolveBinding() as for MethodDeclaration node. Need : I am visiting a FieldDeclaration node in a Class having public constants, and want to search references for that field in the project. I am using JDT's SearchEngine for same. For this I want to create a search pattern as follows : SearchPattern.createPattern(iField,

Abstract syntax tree using the shunting yard algorithm

放肆的年华 提交于 2019-12-10 16:56:54
问题 I have an infix expression that I have tokenised and would like to proceed to create an abstract syntax tree. I understand the shunting-yard algorithm used in these cases. I have only found ways to convert the infix expression to RPN format, not into an AST. I could create the RPN version first and then AST from it, but it seems unnecessary. My language of choice is JavaScript, though I only need to see an example in any language and/or a description of the algorithm. I have skimmed through

Tracking source position of AST nodes in a compiler (ocaml)

▼魔方 西西 提交于 2019-12-10 15:57:03
问题 I'm writing a compiler in ocaml, using ocamllex/yacc. Things are going well, but I've a design problem. For each AST node I create, it'd be good to have information about line/character position of that node in the source code. That would be useful for providing error messages to the user later. Now, I can add some kind of meta type to my nodes: type node = Node1 of ... * meta | Node2 of ... * meta but that seems redundant. Later, when I'm done with verifying the AST, I'll have to write match

Convert ast node into python object

孤人 提交于 2019-12-10 15:45:29
问题 Given an ast node that can be evaluated by itself, but is not literal enough for ast.literal_eval e.g. a list comprehension src = '[i**2 for i in range(10)]' a = ast.parse(src) Now a.body[0] is an ast.Expr and a.body[0].value an ast.ListComp . I would like to obtain the list that eval(src) would result, but given only the ast.Expr node. 回答1: Perhaps you're looking for compile()? The result of calling compile() on an AST object is a code object that can be passed to eval() . >>> src = '[i**2

How do I debug an error in `ast.literal_eval`?

余生长醉 提交于 2019-12-10 14:40:06
问题 I wrote my data to a file using pprint.PrettyPrinter and I am trying to read it using ast.literal_eval. This has been working for me for quite some time, and I am reasonably satisfied with the text representation produced. However, today I got this error on deserialization: File "/...mypath.../store.py", line 82, in <lambda> reader=(lambda fd: ast.literal_eval(fd.read())), File "/usr/lib64/python2.7/ast.py", line 80, in literal_eval return _convert(node_or_string) File "/usr/lib64/python2.7