用c语言表示文法E->S S->BB B->aB B->b的action表和goto表
时间: 2024-05-17 22:17:08 浏览: 14
根据这个文法构建的LR(1)分析表如下:
| 状态 | a | b | $ | S | B |
| :------: | :-------: | :-------: | :-------: | :-------: | :-------: |
| 0 | shift 2 | shift 3 | | 1 | 4 |
| 1 | | | acc | | |
| 2 | shift 2 | shift 3 | | 5 | 4 |
| 3 | shift 2 | shift 3 | | 6 | 4 |
| 4 | shift 2 | shift 3 | | | 7 |
| 5 | shift 2 | shift 3 | | | 8 |
| 6 | shift 2 | shift 3 | | | 9 |
| 7 | | | reduce 2 | | |
| 8 | | | reduce 1 | | |
| 9 | | | reduce 3 | | |
其中状态表示为数字,a、b、$ 分别表示读入字符 a、b 和输入串的结束符号。S、B 表示文法中的符号。shift 表示移进操作,reduce 表示规约操作,acc 表示分析成功。
根据上述分析表得到 action 表和 goto 表如下:
| 状态 | a | b | $ |
| :------: | :-------: | :-------: | :-------: |
| 0 | shift 2 | shift 3 | |
| 2 | shift 2 | shift 3 | |
| 3 | shift 2 | shift 3 | |
| 4 | shift 2 | shift 3 | |
| 5 | shift 2 | shift 3 | |
| 6 | shift 2 | shift 3 | |
| 7 | r2 | r2 | r2 |
| 8 | r1 | r1 | r1 |
| 9 | r3 | r3 | r3 |
| 状态 | S | B |
| :------: | :-------: | :-------: |
| 0 | 1 | 4 |
| 2 | 5 | 4 |
| 3 | 6 | 4 |
| 4 | | 7 |
| 5 | | 8 |
| 6 | | 9 |
| 7 | | |
| 8 | | |
| 9 | | |
相关推荐
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)