﻿ 可设置语法阐明器开拓纪事（五） 结构一个真正能用的状态机（中） - C语言/C++ 教程

# 可设置语法阐明器开拓纪事（五） 结构一个真正能用的状态机（中）

2017-11-02 08:00 星期四 所属： C语言/C++ 教程 浏览：57

#p#副标题#e#

#p#副标题#e#

#p#分页标题#e#

#p#副标题#e#

```StartState: 22[Exp.RootStart]
\$TokenBegin => 23[Exp.Start]
State Stack:
NUMBER[1] => 2[Number.1]
State Stack: 23[Exp.Start], 21[Term.Start], 19[Factor.Start]
Shift 23[Exp]
Shift 21[Term]
Shift 19[Factor]
Assign value
Create NumberExpression
MUL[*] => 5[Term.3]
State Stack: 23[Exp.Start]
Reduce 19[Factor]
Using
Reduce 21[Term]

Using
LR-Reduce 21[Term]
Assign firstOperand
Setter binaryOperator = Mul
Create BinaryExpression
NUMBER[2] => 2[Number.1]
State Stack: 23[Exp.Start], 5[Term.3], 19[Factor.Start]
Shift 5[Term]
Shift 19[Factor]
Assign value
Create NumberExpression
State Stack:
Reduce 19[Factor]
Using
Reduce 5[Term]
Assign secondOperand
Reduce 23[Exp]
Using
LR-Reduce 23[Exp]
Assign firstOperand
Create BinaryExpression
NUMBER[3] => 2[Number.1]
State Stack: 10[Exp.3], 21[Term.Start], 19[Factor.Start]
Shift 10[Exp]
Shift 21[Term]
Shift 19[Factor]
Assign value
Create NumberExpression
MUL[*] => 5[Term.3]
State Stack: 10[Exp.3]
Reduce 19[Factor]
Using
Reduce 21[Term]
Using
LR-Reduce 21[Term]
Assign firstOperand
Setter binaryOperator = Mul
Create BinaryExpression
NUMBER[4] => 2[Number.1]
State Stack: 10[Exp.3], 5[Term.3], 19[Factor.Start]
Shift 5[Term]
Shift 19[Factor]
Assign value
Create NumberExpression
\$TokenFinish => 11[Exp.RootEnd]
State Stack:
Reduce 19[Factor]
Using
Reduce 5[Term]
Assign secondOperand
Reduce 10[Exp]
Assign secondOperand```

```BinaryExpression {
firstOperand = BinaryExpression {
binaryOperator = [Mul]
firstOperand = NumberExpression {
value = [1]
}
secondOperand = NumberExpression {
value = [2]
}
}
secondOperand = BinaryExpression {
binaryOperator = [Mul]
firstOperand = NumberExpression {
value = [3]
}
secondOperand = NumberExpression {
value = [4]
}
}
}```