Questions tagged [abstract-syntax-tree]
Abstract syntax trees (ASTs) represent the recursive structure of a formal document (program source code).
2,958
questions
0
votes
0
answers
24
views
How to build the syntax tree of a C language project folder [closed]
I want to generate the syntax tree for a C project in a project folder, where the C files may contain comments, macro definitions, etc. What language and syntax tree library should I use
I have ...
0
votes
0
answers
12
views
Creating Semantic Slice from C# Program using AST and PDG
I'm experimenting with creating a semantic slice from a C# program and have obtained the abstract syntax tree (AST) and program dependence graph (PDG). However, I'm unsure where to start generate a ...
0
votes
0
answers
29
views
how do i parse typescript code into AST inside the browser? [closed]
I'm current working on a react project that requires to convert a typescript code into AST on client-side but i couldn't find any script or library that could do this.
so far i looked up in so many ...
1
vote
0
answers
7
views
What parameter or option in Pyan allows for the specification of the initial function when generating a callgraph?
I'm using the following code to build a callgraph with Pyan. However, due to the project's size, constructing the callgraph takes a considerable amount of time. Is there a way I can specify the ...
2
votes
1
answer
29
views
How to get namespace from Type in TypeScript AST?
I am traversing a method using the TS compiler API and the method has some return type.
I need info over that type, like what package it is from and if it is exposed under a namespace.
Is this ...
0
votes
0
answers
12
views
How to prevent Babel from formatting the generated code?
When using Babel to modify the AST of a JavaScript code and writing the generated code back to the original file, I observed that the original file gets reformatted. However, I do not want the code to ...
0
votes
1
answer
19
views
VS code extension parse value of variable of typescript file
I'm working on a VS code extension to parse OpenAPI specs. The spec can be defined as a variable with a fixed name inside a typescript file.
Inside my vs extension I get the document as a string: ...
0
votes
1
answer
26
views
How can I determine if a class member is a getter or setter?
I am trying to use ts-morph to validate code in a transpiler I am writing. No it is not a TypeScript transpiler, but I need to support both JS and TS code within my original file.
I have the following ...
0
votes
0
answers
43
views
Abstract language tree generation doesn't work with specific syntax
I am trying to build a console calculator by building an abstract syntax tree out of the specific tokens, including numbers, arithmetic operators and parentheses. I have got a recursive approach here:
...
0
votes
2
answers
95
views
How to modify .py file using LibCST?
Hello.
I have some Python source code that I am trying to modify using LibCST. In short, I need to import 3 modules into the source .py file at a specific location. I am using LibCST instead of AST ...
1
vote
1
answer
48
views
Is it possible to traverse only a subtree of the AST with RecursiveASTVisitor
I want to traverse a project with a huge AST with clang's RecursiveASTVisitor. When I specify that the whole AST should be traversed (as follows), it takes a lot of time:
void MyVisitor::...
1
vote
0
answers
127
views
AST selector for eslint rule for Angular ngOnChanges method
The idea is to validate ngOnChanges Angular method.
it should have changes of type SimpleChanges as an argument
inside the function when accessing the property currentChanges should be optionaly ...
0
votes
0
answers
119
views
Modifying Julia code using macros to substitute variables
I'm trying to create a Julia macro to substitute specific variables in a Julia program with new ones. I have a working example, but I'm facing a challenge when I need to reassign variables within ...
0
votes
1
answer
38
views
Does AST have a patterns that outlines the types of data it should include?
I am thinking about how my AST should look like.
I found that standard AST is:
{ type: ..., value:..., children:...}
Unfortunately, I have a problem for packing, for example:
var x int = 100
I don't ...
1
vote
1
answer
39
views
Minimal gradle multi-project build including a global AST transformation
I am trying to create a gradle project that applies a global AST transformation defined in project A to a class defined in project B. I've been following the instructions in this guide without success:...
0
votes
1
answer
29
views
Convert LibCST type Annotation back into type?
After creating a start of a function that converts the Annotation type back into a type:
@typechecked
def extract_type_from_annotation(
*,
annotation: Union[
Subscript, Index, Name, ...
1
vote
1
answer
57
views
References vs Rc's to values in Context for tokenization
I am creating an algebraic tokenizer/parser where implementations of individual token prototypes (such as operators, functions, constants, ...) are contained in a Context struct so that I don't have ...
0
votes
0
answers
23
views
Type hints alter behavior of ast ClassDef base classes?
When a class inherits a parent class with a type hint, ast returns a base without an id attribute. Why is that?
The code below prints Parent as I expected.
import ast
def print_parents(code):
...
0
votes
0
answers
37
views
Why does my AST generator trigger syntax error for a notebook file?
I tried to generate an AST of a notebook. Some files are okay to generate that, but I sometimes I got this syntax error.
Traceback (most recent call last):
File "/home/jupyterss/.local/lib/...
-1
votes
1
answer
44
views
Resolving Errors in a Yacc and Flex Compiler Project | Cannot generate AST from YACC Grammar
I want to display an AST for a given expression, and given below is my code for the same
Lex File
%{
#include "y.tab.h"
#include "ast.h"
%}
%option yylineno
digit [0-9]
...
0
votes
0
answers
38
views
C type representation in abstract syntax tree (AST)
I am implementing a C compiler and I am struggling to find a good way of representing an expression's type in the AST. Is there a standard way of doing this? I thought about implementing it as a ...
0
votes
1
answer
41
views
How to use common expression elimination together (CSE) with codegen
I'm trying to use sympy.utilities.codegen. I need compute a complicated function and its derivative. As a simplified example the function f is
x = Symbol('x')
y = Symbol('y')
f = 1 / (x - y)
df = f....
1
vote
1
answer
35
views
When I assemble an AST tree into a React component, the Cyrillic alphabet is converted to Unicode escape sequences
Actually, any text other than Latin does this.
I want to add an attribute "attrName" with a value "киррилица" to the button:
<button attrName="киррилица">текст</...
0
votes
0
answers
19
views
Groovy AST: the order of local and global transformations
I have an AST transformation which runs both as a global and a local one.
The idea is,
the global AST finds all the classes annotated with @Entity
the local AST is "injecting" a list of ...
0
votes
1
answer
120
views
How to add web-tree-sitter to a NextJS project?
I want to be able to generate ASTs by parsing code typed on my NextJS web app. I saw that I should be using web-tree-sitter to achieve such a thing.
I successfully used Docker to generate the tree-...
3
votes
2
answers
74
views
Can PowerShell load all functions from a script at the start of running a script (without using dot sourcing)?
Here's the script that prompted this question. The idea was to see if it's possible to have a script load its own functions (without using dot sourcing) before they would have otherwise been defined. ...
0
votes
1
answer
35
views
How to get class name from a methodCallExpr without invoking reolve()
Using javaparser library in Java, I have a Visitor class that extracts methodCallExpr. now I want to get the class name of the objects on which they are invoked. For instance:
a.sayHi();
when I call ...
1
vote
0
answers
49
views
Can we use meta programming in groovy to block some string variable from getting print
def sen = "sensitiveValue"
def nonSen = "nonSensitiveValue"
println sen
println nonSen
expected output
*****
nonSensitiveValue
String.metaClass program to avoid printing ?
0
votes
0
answers
99
views
Convert ast back to template string in Vue
I am using vue-template-compiler to change attribs in specific div, after updating I want to convert the ast's back to template string. How can I do it?
I want something like dom-serializer for vue.
...
1
vote
1
answer
69
views
How to interpret ast.literal_eval() ValueError message?
When attempting to use ast.literal_eval() on an extremely massive string I receive the error ValueError: malformed node or string on line 1: <ast.Name object at 0x000001FAAA9B1420>. It is ...
0
votes
0
answers
54
views
How can I get AST from a C# file? [duplicate]
I know I can use esprima to get AST for a given JavaScript file/code.
But I can't find a library, or a way to get the AST for C# code.
How can I get that?
Update: I work on Linux. I don't have access ...
0
votes
0
answers
39
views
Why the communication between the SQL database and the ORMs/Query Builders is done only by SQL concrete syntax?
As I know, all ORMs and Query Builders deal with the database by queries expressed in the SQL concrete syntax, in the same way as humans do when writing SQL queries from scratch.
The pitfall in that ...
2
votes
0
answers
105
views
Code generation in Golang: using the go/ast package to add doc comments,but comments‘ site not right
When I execute go generate in the errrmsg directory, the comments for the function are not in the correct location
// Code generated by gen_code. DO NOT EDIT.
// 提示内容:"成功"
// 状态码:10000
// ...
2
votes
1
answer
57
views
How to find the clang::SourceRange of a deleted function?
I am working on a Clang AST generated from the following source code:
struct has_deleted_function_member
{
void deleted_function1() = delete;
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^ col:33
};
void ...
0
votes
2
answers
204
views
how to understand from where a function call is made?
I am using TreeSitter to parse python code.
I need to understand check_files_in_directory is invoked from GPT4Readability.utils. I already captured all the function calls. I have to do this ...
1
vote
2
answers
61
views
Groovy AstBuilder use argumentList for method params
I want to add the following if-statement at the beginning of a method:
@Grant( [ Permission.admin ] )
def someMethod( someArg ){
if( GrantUtil.checkAuthorization( someArg, Permission.admin ){ // 2nd ...
2
votes
1
answer
59
views
How to find SourceLocation of the outer template parameter list of a class template member function definition?
I am working on a Clang AST generated from the following source code:
template<class T>
struct my_class
{
template<class U>
void foo(U arg);
};
template<class V>
template<...
0
votes
0
answers
22
views
Groovy AST superclass methods return null
I have a super-class with CRUD methods like:
class CRUDController<T extends MongoEntity> implements ControllerTrait {
@Transactional
void list( RoutingContext rc ) {
def q = query ...
0
votes
1
answer
70
views
How do I use the Dart analyzer class to build a tree instance that reflects the AST?
I would like to use the analyzer package to parse the widget tree that's defined in the build function and automagically factor the code for each method invocation into separate methods.
Pretend the ...
0
votes
0
answers
45
views
java.lang.SecurityException: class "org.eclipse.core.runtime.Plugin"'s signer information does not match signer information
my code:
ASTParser parser = ASTParser.newParser(11);
parser.setUnitName("D:\\code\\sscs\\filecenter_service\\src");
parser.setEnvironment(null, null, null, false);
parser.setSource("...
0
votes
1
answer
315
views
How to get AST from Python code, change it, and write it back to file, in Java?
Question
How can one read an arbitrary Python file, build an abstract syntax tree from it, modify that, and then write the modified AST back to file, in Java? (Small note, for a concrete syntax tree (...
1
vote
0
answers
27
views
Parallel Transform AST
I am writing a simple ast parser, and I have already created a transformer in visitor pattern, and I have a question, how do I transform AST in parallel, my parser is a recursive decent parser, so it ...
0
votes
0
answers
47
views
Result of @babel/parser and @babel/generator are different
I take a simple code: "const Component = () => (123)"
convert it to ast, then convert it back to code without any changes
i expect the incoming and outgoing code to be the same, but you ...
0
votes
0
answers
47
views
Markdown to HTML while using c++ for designing backend compiler
How can I convert the .md(markdown) files to HTML page view using c++ as base language!?
Using own compiler with softwares such as Flex and Bison...pls let me know the steps to be followed
I've ...
0
votes
1
answer
72
views
How to extract the exact information of `GenArg`?
I'm writing a Coq formatter (code). So far, I got the AST of a Coq code and pretty-printed a few of its nodes. However, I cannot pretty-print VernacExtend nodes.
The CoqAst below represents the AST of ...
0
votes
1
answer
41
views
Lifetime problem when visitor recursively traversal AST
I have a parser toy that wants to transform AST value like SCSS nested rules, I got a problem is that when I visit every node, I would transform AST node's value computed by parent value and ancestor ...
2
votes
1
answer
66
views
Python decorator that resolves some expressions in a function
I want to write a decorator that "pre-resolves" some expressions in a function. That is,
CONSTS = {'pos': 1}
@resolve(CONSTS)
def f(x: list):
return x[CONSTS['pos']]
should be the same ...
1
vote
2
answers
143
views
How to generate the AST of a Coq source code?
I'm trying to write a Coq source code formatter, and I want the AST for a Coq source code.
Firstly I tried to generate ASTs from the official Coq library but gave it up because I couldn't know how.
...
1
vote
1
answer
61
views
Print source of lambda without surrounding call
If I define a function
def foo(function):
import inspect
return inspect.getsource(function)
and then call it, I get:
In [11]: foo(lambda x: x[0] + x[1]*2)
Out[11]: 'foo(lambda x: x[0] + x[1]*...
0
votes
1
answer
100
views
Best Practice for Design A Identifier AST in Rust
I am learning Rust and implementing a toy parser, At the beginning I definite my AST like
struct ASTIdentifier {
name: String,
}
the problem with this design is that I need to allocate heap space ...