请根据上述举例
时间: 2024-02-22 22:57:35 浏览: 83
参考例子
3星 · 编辑精心推荐
假设有以下文法:
```
S -> E
E -> T + E | T
T -> int | (E)
```
对于这个文法,我们可以计算出各个符号的First集和Follow集:
- First(S) = {int, (}
- First(E) = {int, (}
- First(T) = {int, (}
- Follow(S) = {$}
- Follow(E) = {+, $}
- Follow(T) = {+, $}
接下来,我们来计算FIRSTVT和LASTVT集合:
- FIRSTVT(S) = {int, (}
- FIRSTVT(E) = {int, (}
- FIRSTVT(T) = {int, (}
- LASTVT(S) = {int, )}
- LASTVT(E) = {int, )}
- LASTVT(T) = {int}
同时,我们还可以根据FIRSTVT和LASTVT集合计算出各个产生式的活跃变量:
- S -> E
- 没有活跃变量
- E -> T + E
- 活跃变量 = FIRSTVT(T)
- E -> T
- 活跃变量 = FIRSTVT(T)
- T -> int
- 活跃变量 = {int}
- T -> (E)
- 活跃变量 = FIRSTVT(E) = {int, (}
阅读全文