1, theoretical basis
- Context-free grammar
- Pushdown automata (PDA)
2, parsing mode
- Top-down analysis (-PDA on top of the stack, the lower stack bottom -PDA)
- Bottom-up analysis
- Priority analysis
- LR analysis
3、PDA
PDA definitions:
-
usage:
-
When reading the input string, and the push-down stack is empty; or read the input string, and the controller reaches certain final state
-
Principle Analysis:
- Pushdown stack placed inside S (nonterminal as: S-> Sb | c), input with a specific statement as a + b #, compared to the statements in the push-down stack S, if the same, disappear, read head moved back one, continue to compare
- When pushing the stack is empty, and the input band is empty (the read head to the end) to match the ends.
- If the push-down stack top element has been completed backtracking all possible states, still can not match the position of the input with the read head, - "do not match, an error, the end.
-
4, a top down analysis of the disadvantages backtracking
- If the grammar there is left recursive , there will be an infinite loop
- If there are multiple production candidate type , select which derivation is completely blind.
- Back, time & space consumption
- If the identification statement is wrong, but can not point out exactly what is wrong.
5, the top-down analysis algorithm without backtracking
- Eliminate left recursion (such as: P-> Pa)