Skip to content

Commit

Permalink
debug basically done
Browse files Browse the repository at this point in the history
还留下了3个reduce/shift conflict,dangling-else可以直接用yacc内部机制修复,另外两个是是否var-declaration是否含有赋值的问题,也可以解决。
放了bison-3.7.6的安装包,他可以展示conflict 的例子,教程如下:
https://www.osetc.com/en/how-to-install-bison-gnu-parser-generator-on-ubuntu-16-04-18-04-linux.html

https://www.gnu.org/software/bison/manual/html_node/Counterexamples.html
  • Loading branch information
acnq committed Jun 3, 2021
1 parent d64afd8 commit 045c1fe
Show file tree
Hide file tree
Showing 8 changed files with 1,048 additions and 1,120 deletions.
Binary file added bison-3.7.6.tar.gz
Binary file not shown.
487 changes: 254 additions & 233 deletions lex.yy.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lexer.l
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "parser.tab.h"

static FILE* yyparse_file_ptr;
extern void yyerror(char* s);
extern void yyerror(std::string s);
%}

/*定义状态,第一句有点意义不明*/
Expand Down Expand Up @@ -171,4 +171,4 @@ int yywrap(void) {
return 1;
}



8 changes: 4 additions & 4 deletions our_syntax.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
1. *program $\rightarrow$ declaration-list*
2. *declaration-list* $\rightarrow$ *declaration-list* *declaration* | *declaration*
3. *declaration* $\rightarrow$ *var-declaration* | *fun-declaration*
4. *var-declaration* $\rightarrow$ *type-specifier* **ID** **;** | *base_type* **ID** **=** *expression* **;**
4. *var-declaration* $\rightarrow$ *type-specifier* **ID** **;** | *base_type* **ID** **=** *expression* **;** | *array-type* **ID ** = **{** *array-init-list* **}** **;**
5. *type-specifier* $\rightarrow$ *base-type* | *array-type*
6. *array-type* $\rightarrow$ *base-type* **[** **NUM** **]** | *array-type* **[** **NUM** **]** | *array-type* **[** **NUM** **]** **=** **{** *arr-init-list* **}** <!-- 我们不支持定义数组的时候方括号内含有表达式 --> <!--支持多维数组-->
7. *arr-init-list* $\rightarrow$ *arr-init-list* **,** *arr-init* | *arr-init*
8. *arr-init* $\rightarrow$ **{** *arr-init-list* **}** | **NUM** <!--注意这里要有方法判断括号的嵌套-->
6. *array-type* $\rightarrow$ *base-type* **[** **NUM** **]** | *array-type* **[** **NUM** **]** <!-- 我们不支持定义数组的时候方括号内含有表达式 --> <!--支持多维数组-->
7. *array-init-list* $\rightarrow$ *array-init-list* **,** *array-init* | *array-init*
8. *array-init* $\rightarrow$ **{** *array-init-list* **}** | **NUM** <!--注意这里要有方法判断括号的嵌套-->
9. *base_type* $\rightarrow$ **int** | **void** | **double** | **float** | **char** | **bool**
10. *fun-declaration* $\rightarrow$ *type-specifier* **ID** **(** *params* **)** *compound-stmt* | **extern** *type-specifier* **ID** **(** *params* **)** <!--这里实现了extern函数-->
11. *params* $\rightarrow$ *param-list* | **void**
Expand Down
Loading

0 comments on commit 045c1fe

Please sign in to comment.