date:2024-12-01title: Compiler-Solution For LR Parsing Algorithm, LR(0) items, SLR Parsing Table Construction
status: DONE
author:- AllenYGY
tags:- NOTE
- Compiler
publish:true
Compiler-Solution For LR Parsing Algorithm, LR(0) items, SLR Parsing Table Construction
LR Parsing Algorithm
Put the special symbol $ at the end of the input.
Put state 0 at the bottom of the stack.
In each iteration, suppose the current configuration is the current state is and the next input token is
If is "", then the next configuration is
If is "", then the next configuration is where and . At the same time, the parser outputs 就是下一个栈顶元素,换句话说就是当前状态的上一个状态
首先先判断归约的 Production Rule,可以知道当前的token 会被归约成哪个token
然后根据 token,去找到下一个状态
If is "accept" and the current configuration is Where is the start symbol of the grammar, the parser accepts the input.
For all other cases, like is blank, the parser finds a syntax error and switch to error recovery.