0

If I were to create a pushdown automation that accepts a state(name) and those states accept transitions(input, pop, push, nextState). How does all this help me construct a parse tree?

I mean a pushdown automata is great for checking if something is in the language, like if a sequence of tokens or whatever is in the correct order... but syntax trees?

I mean consider the following example:

Foo {
 Woo {
  Hello World
 }
}

The pda can only remember the top item in a stack and the current input. How am I supposed to construct the tree? Should I combine PDA with recursion?

Asperger
  • 3,064
  • 8
  • 52
  • 100

1 Answers1

1

Broadly, each item on the stack contains a list of syntax subtrees. When you push a new item, its list starts off empty. When you shift (consume) a token, you add it to this list. When you pop, you take all the subtrees in the list of the top item, set them as children of the new node, and add this new subtree to the list of the new top of the item stack. Eventually, when you pop the last item off stack, you'll end up with a single subtree, which will be the entire syntax tree.

yuri kilochek
  • 12,709
  • 2
  • 32
  • 59
  • I understand. Could you maybe also give a small example. Maybe some graphics or something to make it easier to imagine? I would make it a bit easier to consume. – Asperger Apr 02 '17 at 10:52