Skip to content

Understanding AST (Abstract Syntax Tree) #12912

Closed Answered by nrmancuso
ThatSneakyCoder asked this question in Q&A
Discussion options

You must be logged in to vote

@shubh220922

Abstract syntax trees are a way to represent the structure of source code that is convenient to me. Depending on how I want to use the AST, I might remove elements I don't care about, or add imaginary ones that help me do whatever I want to do with it. An AST is just my interpretation of some source code. Don't get hung up with technical stuff, this is why it is abstract :)

In Checkstyle, this is how we generate the AST:

  1. Create a stream of characters from the source code file
  2. Recognize certain elements within this stream (tokens), create a token stream
  3. Recognize groups of tokens that form larger elements (production rules)
  4. Create a parse tree from the production rules
  5. Visit …

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
3 replies
@romani
Comment options

@romani
Comment options

@nrmancuso
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by ThatSneakyCoder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants