Questions tagged [abstract-syntax-tree]
For questions about abstract syntax trees (ASTs), hierarchical representations of the syntactic structure of code, typically used in compilers, interpreters, and static analysis tools. Do not use for questions about syntax design.
8 questions
6
votes
2
answers
440
views
Representing multiple alternative ASTs in one structure
Sometime during the past year I read (possibly on SO/SE) about a topic that sounded interesting. Now I would like to pick it up but I can't find it again. My memory is somewhat vague, I'm afraid.
I ...
28
votes
7
answers
13k
views
Why do compilers typically convert code into abstract syntax/parse trees before the final product?
When I started researching parsing and compiling I started with simple mathematical expression parsers. Many of the existing implementations I found have an intermediate step of converting a string ...
-1
votes
1
answer
377
views
Look behind in parsers [closed]
If Sandwich's AST generator finds that the first token is an identifier, one of two cases can be true:
Function call
Variable assignment
It stores the identifier and checks if the next token is a = ...
13
votes
3
answers
2k
views
Preserving Comments in AST
I'm currently working on a protobuf parser and I'm trying to preserve the comments in the AST. However, there many non-trivial cases and I was wondering if there was an already existing algorithm/data ...
16
votes
7
answers
4k
views
What languages give you access to the AST to modify during compilation?
Are there any languages which allow you to get access to the AST during compile time, to use some part of the AST to generate code, or to possibly rewrite the code/AST to optimize it in a heuristic ...
8
votes
2
answers
273
views
How can I reduce the amount of AST duplication in my code?
I'm working on a language that transpiles to Lua, and writing the transpiler in Kotlin. One problem I'm having is that I simply have too many AST types. I have an untyped AST, a typed AST, and a Lua ...
8
votes
3
answers
532
views
Representing parenthesis in an AST
This language is implemented in Rust using a lot of enums for things like expressions. Some of the planned validation rules involve checking how parenthesis are used -- where they're needed and are ...
13
votes
2
answers
2k
views
What is the difference between an Abstract Syntax Tree and a Parse Tree?
Compiling and interpreting programming languages typically involves parsing text into a tree that represents the different groupings of syntactic elements. The hierarchy represents which syntactic ...