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.

Filter by
Sorted by
Tagged with
-1 votes
1 answer
283 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 = ...
The_AH's user avatar
  • 17
12 votes
3 answers
619 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 ...
Clément Jean's user avatar
15 votes
7 answers
2k 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 ...
Lance's user avatar
  • 695
8 votes
2 answers
154 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 ...
Seggan's user avatar
  • 2,603
8 votes
3 answers
165 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 ...
0xLogN's user avatar
  • 180
10 votes
2 answers
555 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 ...
user16217248's user avatar
  • 7,525