Commit 4eae2dbe authored by Kai Ma's avatar Kai Ma

[Lab1] Publish

parents
project(CMINUSF)
cmake_minimum_required( VERSION 3.4 )
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} -std=c99")
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_C_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
set(CMAKE_C_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
set(CMAKE_CXX_STANDARD 17)
find_package(FLEX REQUIRED)
find_package(BISON REQUIRED)
find_package(LLVM REQUIRED CONFIG)
message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
llvm_map_components_to_libnames(
llvm_libs
support
core
)
INCLUDE_DIRECTORIES(
include
${LLVM_INCLUDE_DIRS}
)
add_definitions(${LLVM_DEFINITIONS})
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR})
include_directories(${PROJECT_SOURCE_DIR})
include_directories(${PROJECT_BINARY_DIR})
add_subdirectory(src)
add_subdirectory(tests)
# 基础知识
在本次实验中,我们将用到`Flex``Bison`两个工具以及`Cminus-f`语言。这里对其进行简单介绍。
## Cminus-f词法
`Cminus`是C语言的一个子集,该语言的语法在《编译原理与实践》第九章附录中有详细的介绍。而`Cminus-f`则是在`Cminus`上追加了浮点操作。
1. 关键字
```c
else if int return void while float
```
2. 专用符号
```c
+ - * / < <= > >= == != = ; , ( ) [ ] { } /* */
```
3. 标识符ID和整数NUM,通过下列正则表达式定义:
```c
letter = a|...|z|A|...|Z
digit = 0|...|9
ID = letter+
INTEGER = digit+
FLOAT = (digit+. | digit*.digit+)
```
4. 注释用`/*...*/`表示,可以超过一行。注释不能嵌套。
```c
/*...*/
```
## Cminus-f语法
本小节将给出Cminus-f的语法,该语法在Cminus语言(《编译原理与实践》第九章附录)的基础上增加了float类型。
我们将 Cminus-f 的所有规则分为五类。
1. 字面量、关键字、运算符与标识符
- `id`
- `type-specifier`
- `relop`
- `addop`
- `mulop`
2. 声明
- `declaration-list`
- `declaration`
- `var-declaration`
- `fun-declaration`
- `local-declarations`
3. 语句
- `compound-stmt`
- `statement-list`
- `statement`
- `expression-stmt`
- `iteration-stmt`
- `selection-stmt`
- `return-stmt`
4. 表达式
- `expression`
- `var`
- `additive-expression`
- `term`
- `factor`
- `integer`
- `float`
- `call`
5. 其他
- `params`
- `param-list`
- `param`
- `args`
- `arg-list`
起始符号是 `program`。文法中用到的 token 均以下划线和粗体标出。
1. $`\text{program} \rightarrow \text{declaration-list}`$
2. $`\text{declaration-list} \rightarrow \text{declaration-list}\ \text{declaration}\ |\ \text{declaration}`$
3. $`\text{declaration} \rightarrow \text{var-declaration}\ |\ \text{fun-declaration}`$
4. $`\text{var-declaration}\ \rightarrow \text{type-specifier}\ \underline{\textbf{ID}}\ \textbf{;}\ |\ \text{type-specifier}\ \underline{\textbf{ID}}\ \underline{\textbf{[}}\ \underline{\textbf{INTEGER}}\ \underline{\textbf{]}}\ \textbf{;}`$
5. $`\text{type-specifier} \rightarrow \underline{\textbf{int}}\ |\ \underline{\textbf{float}}\ |\ \underline{\textbf{void}}`$
6. $`\text{fun-declaration} \rightarrow \text{type-specifier}\ \underline{\textbf{ID}}\ \underline{\textbf{(}}\ \text{params}\ \underline{\textbf{)}}\ \text{compound-stmt}`$
7. $`\text{params} \rightarrow \text{param-list}\ |\ \underline{\textbf{void}}`$
8. $`\text{param-list} \rightarrow \text{param-list}\ ,\ \text{param}\ |\ \text{param}`$
9. $`\text{param} \rightarrow \text{type-specifier}\ \underline{\textbf{ID}}\ |\ \text{type-specifier}\ \underline{\textbf{ID}}\ \underline{\textbf{[}}\ \underline{\textbf{]}}`$
10. $`\text{compound-stmt} \rightarrow \underline{\textbf{\{}}\ \text{local-declarations}\ \text{statement-list} \underline{\textbf{\}}}`$
11. $`\text{local-declarations} \rightarrow \text{local-declarations var-declaration}\ |\ \text{empty}`$
12. $`\text{statement-list} \rightarrow \text{statement-list}\ \text{statement}\ |\ \text{empty}`$
13. $`\begin{aligned}\text{statement} \rightarrow\ &\text{expression-stmt}\\ &|\ \text{compound-stmt}\\ &|\ \text{selection-stmt}\\ &|\ \text{iteration-stmt}\\ &|\ \text{return-stmt}\end{aligned}`$
14. $`\text{expression-stmt} \rightarrow \text{expression}\ \underline{\textbf{;}}\ |\ \underline{\textbf{;}}`$
15. $`\begin{aligned}\text{selection-stmt} \rightarrow\ &\underline{\textbf{if}}\ \underline{\textbf{(}}\ \text{expression}\ \underline{\textbf{)}}\ \text{statement}\\ &|\ \underline{\textbf{if}}\ \underline{\textbf{(}}\ \text{expression}\ \underline{\textbf{)}}\ \text{statement}\ \underline{\textbf{else}}\ \text{statement}\end{aligned}`$
16. $`\text{iteration-stmt} \rightarrow \underline{\textbf{while}}\ \underline{\textbf{(}}\ \text{expression}\ \underline{\textbf{)}}\ \text{statement}`$
17. $`\text{return-stmt} \rightarrow \underline{\textbf{return}}\ \underline{\textbf{;}}\ |\ \underline{\textbf{return}}\ \text{expression}\ \underline{\textbf{;}}`$
18. $`\text{expression} \rightarrow \text{var}\ \textbf{=}\ \text{expression}\ |\ \text{simple-expression}`$
19. $`\text{var} \rightarrow \underline{\textbf{ID}}\ |\ \underline{\textbf{ID}}\ \underline{\textbf{[}}\ \text{expression} \underline{\textbf{]}}`$
20. $`\text{simple-expression} \rightarrow \text{additive-expression}\ \text{relop}\ \text{additive-expression}\ |\ \text{additive-expression}`$
21. $`\text{relop}\ \rightarrow \underline{\textbf{<=}}\ |\ \underline{\textbf{<}}\ |\ \underline{\textbf{>}}\ |\ \underline{\textbf{>=}}\ |\ \underline{\textbf{==}}\ |\ \underline{\textbf{!=}}`$
22. $`\text{additive-expression} \rightarrow \text{additive-expression}\ \text{addop}\ \text{term}\ |\ \text{term}`$
23. $`\text{addop} \rightarrow \underline{\textbf{+}}\ |\ \underline{\textbf{-}}`$
24. $`\text{term} \rightarrow \text{term}\ \text{mulop}\ \text{factor}\ |\ \text{factor}`$
25. $`\text{mulop} \rightarrow \underline{\textbf{*}}\ |\ \underline{\textbf{/}}`$
26. $`\text{factor} \rightarrow \underline{\textbf{(}}\ \text{expression}\ \underline{\textbf{)}}\ |\ \text{var}\ |\ \text{call}\ |\ \text{integer}\ |\ \text{float}`$
27. $`\text{integer} \rightarrow \underline{\textbf{INTEGER}}`$
28. $`\text{float} \rightarrow \underline{\textbf{FLOATPOINT}}`$
29. $`\text{call} \rightarrow \underline{\textbf{ID}}\ \underline{\textbf{(}}\ \text{args} \underline{\textbf{)}}`$
30. $`\text{args} \rightarrow \text{arg-list}\ |\ \text{empty}`$
31. $`\text{arg-list} \rightarrow \text{arg-list}\ \underline{\textbf{,}}\ \text{expression}\ |\ \text{expression}`$
## Flex用法简介
`FLEX`是一个生成词法分析器的工具。利用`FLEX`,我们只需提供词法的正则表达式,就可自动生成对应的C代码。整个流程如下图:
[![img](http://alumni.cs.ucr.edu/~lgao/teaching/Img/flex.jpg)](http://alumni.cs.ucr.edu/~lgao/teaching/Img/flex.jpg)
首先,`FLEX`从输入文件`*.lex`或者`stdio`读取词法扫描器的规范,从而生成C代码源文件`lex.yy.c`。然后,编译`lex.yy.c`并与`-lfl`库链接,以生成可执行的`a.out`。最后,`a.out`分析其输入流,将其转换为一系列token。
简答的说,`Flex`根据用户定义的正则表达式对输入的字符串进行分析,生成token stream。在我们的编译原理实验中,token stream将被用于后续的语法树生成等后续工作。一个简单的示意如下:
```shell
"int main() {int a; a = 1;}" #main.c文件,现在是一个文本
-> flex分析
-> "}" ";" "1" "=" "a" ";" "a" "int" "{" ")" "(" "main" "int" # 生成的token stream
# >>>>>>>>>>>>>>>>>>token stream>>>>>>>>>>>>>>>>>>>>>>>>>>>>
```
我们以一个简单的单词数量统计的程序`wc.l`为详细介绍下`Flex`的功能和用法(请仔细看程序中的注释内容):
```c
%option noyywrap
%{
//在%{和%}中的代码会被原样照抄到生成的lex.yy.c文件的开头,也就是在%{和}%中,你应该按C语言写代码,在这里可以完成变量声明与定义、相关库的导入和函数定义
#include <string.h>
int chars = 0;
int words = 0;
%}
%%
/* 注意这里的%%开头*/
/* %%开头和%%结尾之间的内容就是使用flex进行解析的部分 */
/* 你可以按照我这种方式在这个部分写注释,注意注释最开头的空格,这是必须的 */
/* 你可以在这里使用你熟悉的正则表达式来编写模式, 你可以用C代码来指定模式匹配时对应的动作 */
/* 在%%和%%之间,你应该按照如下的方式写模式和动作 */
/* 模式 动作 */
/* 其中模式就是正则表达式,动作为模式匹配执行成功后执行相应的动作,这里的动作就是相应的代码 */
/* 你可以仔细研究下后面的例子 */
/* [a-zA-Z]+ 为正则表达式,用于匹配大小写字母 */
/* {chars += strlen(yytext);words++;} 则为匹配到大小写字母后,执行的动作(代码),这里是完成一个字符累加操作 */
/* 这里yytext的类型为 char*, 是一个指向匹配到字符串的指针 */
/* yytext是flex自动生成的,在%%和%%之中无需额外定义或者声明 */
/* 一条 模式 + 动作 */
[a-zA-Z]+ { chars += strlen(yytext);words++;}
/* 另一条 模式 + 动作; . 匹配任意字符,这里匹配非大小写字母的其他字符。这里思考一个问题,A既可以被[a-zA-Z]+匹配,也可以被.匹配,在这个程序中为什么A优先被[a-zA-Z]+匹配?如果你感兴趣可以去看另一个文档 */
. {}
/* 对其他所有字符,不做处理,继续执行 */
/* 注意这里的%%结尾 */
%%
// flex部分结束,这里可以正常写c代码了
int main(int argc, char **argv){
// yylex()是flex提供的词法分析例程,调用yylex()即开始执行Flex的词法分析,同样的yylex()也是flex自行生成的,无需额外定义和生成,默认输入读取stdin
// 如果不清楚什么是stdin,可以自己百度查一下
yylex();
// 输出 words和chars,这些变量在匹配过程中,被执行相应的动作
printf("look, I find %d words of %d chars\n", words, chars);
return 0;
}
```
使用Flex生成lex.yy.c
```shell
$ flex wc.l
$ gcc lex.yy.c
$ ./a.out
hello world
^D
look, I find 2 words of 10 chars
```
*注: 在以stdin为输入时,需要按下ctrl+D以退出*
至此,你已经成功使用Flex完成了一个简单的分析器!
为了对实验有较好的体验,我建议你好好阅读以下两个关于flex文档:
* [Flex matching](./Flex-matching.md)
* [Flex regular expressions](./Flex-regular-expressions.md)
## Bison用法简介
Bison 是一款解析器生成器(parser generator),它可以将 LALR 文法转换成可编译的 C 代码,从而大大减轻程序员手动设计解析器的负担。Bison 是 GNU 对早期 Unix 的 Yacc 工具的一个重新实现,所以文件扩展名为 `.y`。(Yacc 的意思是 Yet Another Compiler Compiler。)
### 识别一个简单的语言
下面我们以一个简单的语言为例,介绍 Bison 的用法。
每个 Bison 文件由 `%%` 分成三部分。
```c
%{
#include <stdio.h>
/* 这里是序曲 */
/* 这部分代码会被原样拷贝到生成的 .c 文件的开头 */
int yylex(void);
void yyerror(const char *s);
%}
/* 这些地方可以输入一些 bison 指令 */
/* 比如用 %start 指令指定起始符号,用 %token 定义一个 token */
%start reimu
%token REIMU
%%
/* 从这里开始,下面是解析规则 */
reimu : marisa { /* 这里写与该规则对应的处理代码 */ puts("rule1"); }
| REIMU { /* 这里写与该规则对应的处理代码 */ puts("rule2"); }
; /* 规则最后不要忘了用分号结束哦~ */
/* 这种写法表示 ε —— 空输入 */
marisa : { puts("Hello!"); }
%%
/* 这里是尾声 */
/* 这部分代码会被原样拷贝到生成的 .c 文件的末尾 */
int yylex(void)
{
int c = getchar(); // 从 stdin 获取下一个字符
switch (c) {
case EOF: return YYEOF;
case 'R': return REIMU;
default: return 0; // 返回无效 token 值,迫使 bison 报错
}
}
void yyerror(const char *s)
{
fprintf(stderr, "%s\n", s);
}
int main(void)
{
yyparse(); // 启动解析
return 0;
}
```
另外有一些值得注意的点:
1. Bison 传统上将 token 用大写单词表示,将 symbol 用小写字母表示。
2. Bison 能且只能生成解析器源代码(一个 `.c` 文件),并且入口是 `yyparse`,所以为了让程序能跑起来,你需要手动提供 `main` 函数(但不一定要在 `.y` 文件中——你懂“链接”是什么,对吧?)。
3. Bison 不能检测你的 action code 是否正确——它只能检测文法的部分错误,其他代码都是原样粘贴到 `.c` 文件中。
4. Bison 需要你提供一个 `yylex` 来获取下一个 token。
5. Bison 需要你提供一个 `yyerror` 来提供合适的报错机制。
顺便提一嘴,上面这个 `.y` 是可以工作的——尽管它只能接受两个字符串。把上面这段代码保存为 `reimu.y`,执行如下命令来构建这个程序:
```shell
$ bison reimu.y
$ gcc reimu.tab.c
$ ./a.out
R<-- 不要回车在这里按 Ctrl-D
rule2
$ ./a.out
<-- 不要回车在这里按 Ctrl-D
Hello!
rule1
$ ./a.out
blablabla <-- 回车或者 Ctrl-D
Hello!
rule1 <-- 匹配到了 rule1
syntax error <-- 发现了错误
```
于是我们验证了上述代码的确识别了该文法定义的语言 `{ "", "R" }`
### Bison 和 Flex 联动
聪明的你应该发现了,我们这里手写了一个 `yylex` 函数作为词法分析器。而在上文中我们正好使用 flex 自动生成了一个词法分析器。如何让这两者协同工作呢?特别是,我们需要在这两者之间共享 token 定义和一些数据,难道要手动维护吗?哈哈,当然不用!下面我们用一个四则运算计算器来简单介绍如何让 bison 和 flex 协同工作——重点是如何维护解析器状态、`YYSTYPE` 和头文件的生成。
首先,我们必须明白,整个工作流程中,bison 是占据主导地位的,而 flex 仅仅是一个辅助工具,仅用来生成 `yylex` 函数。因此,最好先写 `.y` 文件。
```c
/* calc.y */
%{
#include <stdio.h>
int yylex(void);
void yyerror(const char *s);
%}
%token RET
%token <num> NUMBER
%token <op> ADDOP MULOP LPAREN RPAREN
%type <num> top line expr term factor
%start top
%union {
char op;
double num;
}
%%
top
: top line {}
| {}
line
: expr RET
{
printf(" = %f\n", $1);
}
expr
: term
{
$$ = $1;
}
| expr ADDOP term
{
switch ($2) {
case '+': $$ = $1 + $3; break;
case '-': $$ = $1 - $3; break;
}
}
term
: factor
{
$$ = $1;
}
| term MULOP factor
{
switch ($2) {
case '*': $$ = $1 * $3; break;
case '/': $$ = $1 / $3; break; // 想想看,这里会出什么问题?
}
}
factor
: LPAREN expr RPAREN
{
$$ = $2;
}
| NUMBER
{
$$ = $1;
}
%%
void yyerror(const char *s)
{
fprintf(stderr, "%s\n", s);
}
```
```c
/* calc.l */
%option noyywrap
%{
/* 引入 calc.y 定义的 token */
#include "calc.tab.h"
%}
%%
\( { return LPAREN; }
\) { return RPAREN; }
"+"|"-" { yylval.op = yytext[0]; return ADDOP; }
"*"|"/" { yylval.op = yytext[0]; return MULOP; }
[0-9]+|[0-9]+\.[0-9]*|[0-9]*\.[0-9]+ { yylval.num = atof(yytext); return NUMBER; }
" "|\t { }
\r\n|\n|\r { return RET; }
%%
```
最后,我们补充一个 `driver.c` 来提供 `main` 函数。
```c
int yyparse();
int main()
{
yyparse();
return 0;
}
```
使用如下命令构建并测试程序:
```shell
$ bison -d calc.y
(生成 calc.tab.c 和 calc.tab.h。如果不给出 -d 参数,则不会生成 .h 文件。)
$ flex calc.l
(生成 lex.yy.c)
$ gcc lex.yy.c calc.tab.c driver.c -o calc
$ ./calc
1+1
= 1.000000
2*(1+1)
= 4.000000
2*1+1
= 3.000000
```
如果你复制粘贴了上述程序,可能会觉得很神奇,并且有些地方看不懂。下面就详细讲解上面新出现的各种构造。
* `YYSTYPE`: 在 bison 解析过程中,每个 symbol 最终都对应到一个语义值上。或者说,在 parse tree 上,每个节点都对应一个语义值,这个值的类型是 `YYSTYPE``YYSTYPE` 的具体内容是由 `%union` 构造指出的。上面的例子中,
```c
%union {
char op;
double num;
}
```
会生成类似这样的代码
```c
typedef union YYSTYPE {
char op;
double num;
} YYSTYPE;
```
为什么使用 `union` 呢?因为不同节点可能需要不同类型的语义值。比如,上面的例子中,我们希望 `ADDOP` 的值是 `char` 类型,而 `NUMBER` 应该是 `double` 类型的。
* `$$``$1`, `$2`, `$3`, ...:现在我们来看如何从已有的值推出当前节点归约后应有的值。以加法为例:
```c
term : term ADDOP factor
{
switch $2 {
case '+': $$ = $1 + $3; break;
case '-': $$ = $1 - $3; break;
}
}
```
其实很好理解。当前节点使用 `$$` 代表,而已解析的节点则是从左到右依次编号,称作 `$1`, `$2`, `$3`...
* `%type <>``%token <>`:注意,我们上面可没有写 `$1.num` 或者 `$2.op` 哦!那么 bison 是怎么知道应该用 `union` 的哪部分值的呢?其秘诀就在文件一开始的 `%type``%token` 上。
例如,`term` 应该使用 `num` 部分,那么我们就写
```c
%type <num> term
```
这样,以后用 `$` 去取某个值的时候,bison 就能自动生成类似 `stack[i].num` 这样的代码了。
`%token<>` 见下一条。
* `%token`:当我们用 `%token` 声明一个 token 时,这个 token 就会导出到 `.h` 中,可以在 C 代码中直接使用(注意 token 名千万不要和别的东西冲突!),供 flex 使用。`%token <op> ADDOP` 与之类似,但顺便也将 `ADDOP` 传递给 `%type`,这样一行代码相当于两行代码,岂不是很赚。
* `yylval`:这时候我们可以打开 `.h` 文件,看看里面有什么。除了 token 定义,最末尾还有一个 `extern YYSTYPE yylval;` 。这个变量我们上面已经使用了,通过这个变量,我们就可以在 lexer **里面**设置某个 token 的值。
呼……说了这么多,现在回头看看上面的代码,应该可以完全看懂了吧!这时候你可能才意识到为什么 flex 生成的分析器入口是 `yylex`,因为这个函数就是 bison 专门让程序员自己填的,作为一种扩展机制。另外,bison(或者说 yacc)生成的变量和函数名通常都带有 `yy` 前缀,希望在这里说还不太晚……
最后还得提一下,尽管上面所讲已经足够应付很大一部分解析需求了,但是 bison 还有一些高级功能,比如自动处理运算符的优先级和结合性(于是我们就不需要手动把 `expr` 拆成 `factor`, `term` 了)。这部分功能,就留给同学们自己去探索吧!
# Flex matching -- How the Input Is Matched
This document is from `The flex Manual`. For better experience, we recommend you to read the original documents. `The flex Manual` can be read with `info flex` in terminal.
```shell
$ info flex
# choose Matching node
```
However, the following is enough for you to finish labs.
Note: if there is any discrepancy, please refer to `The flex Manual`.
**************************
When the generated scanner is run, it analyzes its input looking for strings which match any of its patterns. If it finds more than one match, it takes the one matching the most text (for trailing context rules, this includes the length of the trailing part, even though it will then be returned to the input). If it finds two or more matches of the same length, the rule listed first in the `flex` input file is chosen.
Once the match is determined, the text corresponding to the match (called the "token") is made available in the global character pointer `yytext`, and its length in the global integer `yyleng`. The "action" corresponding to the matched pattern is then executed, and then the remaining input is scanned for another match.
If no match is found, then the "default rule" is executed: the next character in the input is considered matched and copied to the standard output. Thus, the simplest valid `flex` input is:
```c
%%
```
which generates a scanner that simply copies its input (one character at a time) to its output.
Note that `yytext` can be defined in two different ways: either as a character _pointer_ or as a character _array_. You can control which definition `flex` uses by including one of the special directives `%pointer` or `%array` in the first (definitions) section of your flex input. The default is `%pointer`, unless you use the `-l` lex compatibility option, in which case `yytext` will be an array. The advantage of using `%pointer` is substantially faster scanning and no buffer overflow when matching very large tokens (unless you run out of dynamic memory). The disadvantage is that you are restricted in how your actions can modify `yytext`, and calls to the `unput()` function destroys the present contents of `yytext`, which can be a considerable porting headache when moving between different `lex` versions.
The advantage of `%array` is that you can then modify `yytext` to your heart‘s content, and calls to `unput()` do not destroy `yytext`. Furthermore, existing `lex` programs sometimes access `yytext` externally using declarations of the form:
```c
extern char yytext[];
```
This definition is erroneous when used with `%pointer`, but correct for `%array`.
The `%array` declaration defines `yytext` to be an array of `YYLMAX` characters, which defaults to a fairly large value. You can change the size by simply #define'ing `YYLMAX` to a different value in the first section of your `flex` input. As mentioned above, with `%pointer` yytext grows dynamically to accommodate large tokens. While this means your `%pointer` scanner can accommodate very large tokens (such as matching entire blocks of comments), bear in mind that each time the scanner must resize `yytext` it also must rescan the entire token from the beginning, so matching such tokens can prove slow. `yytext` presently does _not_ dynamically grow if a call to `unput()` results in too much text being pushed back; instead, a run-time error results.
Also note that you cannot use `%array` with C++ scanner classes
## Flex regular expressions
This document is from `The flex Manual`. For better experience, we recommend you to read the original documents. `The flex Manual` can be read with `info flex` in terminal.
```shell
$ info flex
# choose Patterns node
```
However, the following is enough for you to finish labs.
Note: if there is any discrepancy, please refer to `The flex Manual`.
---
The patterns in the input are written using an extended set of regular expressions. These are:
* `x`
match the character `x`
* `.`
any character (byte) except newline
* `[xyz]`
a "character class"; in this case, the pattern matches either an `x`, a `y`, or a `z`
* `[abj-oZ]`
a "character class" with a range in it; matches an `a`, a `b`, any letter from `j` through `o`, or a `Z`
* `[^A-Z]`
a "negated character class", i.e., any character but those in the class. In this case, any character EXCEPT an uppercase letter.
* `[^A-Z\n]`
any character EXCEPT an uppercase letter or a newline
* `[a-z]{-}[aeiou]`
the lowercase consonants
* `r*`
zero or more r`s, where r is any regular expression
* `r+`
one or more r`s
* `r?`
zero or one r`s (that is, "an optional r")
* `r{2,5}`
anywhere from two to five `r`
* `r{2,}`
two or more `r`
* `r{4}`
exactly 4 `r`
* `"[xyz]\"foo"`
the literal string: `[xyz]"foo`
* `\X`
if X is `a`, `b`, `f`, `n`, `r`, `t`, or `v`, then the ANSI-C interpretation of `\x`. Otherwise, a literal `X` (used to escape operators such as `*`)
* `\0`
a NUL character (ASCII code 0)
* `\123`
the character with octal value 123
* `\x2a`
the character with hexadecimal value 2a
* `(r)`
match an `r`; parentheses are used to override precedence (see below)
* `(?r-s:pattern)`
apply option `r` and omit option `s` while interpreting pattern. Options may be zero or more of the characters `i`, `s`, or `x`.
`i` means case-insensitive. `-i` means case-sensitive.
`s` alters the meaning of the `.` syntax to match any single byte whatsoever. `-s` alters the meaning of `.` to match any byte except `\n`.
`x` ignores comments and whitespace in patterns. Whitespace is ignored unless it is backslash-escaped, contained within `""`s, or appears inside a character class.
The following are all valid:
* `(?:foo)` same as `(foo)`
* `(?i:ab7)` same as `([aA][bB]7)`
* `(?-i:ab)` same as `(ab)`
* `(?s:.) ` same as `[\x00-\xFF]`
* `(?-s:.)` same as `[^\n]`
* `(?ix-s: a . b)` same as `([Aa][^\n][bB])`
* `(?x:a b)` same as `("ab")`
* `(?x:a\ b)` same as `("a b")`
* `(?x:a" "b) ` same as` ("a b")`
* `(?x:a[ ]b) ` same as `("a b")`
* ```shell
(?x:a
/* comment */
b
c)
```
same as `(abc)`
* `(?# comment )`
omit everything within `()`. The first `)` character encountered ends the pattern. It is not possible to for the comment to contain a `)` character. The comment may span lines.
* `rs`
the regular expression `r` followed by the regular expression `s`; called "concatenation"
* `r|s`
either an `r` or an `s`
* `r/s`
an `r` but only if it is followed by an `s`. The text matched by `s` is included when determining whether this rule is the longest match, but is then returned to the input before the action is executed. So the action only sees the text matched by `r`. This type of pattern is called "trailing context". (There are some combinations of `r/s` that flex cannot match correctly.)
* `^r`
an `r`, but only at the beginning of a line (i.e., when just starting to scan, or right after a newline has been scanned).
* `r$`
an `r`, but only at the end of a line (i.e., just before a newline). Equivalent to `r/\n`.
Note that `flex`s notion of "newline" is exactly whatever the C compiler used to compile `flex` interprets `\n` as; in particular, on some DOS systems you must either filter out `\r`s in the input yourself, or explicitly use `r/\r\n` for `r$`.
* `<s>r`
an `r`, but only in start condition `s`.
* `<s1,s2,s3>r`
same, but in any of start conditions `s1`, `s2`, or `s3`.
* `<*>r`
an `r` in any start condition, even an exclusive one.
* `<<EOF>>`
an end-of-file.
* `<s1,s2><<EOF>>`
an end-of-file when in start condition `s1` or `s2`
Note that inside of a character class, all regular expression operators lose their special meaning except escape (`\`) and the character class operators, `-`, `]]`, and, at the beginning of the class, `^`.
The regular expressions listed above are grouped according to precedence, from highest precedence at the top to lowest at the bottom. Those grouped together have equal precedence (see special note on the precedence of the repeat operator, `{}`, under the documentation for the `--posix` POSIX compliance option). For example,
`foo|bar*` is the same as `(foo)|(ba(r*))`
Since the `*` operator has higher precedence than concatenation, and concatenation higher than alternation (`|`). This pattern therefore matches _either_ the string `foo` _or_ the string `ba` followed by zero-or-more `r`'s. To match `foo` or zero-or-more repetitions of the string `bar`, use:
` foo|(bar)*`
And to match a sequence of zero or more repetitions of `foo` and`bar`:
`(foo|bar)*`
In addition to characters and ranges of characters, character classes can also contain "character class expressions". These are expressions enclosed inside `[:` and `:]` delimiters (which themselves must appear between the `[` and `]` of the character class. Other elements may occur inside the character class, too). The valid expressions are:
`[:alnum:]` `[:alpha:]` `[:blank:]`
`[:cntrl:]` `[:digit:]` `[:graph:]`
`[:lower:]` `[:print:]` `[:punct:]`
`[:space:]` `[:upper:]` `[:xdigit:]`
These expressions all designate a set of characters equivalent to the corresponding standard C `isXXX` function. For example, `[:alnum:]` designates those characters for which `isalnum()` returns true - i.e., any alphabetic or numeric character. Some systems don't provide `isblank()`, so flex defines `[:blank:]` as a blank or a tab.
For example, the following character classes are all equivalent:
* `[[:alnum:]]`
* `[[:alpha:][:digit:]]`
* `[[:alpha:][0-9]]`
* `[a-zA-Z0-9]`
A word of caution. Character classes are expanded immediately when seen in the `flex` input. This means the character classes are sensitive to the locale in which `flex` is executed, and the resulting scanner will not be sensitive to the runtime locale. This may or may not be desirable.
* If your scanner is case-insensitive (the `-i` flag), then
`[:upper:]` and `[:lower:]` are equivalent to `[:alpha:]`.
* Character classes with ranges, such as `[a-Z]`, should be used with caution in a case-insensitive scanner if the range spans upper or lowercase characters. Flex does not know if you want to fold all upper and lowercase characters together, or if you want the literal numeric range specified (with no case folding). When in doubt, flex will assume that you meant the literal numeric range, and will issue a warning. The exception to this rule is a character range such as `[a-z]` or `[S-W]` where it is obvious that you want case-folding to occur. Here are some examples with the `-i` flag enabled:
| Range | Result | Literal Range | Alternate Range |
| ------- | --------- | ------------------ | ------------------- |
| `[a-t]` | ok | `[a-tA-T]` | |
| `[A-T]` | ok | `[a-tA-T]` | |
| `[A-t]` | ambiguous | `[A-Z\[\\\]_'a-t]` | `[a-tA-T]` |
| `[_-{]` | ambiguous | `[_'a-z{]` | `[_'a-zA-Z{]` |
| `[@-C]` | ambiguous | `[@ABC]` | `[@A-Z\[\\\]_'abc]` |
* A negated character class such as the example `[^A-Z]` above _will_ match a newline unless `\n` (or an equivalent escape sequence) is one of the characters explicitly present in the negated character class (e.g., `[^A-Z\n]`). This is unlike how many other regular expression tools treat negated character classes, but unfortunately the inconsistency is historically entrenched. Matching newlines means that a pattern like `[^"]*` can match the entire input unless there`s another quote in the input.
Flex allows negation of character class expressions by prepending `^` to the POSIX character class name.
`[:^alnum:]` `[:^alpha:]` `[:^blank:]`
`[:^cntrl:]` `[:^digit:]` `[:^graph:]`
`[:^lower:]` `[:^print:]` `[:^punct:]`
`[:^space:]` `[:^upper:]` `[:^xdigit:]`
Flex will issue a warning if the expressions `[:^upper:]` and`[:^lower:]` appear in a case-insensitive scanner, since their meaning is unclear. The current behavior is to skip them entirely, but this may change without notice in future revisions of flex.
* The `{-}` operator computes the difference of two character classes. For example, `[a-c]{-}[b-z]` represents all the characters in the class `[a-c]` that are not in the class `[b-z]` (which in this case, is just the single character `a`). The `{-}` operator is left associative, so `[abc]{-}[b]{-}[c]` is the same as `[a]`. Be careful not to accidentally create an empty set, which will never match.
* The `{+}` operator computes the union of two character classes. For example, `[a-z]{+}[0-9]` is the same as `[a-z0-9]`. This operator is useful when preceded by the result of a difference operation, as in, `[[:alpha:]]{-}[[:lower:]]{+}[q]`, which is equivalent to `[A-Zq]` in the "C" locale.
* A rule can have at most one instance of trailing context (the `/` operator or the `$` operator). The start condition, `^`, and `<<EOF>>` patterns can only occur at the beginning of a pattern, and, as well as with `/` and `$`, cannot be grouped inside parentheses. A `^` which does not occur at the beginning of a rule or a `$` which does not occur at the end of a rule loses its special properties and is treated as a normal character.
* The following are invalid:
`foo/bar$`
`<sc1>foo<sc2>bar`
Note that the first of these can be written `foo/bar\n`.
* The following will result in `$` or `^` being treated as a normal character:
`foo|(bar$)`
``foo|^bar`
If the desired meaning is a `foo` or a `bar`-followed-by-a-newline, the following could be used (the special `|` action is explained below):
```shell
foo |
bar$ /* action goes here */
```
A similar trick will work for matching a `foo` or a `bar`-at-the-beginning-of-a-line.
# 拓展阅读
这部分内容是与语法分析有关的拓展阅读,供学有余力的同学扩展视野,不作为实验或课程要求。
## 不同的生成器
Bison 并非唯一的解析器生成器,甚至不是最好用的。我们推荐同学们进一步了解其他生成器,以备不时之需。
可以从以下几个角度来研究:
1. 支持怎样的文法?
2. 目标语言是什么?
3. 是如何实现的?
4. 支持怎样的 lexer?
5. 效率如何?
等等。其实 Wikipedia 上就有一个[对比页面](https://en.wikipedia.org/wiki/Comparison_of_parser_generators)
## 手写解析器
尽管解析器生成器非常好用:只要把文法倒进去,它就可以自动生成大量代码。但是有以下几个弊端:
1. 生成的是解析树而不是抽象语法树。这需要之后较多的人工工作来进行转换。
2. 报错和错误恢复可能比较复杂。
3. 如果生成器缺乏必需功能或者 bug,会造成很大的困扰。
在真实世界中,人们常常为了避免上述弊端而手写解析器。实践中,为了便于报错等,常常选择**自顶向下** (top-down) 解析器,或者是**递归下降** (recursive descent),或者是 LL。
过去人们常常认为 top-down 解析无法处理左递归。实际上,存在一种名为 Pratt parser 的技术可以解决这个问题。它是递归下降的一个简单变体,很容易理解,但又相当强大,非常适合处理表达式(递归、运算符有结合性)。这里给两个参考文章,供有兴趣的同学阅读。
1. [Simple Top-Down Parsing in Python](http://effbot.org/zone/simple-top-down-parsing.htm) (Python)
2. [Simple but Powerful Pratt Parsing](https://matklad.github.io/2020/04/13/simple-but-powerful-pratt-parsing.html) (Rust)
3. [Pratt Parsing Index](https://www.oilshell.org/blog/2017/03/31.html) (一篇调查文章)
总之,top-down 解析器是实践中最常用的,毕竟非常好写。为此,我们推荐同学们做以下练习:
1. 在自己喜欢的语言中,用递归下降的方法编写 JSON 解析器。JSON 是目前最常用的互联网数据交换格式,它的文法可在其官网 [json.org](http://json.org) 上查阅。
2. 在自己喜欢的语言中,用 Pratt 解析的方法编写一个四则运算计算器,尝试提供用户友好的错误报告。
## 解析器组合子
解析器组合子 (parser combinator) 是一种高阶函数,它可以把多个解析器组合成单个解析器。这是什么意思呢?又有什么应用价值呢?
首先需要定义这里所说的“解析器”是什么。在这里,解析器接受一段字符串,并返回解析的输出 **和** 剩下的字符串。所以,这里说的解析器实际上是一个函数。
举一个例子,假设存在词法分析器(它实际上也是一种解析器,但接受的文法是正则文法) `number``identifier`
```
number("123abc") ==> (Some(123), "abc") 注意这里返回的是整数 123 而不是字符串
number("abc123") ==> (None, "abc123") 识别失败,因此 number 对应的输出是 None
identifier("abc123") ==> (Some("abc123"), "") 这里返回的是字符串 "abc123"
```
`Some(x)` 表示解析成功,输出为 `x``None` 表示该解析器解析失败。)
假设这个语言是计算器的语言,支持用 `2x` 表示 `2*x`。所以 `factor` 可以是数字后接标识符。假如有一种方法,把 `number``identifier` 组合起来,岂不是很好?我们引入如下组合子:
1. `seq(p,q)`: 表示将输入按顺序经过 p 和 q,并输出两者的结果;如果其中某一步失败,则整个 `seq(p,q)` 也失败。
2. `or(p,q)`: 表示首先尝试 p,如果成功则返回结果,否则接着尝试 q,否则失败。
那么就可以定义
```
factor = or(
seq(number,identifier).map { Expr.Mul(Expr.Const(#1), Expr.Val(#2)) },
number.map(Expr.Const)
)
```
(上面的 `.map(...)` 用于将字符串或数字等数值转换成抽象语法树节点。可以与文法文件中的 action code 类比。)
根据上面说的,我们可以推测它的行为是:
```
factor("123") = (Some(Expr.Const(123)), "")
factor("2x") = (Some(Expr.Mul(Expr.Const(2), Expr.Val("x"))), "")
```
不难看出函数组合成大函数的过程,就是我们把小解析器组合成大解析器的过程,并且可以很自然地把自己想要的逻辑嵌入进去。更有趣的是,编译器是完全知道每个函数的类型的。
由此可见,解析器组合子是一种编程技巧而不是一种解析技术(解析技术是隐含在组合子的实现里的),使用这种技巧可以让代码模块化程度更高,并且在类型较强的语言中可以在编译时就捕获错误。此外,尽管代码是完全手写的,但代码却可以和使用解析器生成器一样干净整洁。感兴趣的同学请务必在自己喜欢的高级语言中尝试一番,或者亲自动手写一套组合子。
## 解析器表达式文法
[Parser Expression Grammar](https://zh.wikipedia.org/wiki/解析表达文法) 总结了一大类递归下降分析器可以解析的语言文法,它的核心就是回溯,特点是不能有二义性。PEG 可以比较直观地转换成相应的分析器代码,因此常常用于各种各样的 Parser Generator、Parser Combinator(其实上一节中的组合子组合下来就可以实现 PEG)。PEG 是目前实践中最常用的一类文法,可能没有之一。而且 PEG 是相当容易理解的。缺陷是编写者需要注意各构造的顺序,同时和 LL 文法一样无法支持左递归。
PEG 最近在工业界的一个新闻是 Python 将自己的解析器改成 PEG 的了。然后基于这个新的解析器,支持了一个模式匹配的构造。
- [PEP 617 -- New PEG parser for CPython](https://www.python.org/dev/peps/pep-0617/#background-on-peg-parsers)
- [PEP 622 -- Structural Pattern Matching](https://www.python.org/dev/peps/pep-0622/)
这里给出一个例子:
```python
match something:
case 0 | 1 | 2:
print("Small number")
case [] | [_]:
print("A short sequence")
case str() | bytes():
print("Something string-like")
case _:
print("Something else")
```
为了提供向前兼容性,Python 将 `match``case` 设为了“软关键字”(soft keyword)。这个设计最早是 Java 10 引入的 `var` 关键字,用以支持自动类型推断。下面以 Java 为例介绍一下软关键字。
- [JEP 286: Local-Variable Type Inference](https://openjdk.java.net/jeps/286)
所谓的软关键字,就是与硬关键字相对(废话),其含义与上下文有关(这并不意味着上下文相关文法)。引入软关键字的目的主要是避免原先合法的代码在新版中出错。
一个硬关键字在词法分析阶段会被直接分析成关键字。例如, `if` 被分析成一个叫做 `IF` 的 token,这和 `[` 被分析成 `LBRACKET` 没有什么区别。而一个像 `var` 这样的软关键字,则会首先分析成某种 `IDENT(var)``VAR` 的复合状态,这里不妨就叫做 `VAR`,然后在语法分析阶段再进行分析。大致思想如下:
```
IDENT ::= ... | VAR // 变量名仍然可以叫 var
var-declaration ::= ... | VAR IDENT EQ initializer SEMICOLON // var 可以开启一个变量定义
```
为什么可以这样做?可以尝试分析一下下面的例子:
```java
var(); // 旧版可以编译,新版语义不变
var = 1; // 旧版可以编译,新版语义不变
var msg = "hello"; // 旧版报错
var var = 1; // 旧版报错
```
这样的语法在带回溯的 PEG 中是很容易写出来的。
## 更多的解析技术
课本上介绍的解析技术非常实用,但并不是解析的全部。例如:
1. 可以处理二义文法和左递归的 [Earley parser](https://en.wikipedia.org/wiki/Earley_parser)
2. 线性时间的 [Packrat parser](https://en.wikipedia.org/wiki/Parsing_expression_grammar)
3. 使用动态规划思想设计的 O(n³|G|) 时间的 [CYK 算法](https://en.wikipedia.org/wiki/CYK_algorithm)
4. 哪怕是在解析已经被视为 solved problem 的 2020 年,还有诸如 [Pika parser](https://arxiv.org/abs/2005.06444) 之类的算法在不断被提出。
当然,这些算法知道名字就行了,实践中大概率是用不到的。
## 有没有一劳永逸的办法?
聪明的同学可能会提出这样的问题:我们随便写文法,然后让机器自动检查这个文法是否是二义的,并转换成一种非常高效的文法表示,最后自动生成代码,这是可以办到的吗?
很遗憾,答案是否定的。要理解背后的原理,需要进一步学习相关理论才可以(而且证明也有点繁杂)。在这里,我们(用非常不严谨的语言)列出与上下文无关文法相关的一些结论。注:“不可判定” 的意思是 “不可能写出来这样一个程序”,是不是听起来非常中二 :-p
1. 上下文无关文法的二义性是不可判定的。
2. 检查文法是否接受任何字符串是不可判定的。
3. 检查两个文法是否接受相同的语言是不可判定的。
4. 无法判定两个 CFG 接受的语言交集是否是空的。
另外,尽管有上面 2 这样的结论,但是 “检查文法是否什么字符串都不接受” 却是可判定的,将 CFG 转换成 Chomsky normal form 就可以轻松办到。
(聪明的同学可能会开始思考对正则语言来说上面这些问题的结论是怎样的……)
下面介绍一个著名的问题 [Post correspondence problem](https://en.wikipedia.org/wiki/Post_correspondence_problem),来说明有时候人类的直觉是很不靠谱的。
给定相同长度的两个字符串列表 a[1], a[2], a[3], ..., a[n] 和 b[1], b[2], b[3], ..., b[n],回答:是否存在一列下标 i[1], i[2], ..., i[k],使得 a[i[1]] a[i[2]] ... a[i[k]] = b[i[1]] b[i[2]] ... b[i[k]]?
帮助大家有一个感性认识,下面复读一下 Wikipedia 上的例子:
| a₁ | a₂ | a₃ |
| ----- | ----- | ----- |
| a | ab | bba |
| b₁ | b₂ | b₃ |
| ----- | ----- | ----- |
| baa | aa | bb |
对这组输入来说,这个问题是有解的,因为 a₃a₂a₃a₁ = b₃b₂b₃b₁。
尽管一时半会可能想不到高效的做法,但是直觉告诉我们,似乎可以去暴力枚举,然后一一比较……
**然而**,这个问题是不可能机械求解的!不可能写出一个程序来判定这个问题。PCP不可判定是怎么回事呢?PCP相信大家都很熟悉,但是PCP不可判定是怎么回事呢,下面就让小编带大家一起了解吧。PCP不可判定,其实就是停机问题不可判定,大家可能会很惊讶PCP怎么会不可判定呢?但事实就是这样,小编也感到非常惊讶。
## 在线解析
学到这里,虽说大家已经可以写 parser 了,但是这在工程实践上却还不够。比如说,IDE 为了提供准确的实时报错、自动补全、代码缩进,都需要在用户编辑代码时立即提供语法树。仅仅利用 lab2 这种简单的离线解析器是完全不能满足使用的。在编辑代码时,大部分时间代码都是语法甚至词法不正确的,必须考虑到各种错误情形,并保证不会搞乱代码。此外,在提供自动缩进时,后方的错误不应该影响到前方代码的缩进。还有一个问题是,离线解析需要从头构建语法树,代价较高。受到这种“在线解析”需求的启发,涌现了不少很有实用价值的工作,比如:
1. [tree-sitter](https://github.com/tree-sitter/tree-sitter): incremental parser 框架,总是在内存中维护完整的语法树。
2. [Auto-indentation with incomplete information](https://arxiv.org/ftp/arxiv/papers/2006/2006.03103.pdf): 基于 Operator precedence parser 的用于代码缩进的框架,支持局部前向解析。尽管并不维护完整的语法树,但由于每次解析量很少,所以速度足够快。
# Lab1 实验文档
## 0. 实验目标
本次实验需要同学们从无到有完成一个完整的 Cminus-f 解析器,包括基于 `flex` 的词法分析器和基于 `bison` 的语法分析器。
本次实验提供了若干文档,请根据实验进度和个人需要认真阅读。
- [实验要求](./README.md)(本文档)
- [实验基础知识](./Basics.md)(进行试验前请首先仔细阅读)
- [Flex matching](./Flex-matching.md)
- [Flex regular expressions](./Flex-regular-expressions.md)
- [拓展阅读](./Parser-FurtherReadings.md)(选读)
在提交实验前,请务必仔细阅读本文档,确保已经完成了所有实验要求、自己的代码可以通过所有测试。
## 1. 词法分析器
本部分需要各位同学根据`Cminus-f`的词法补全`src/parser/lexical_analyzer.l`文件,完成词法分析器。在`lexical_analyzer.l`文件中,你只需补全模式和动作即可,能够输出识别出的`token``text` ,`line(刚出现的行数)``pos_start(该行开始位置)``pos_end(结束的位置,不包含)`。比如:
文本输入:
```c
int a;
```
则识别结果应为:
```shell
Token Text Line Column (Start,End)
280 int 0 (1,4)
284 a 0 (5,6)
270 ; 0 (6,7)
```
必须维护正确的:
* `token`
* `text`
选择维护的(方便你debug,测试):
* `line`
* `pos_start`
* `pos_end`
具体的需识别token请参考[基础知识](./Basics.md)
提示:
1. 在编写本部分前,需要首先修改 `.y` 文件。具体怎么做请参见[基础知识](./Basics.md)
2. 在进入实验下一部分前,你可以使用我们提供的 `lexer` 程序进行调试。参见本文档 3.2 节。
3. token编号是自动生成的,`make` 后,可在 `build/syntax_analyzer.h` 中找到。每次修改token后,都应该重新 `make` 后再进行对照。
**特别说明对于部分token,我们只需要进行过滤,即只需被识别,但是不应该被输出到分析结果中。因为这些token对程序运行不起到任何作用。根据 token 定义顺序不同,输出的 token 编号也可能不同,是正常现象。**
## 2. 语法分析器
本部分需要同学们完成 `src/parser/syntax_analyzer.y`。与词法分析器相同,你只需要根据代码中的提示和[基础知识](./Basics.md)中给出的文法填写相应的规则即可。
如果实现正确,该语法分析器可以从 Cminus-f 代码分析得到一颗语法树。例如输入
```c
int main(void) {
return 0;
}
```
可以得到如下语法树
```
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
```
**这一部分必须严格遵守我们给出的语法,输出必须与标准程序输出完全一致。**
## 2.1 思考题
本部分不计入评分,出题的本意在于想要帮助同学们加深对实验细节的理解,欢迎有兴趣和余力的同学在报告中写下你的思考答案,或者在issue中分享出你的看法。
1. [基础知识](./Basics.md)中的计算器例子的文法中存在左递归,为什么 `bison` 可以处理?(提示:不用研究 `bison` 内部运作机制,在下面知识介绍中有提到 `bison` 的一种属性,请结合课内知识思考)
2. 请在代码层面上简述下 `yylval` 是怎么完成协同工作的。(提示:无需研究原理,只分析维护了什么数据结构,该数据结构是怎么和`$1``$2`等联系起来?)
3. 在计算器例子中,除 0 时会发生什么?如果把 `yylval` 修改为整形(`int`, `long` 等),这时候又会发生什么?
4. 能否修改计算器例子的文法,使得它支持除数0规避功能?(提示:这道题很难!尚未有同学给出正确答案。)
## 3. 实验要求
### 3.1 目录结构
与本次实验有关的文件如下。
```
.
├── CMakeLists.txt
├── Documentations
│   └── 1-parser 本次实验的所有文档
├── Reports
│   └── 1-parser
│   └── README.md 在这里写实验报告 <-- 修改
├── include
│   └── syntax_tree.h
├── shell.nix
├── src
│   ├── CMakeLists.txt
│   ├── common
│   │   ├── CMakeLists.txt
│   │   └── syntax_tree.c 语法树的构造
│   └── parser
│   ├── CMakeLists.txt
│   ├── lexical_analyzer.l 词法分析器 <-- 修改
│   └── syntax_analyzer.y 语法分析器 <-- 修改
└── tests
├── CMakeLists.txt
└── parser
│   ├── CMakeLists.txt
│   ├── easy 简单的测试
│   ├── normal 中等复杂度的测试
│   ├── hard 复杂的测试
│   ├── lexer.c 用于词法分析的调试程序
│   ├── parser.c 语法分析
│   ├── syntree_*_std 标准程序输出结果
│   └── test_syntax.sh 用于进行批量测试的脚本
```
### 3.2 编译、运行和验证
项目构建使用 `cmake` 进行。
* 编译
```sh
$ cd 2021fall-Compiler_CMinus
$ mkdir build
$ cd build
$ cmake ..
$ make
```
如果构建成功,会在该目录下看到 `lexer``parser` 两个可执行文件。
* `lexer`用于词法分析,产生token stream;对于词法分析结果,我们不做考察
* `parser`用于语法分析,产生语法树。
* 运行
```sh
$ cd 2020fall-Compiler_CMinus
# 词法测试
$ ./build/lexer ./tests/parser/easy/local-decl.cminus
Token Text Line Column (Start,End)
280 int 0 (0,3)
284 main 0 (4,8)
272 ( 0 (8,9)
282 void 0 (9,13)
273 ) 0 (13,14)
...
# 语法测试
$ ./build/parser ./tests/parser/easy/local-decl.cminus
>--+ program
| >--+ declaration-list
| | >--+ declaration
...
```
* 验证
可以使用 `diff` 与标准输出进行比较。
```sh
$ cd 2020fall-Compiler_CMinus
$ export PATH=$(realpath ./build)
$ cd tests/parser
$ mkdir output.easy
$ parser easy/array.cminus > output.easy/array.cminus
$ diff output.easy/array.cminus syntree_easy_std/array.syntax_tree
[输出为空,代表没有区别,该测试通过]
```
我们提供了 `test_syntax.sh` 脚本进行快速批量测试。该脚本的第一个参数是 `easy` `normal` `hard` 等难度,并且有第二个可选参数,用于进行批量 `diff` 比较。脚本运行后会产生名如 `syntree_easy` 的文件夹。
```sh
$ ./test_syntax.sh easy
[info] Analyzing FAIL_id.cminus
error at line 1 column 6: syntax error
...
[info] Analyzing local-decl.cminus
$ ./test_syntax.sh easy yes
...
[info] Comparing...
[info] No difference! Congratulations!
```
### 3.3 提交要求和评分标准
* 提交要求
本实验的提交要求分为两部分:实验部分的文件和报告,git提交的规范性。
* 实验部分
* 需要完善 `src/parser/lexical_analyzer.l``src/parser/syntax_analyzer.y`
* 需要在 `Reports/1-parser/README.md` 中撰写实验报告。
* 实验报告内容包括
* 实验要求、实验难点、实验设计、实验结果验证、实验反馈
* 实验评估
* 除已提供的 easy, normal, hard 数据集之外,助教会使用额外的测试数据。
* git 提交规范
* 不破坏目录结构(实验报告所需图片放在目录中)
* 不上传临时文件(凡是可以自动生成的都不要上传,如 `build` 目录、测试时自动生成的输出、`.DS_Store` 等)
* git log 言之有物
* 迟交规定
* Soft Deadline:2021-10-03 23:59:59 (UTC+8)
* Hard Deadline:2021-10-10 23:59:59 (UTC+8)
* 补交请邮件提醒 TA:
* 邮箱:`ksqsf@mail.ustc.edu.cn` 抄送 `gpzlx1@mail.ustc.edu.cn` 抄送 `xzwj@mail.ustc.edu.cn`
* 邮件主题:lab1迟交-学号
* 内容:迟交原因、最后版本commitID、迟交时间
* 迟交分数
* x 为相对 Soft Deadline 迟交天数,grade 满分 10
```
final_grade = grade, x = 0
final_grade = grade * (0.9)^x, 0 < x <= 7
final_grade = 0, x > 7
```
* 关于抄袭和雷同
经过助教和老师判定属于作业抄袭或雷同情况,所有参与方一律零分,不接受任何解释和反驳。
如有任何问题,欢迎提issue进行批判指正。
# 实验说明
请 fork 此 repo 到自己的仓库下,随后在自己的仓库中完成实验,请确保自己的 repo 为 Private。
## 目前已布置的实验
* [lab1](./Documentations/1-parser/)
+ DDL:2021-10-03 23:59:59 (UTC+8)
## FAQ: How to merge upstream remote branches
In brief, you need another alias for upstream repository (we assume you are now in your local copy of forked repository on Gitlab):
```shell
$ git remote add upstream http://222.195.68.197/staff/2021fall-compiler_cminus.git
```
Then try to merge remote commits to your local repository:
```shell
$ git pull upstream master
```
Then synchronize changes to your forked remote repository:
```shell
$ git push origin master
```
# lab1 实验报告
学号 姓名
## 实验要求
## 实验难点
## 实验设计
## 实验结果验证
请提供部分自行设计的测试
## 实验反馈
#ifndef _SYNTAX_TREE_HPP_
#define _SYNTAX_TREE_HPP_
extern "C" {
#include "syntax_tree.h"
extern syntax_tree *parse(const char *input);
}
#include <vector>
#include <memory>
#include <string>
enum CminusType {
TYPE_INT,
TYPE_FLOAT,
TYPE_VOID
};
enum RelOp {
// <=
OP_LE,
// <
OP_LT,
// >
OP_GT,
// >=
OP_GE,
// ==
OP_EQ,
// !=
OP_NEQ
};
enum AddOp {
// +
OP_PLUS,
// -
OP_MINUS
};
enum MulOp {
// *
OP_MUL,
// /
OP_DIV
};
class AST;
struct ASTNode;
struct ASTProgram;
struct ASTDeclaration;
struct ASTNum;
struct ASTVarDeclaration;
struct ASTFunDeclaration;
struct ASTParam;
struct ASTCompoundStmt;
struct ASTStatement;
struct ASTExpressionStmt;
struct ASTSelectionStmt;
struct ASTIterationStmt;
struct ASTReturnStmt;
struct ASTFactor;
struct ASTExpression;
struct ASTVar;
struct ASTAssignExpression;
struct ASTSimpleExpression;
struct ASTAdditiveExpression;
struct ASTTerm ;
struct ASTCall;
class ASTVisitor;
class AST {
public:
AST() = delete;
AST(syntax_tree *);
AST(AST &&tree) {
root = tree.root;
tree.root = nullptr;
};
ASTProgram* get_root() { return root.get(); }
void run_visitor(ASTVisitor& visitor);
private:
ASTNode* transform_node_iter(syntax_tree_node *);
std::shared_ptr<ASTProgram> root = nullptr;
};
struct ASTNode {
virtual void accept(ASTVisitor &) = 0;
};
struct ASTProgram : ASTNode {
virtual void accept(ASTVisitor &) override final;
std::vector<std::shared_ptr<ASTDeclaration>>
declarations;
};
struct ASTDeclaration: ASTNode {
virtual void accept(ASTVisitor &) override;
CminusType type;
std::string id;
};
struct ASTFactor: ASTNode {
virtual void accept(ASTVisitor &) override;
};
struct ASTNum: ASTFactor {
virtual void accept(ASTVisitor &) override final;
CminusType type;
union {
int i_val;
float f_val;
};
};
struct ASTVarDeclaration: ASTDeclaration {
virtual void accept(ASTVisitor &) override final;
CminusType type;
std::shared_ptr<ASTNum> num;
};
struct ASTFunDeclaration: ASTDeclaration {
virtual void accept(ASTVisitor &) override final;
std::vector<std::shared_ptr<ASTParam>> params;
std::shared_ptr<ASTCompoundStmt> compound_stmt;
};
struct ASTParam: ASTNode {
virtual void accept(ASTVisitor &) override final;
CminusType type;
std::string id;
// true if it is array param
bool isarray;
};
struct ASTStatement : ASTNode {
virtual void accept(ASTVisitor &) override;
};
struct ASTCompoundStmt: ASTStatement {
virtual void accept(ASTVisitor&) override final;
std::vector<std::shared_ptr<ASTVarDeclaration>> local_declarations;
std::vector<std::shared_ptr<ASTStatement>> statement_list;
};
struct ASTExpressionStmt: ASTStatement {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTExpression> expression;
};
struct ASTSelectionStmt: ASTStatement {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTExpression> expression;
std::shared_ptr<ASTStatement> if_statement;
// should be nullptr if no else structure exists
std::shared_ptr<ASTStatement> else_statement;
};
struct ASTIterationStmt: ASTStatement {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTExpression> expression;
std::shared_ptr<ASTStatement> statement;
};
struct ASTReturnStmt: ASTStatement {
virtual void accept(ASTVisitor &) override final;
// should be nullptr if return void
std::shared_ptr<ASTExpression> expression;
};
struct ASTExpression: ASTFactor {
virtual void accept(ASTVisitor &) override;
};
struct ASTAssignExpression: ASTExpression {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTVar> var;
std::shared_ptr<ASTExpression> expression;
};
struct ASTSimpleExpression: ASTExpression {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTAdditiveExpression> additive_expression_l;
std::shared_ptr<ASTAdditiveExpression> additive_expression_r;
RelOp op;
};
struct ASTVar: ASTFactor {
virtual void accept(ASTVisitor &) override final;
std::string id;
// nullptr if var is of int type
std::shared_ptr<ASTExpression> expression;
};
struct ASTAdditiveExpression: ASTNode {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTAdditiveExpression> additive_expression;
AddOp op;
std::shared_ptr<ASTTerm> term;
};
struct ASTTerm : ASTNode {
virtual void accept(ASTVisitor &) override final;
std::shared_ptr<ASTTerm> term;
MulOp op;
std::shared_ptr<ASTFactor> factor;
};
struct ASTCall: ASTFactor {
virtual void accept(ASTVisitor &) override final;
std::string id;
std::vector<std::shared_ptr<ASTExpression>> args;
};
class ASTVisitor {
public:
virtual void visit(ASTProgram &) = 0;
virtual void visit(ASTNum &) = 0;
virtual void visit(ASTVarDeclaration &) = 0;
virtual void visit(ASTFunDeclaration &) = 0;
virtual void visit(ASTParam &) = 0;
virtual void visit(ASTCompoundStmt &) = 0;
virtual void visit(ASTExpressionStmt &) = 0;
virtual void visit(ASTSelectionStmt &) = 0;
virtual void visit(ASTIterationStmt &) = 0;
virtual void visit(ASTReturnStmt &) = 0;
virtual void visit(ASTAssignExpression &) = 0;
virtual void visit(ASTSimpleExpression &) = 0;
virtual void visit(ASTAdditiveExpression &) = 0;
virtual void visit(ASTVar &) = 0;
virtual void visit(ASTTerm &) = 0;
virtual void visit(ASTCall &) = 0;
};
class ASTPrinter : public ASTVisitor {
public:
virtual void visit(ASTProgram &) override final;
virtual void visit(ASTNum &) override final;
virtual void visit(ASTVarDeclaration &) override final;
virtual void visit(ASTFunDeclaration &) override final;
virtual void visit(ASTParam &) override final;
virtual void visit(ASTCompoundStmt &) override final;
virtual void visit(ASTExpressionStmt &) override final;
virtual void visit(ASTSelectionStmt &) override final;
virtual void visit(ASTIterationStmt &) override final;
virtual void visit(ASTReturnStmt &) override final;
virtual void visit(ASTAssignExpression &) override final;
virtual void visit(ASTSimpleExpression &) override final;
virtual void visit(ASTAdditiveExpression &) override final;
virtual void visit(ASTVar &) override final;
virtual void visit(ASTTerm &) override final;
virtual void visit(ASTCall &) override final;
void add_depth() { depth += 2; }
void remove_depth() { depth -= 2; }
private:
int depth = 0;
};
#endif
#ifndef LOGGING_HPP
#define LOGGING_HPP
#include <iostream>
#include <sstream>
#include <cstdlib>
enum LogLevel
{
DEBUG = 0,
INFO,
WARNING,
ERROR
};
struct LocationInfo
{
LocationInfo(std::string file, int line, const char *func) : file_(file), line_(line), func_(func) {}
~LocationInfo() = default;
std::string file_;
int line_;
const char *func_;
};
class LogStream;
class LogWriter;
class LogWriter
{
public:
LogWriter(LocationInfo location, LogLevel loglevel)
: location_(location), log_level_(loglevel)
{
char *logv = std::getenv("LOGV");
if (logv)
{
std::string string_logv = logv;
env_log_level = std::stoi(logv);
}
else
{
env_log_level = 4;
}
};
void operator<(const LogStream &stream);
private:
void output_log(const std::ostringstream &g);
LocationInfo location_;
LogLevel log_level_;
int env_log_level;
};
class LogStream
{
public:
LogStream() { sstream_ = new std::stringstream(); }
~LogStream() = default;
template <typename T>
LogStream &operator<<(const T &val) noexcept
{
(*sstream_) << val;
return *this;
}
friend class LogWriter;
private:
std::stringstream *sstream_;
};
std::string level2string(LogLevel level);
std::string get_short_name(const char *file_path);
#define __FILESHORTNAME__ get_short_name(__FILE__)
#define LOG_IF(level) \
LogWriter(LocationInfo(__FILESHORTNAME__, __LINE__, __FUNCTION__), level) < LogStream()
#define LOG(level) LOG_##level
#define LOG_DEBUG LOG_IF(DEBUG)
#define LOG_INFO LOG_IF(INFO)
#define LOG_WARNING LOG_IF(WARNING)
#define LOG_ERROR LOG_IF(ERROR)
#endif
#ifndef __SYNTAXTREE_H__
#define __SYNTAXTREE_H__
#include <stdio.h>
#define SYNTAX_TREE_NODE_NAME_MAX 30
struct _syntax_tree_node {
struct _syntax_tree_node * parent;
struct _syntax_tree_node * children[10];
int children_num;
char name[SYNTAX_TREE_NODE_NAME_MAX];
};
typedef struct _syntax_tree_node syntax_tree_node;
syntax_tree_node * new_anon_syntax_tree_node();
syntax_tree_node * new_syntax_tree_node(const char * name);
int syntax_tree_add_child(syntax_tree_node * parent, syntax_tree_node * child);
void del_syntax_tree_node(syntax_tree_node * node, int recursive);
struct _syntax_tree {
syntax_tree_node * root;
};
typedef struct _syntax_tree syntax_tree;
syntax_tree* new_syntax_tree();
void del_syntax_tree(syntax_tree * tree);
void print_syntax_tree(FILE * fout, syntax_tree * tree);
#endif /* SyntaxTree.h */
# Use `nix-shell` to quickly create a dev shell.
{ pkgs ? import <nixpkgs> {} }:
with pkgs; mkShell {
buildInputs = [ flex bison llvmPackages_10.llvm llvmPackages_10.clang ];
shellHook = ''
_rootdir="$(realpath .)"
_builddir="$_rootdir/build"
export PATH="$_builddir:$PATH"
rebuild(){
(cd $_builddir; make -j)
}
'';
}
add_subdirectory(parser)
add_subdirectory(common)
\ No newline at end of file
add_library(common STATIC
syntax_tree.c
ast.cpp
logging.cpp
)
target_link_libraries(common)
#include "ast.hpp"
#include <cstring>
#include <stack>
#include <iostream>
#define _AST_NODE_ERROR_ \
std::cerr << "Abort due to node cast error."\
"Contact with TAs to solve your problem."\
<< std::endl;\
std::abort();
#define _STR_EQ(a, b) (strcmp((a), (b)) == 0)
void AST::run_visitor(ASTVisitor &visitor) {
root->accept(visitor);
}
AST::AST(syntax_tree* s) {
if (s == nullptr) {
std::cerr << "empty input tree!" << std::endl;
std::abort();
}
auto node = transform_node_iter(s->root);
del_syntax_tree(s);
root = std::shared_ptr<ASTProgram>(
static_cast<ASTProgram *>(node));
}
ASTNode *
AST::transform_node_iter(syntax_tree_node *n) {
if (_STR_EQ(n->name, "program")) {
auto node = new ASTProgram();
// flatten declaration list
std::stack<syntax_tree_node *> s;
auto list_ptr = n->children[0];
while (list_ptr->children_num == 2) {
s.push(list_ptr->children[1]);
list_ptr = list_ptr->children[0];
}
s.push(list_ptr->children[0]);
while (!s.empty()) {
auto child_node = static_cast<ASTDeclaration*>(
transform_node_iter(s.top()));
auto child_node_shared =
std::shared_ptr<ASTDeclaration>(child_node);
node->declarations.push_back(child_node_shared);
s.pop();
}
return node;
} else if (_STR_EQ(n->name, "declaration")) {
return transform_node_iter(n->children[0]);
} else if (_STR_EQ(n->name, "var-declaration")) {
auto node = new ASTVarDeclaration();
if (_STR_EQ(n->children[0]->children[0]->name, "int"))
node->type = TYPE_INT;
else
node->type = TYPE_FLOAT;
if (n->children_num == 3) {
node->id = n->children[1]->name;
} else if (n->children_num == 6) {
node->id = n->children[1]->name;
int num = std::stoi(n->children[3]->name);
auto num_node = std::make_shared<ASTNum>();
num_node->i_val = num;
num_node->type = TYPE_INT;
node->num = num_node;
} else {
std::cerr << "[ast]: var-declaration transform failure!" << std::endl;
std::abort();
}
return node;
} else if (_STR_EQ(n->name, "fun-declaration")) {
auto node = new ASTFunDeclaration();
if (_STR_EQ(n->children[0]->children[0]->name, "int")) {
node->type = TYPE_INT;
} else if (_STR_EQ(n->children[0]->children[0]->name, "float")) {
node->type = TYPE_FLOAT;
} else {
node->type = TYPE_VOID;
}
node->id = n->children[1]->name;
// flatten params
std::stack<syntax_tree_node *> s;
auto list_ptr = n->children[3]->children[0];
if (list_ptr->children_num != 0) {
if (list_ptr->children_num == 3) {
while (list_ptr->children_num == 3) {
s.push(list_ptr->children[2]);
list_ptr = list_ptr->children[0];
}
}
s.push(list_ptr->children[0]);
while (!s.empty()) {
auto child_node = static_cast<ASTParam*>(
transform_node_iter(s.top()));
auto child_node_shared =
std::shared_ptr<ASTParam>(child_node);
node->params.push_back(child_node_shared);
s.pop();
}
}
auto stmt_node =
static_cast<ASTCompoundStmt *>(
transform_node_iter(n->children[5]));
node->compound_stmt = std::shared_ptr<ASTCompoundStmt>(stmt_node);
return node;
} else if (_STR_EQ(n->name, "param")) {
auto node = new ASTParam();
if (_STR_EQ(n->children[0]->children[0]->name, "int"))
node->type = TYPE_INT;
else
node->type = TYPE_FLOAT;
node->id = n->children[1]->name;
if (n->children_num == 3)
node->isarray = true;
return node;
} else if (_STR_EQ(n->name, "compound-stmt")) {
auto node = new ASTCompoundStmt();
if (n->children[1]->children_num == 2) {
// flatten local declarations
auto list_ptr = n->children[1];
std::stack<syntax_tree_node *> s;
while (list_ptr->children_num == 2) {
s.push(list_ptr->children[1]);
list_ptr = list_ptr->children[0];
}
while (!s.empty()) {
auto decl_node =
static_cast<ASTVarDeclaration*>(
transform_node_iter(s.top()));
auto decl_node_ptr = std::shared_ptr<ASTVarDeclaration>(decl_node);
node->local_declarations.push_back(decl_node_ptr);
s.pop();
}
}
if (n->children[2]->children_num == 2) {
// flatten statement-list
auto list_ptr = n->children[2];
std::stack<syntax_tree_node *> s;
while (list_ptr->children_num == 2) {
s.push(list_ptr->children[1]);
list_ptr = list_ptr->children[0];
}
while (!s.empty()) {
auto stmt_node =
static_cast<ASTStatement *>(
transform_node_iter(s.top()));
auto stmt_node_ptr = std::shared_ptr<ASTStatement>(stmt_node);
node->statement_list.push_back(stmt_node_ptr);
s.pop();
}
}
return node;
} else if (_STR_EQ(n->name, "statement")) {
return transform_node_iter(n->children[0]);
} else if (_STR_EQ(n->name, "expression-stmt")) {
auto node = new ASTExpressionStmt();
if (n->children_num == 2) {
auto expr_node =
static_cast<ASTExpression *>(
transform_node_iter(n->children[0]));
auto expr_node_ptr = std::shared_ptr<ASTExpression>(expr_node);
node->expression = expr_node_ptr;
}
return node;
} else if (_STR_EQ(n->name, "selection-stmt")) {
auto node = new ASTSelectionStmt();
auto expr_node =
static_cast<ASTExpression *>(
transform_node_iter(n->children[2]));
auto expr_node_ptr = std::shared_ptr<ASTExpression>(expr_node);
node->expression = expr_node_ptr;
auto if_stmt_node =
static_cast<ASTStatement *>(
transform_node_iter(n->children[4]));
auto if_stmt_node_ptr = std::shared_ptr<ASTStatement>(if_stmt_node);
node->if_statement = if_stmt_node_ptr;
// check whether this selection statement contains
// else structure
if (n->children_num == 7) {
auto else_stmt_node =
static_cast<ASTStatement *>(
transform_node_iter(n->children[6]));
auto else_stmt_node_ptr = std::shared_ptr<ASTStatement>(else_stmt_node);
node->else_statement = else_stmt_node_ptr;
}
return node;
} else if (_STR_EQ(n->name, "iteration-stmt")) {
auto node = new ASTIterationStmt();
auto expr_node =
static_cast<ASTExpression *>(
transform_node_iter(n->children[2]));
auto expr_node_ptr = std::shared_ptr<ASTExpression>(expr_node);
node->expression = expr_node_ptr;
auto stmt_node =
static_cast<ASTStatement *>(
transform_node_iter(n->children[4]));
auto stmt_node_ptr = std::shared_ptr<ASTStatement>(stmt_node);
node->statement = stmt_node_ptr;
return node;
} else if (_STR_EQ(n->name, "return-stmt")) {
auto node = new ASTReturnStmt();
if (n->children_num == 3) {
auto expr_node =
static_cast<ASTExpression *>(
transform_node_iter(n->children[1]));
node->expression =
std::shared_ptr<ASTExpression>(expr_node);
}
return node;
} else if (_STR_EQ(n->name, "expression")) {
// simple-expression
if (n->children_num == 1) {
return transform_node_iter(n->children[0]);
}
auto node = new ASTAssignExpression();
auto var_node =
static_cast<ASTVar *>(
transform_node_iter(n->children[0]));
node->var = std::shared_ptr<ASTVar>(var_node);
auto expr_node =
static_cast<ASTExpression *>(
transform_node_iter(n->children[2]));
node->expression =
std::shared_ptr<ASTExpression>(expr_node);
return node;
} else if (_STR_EQ(n->name, "var")) {
auto node = new ASTVar();
node->id = n->children[0]->name;
if (n->children_num == 4) {
auto expr_node =
static_cast<ASTExpression *>(
transform_node_iter(n->children[2]));
node->expression =
std::shared_ptr<ASTExpression>(expr_node);
}
return node;
} else if (_STR_EQ(n->name, "simple-expression")) {
auto node = new ASTSimpleExpression();
auto expr_node_1 =
static_cast<ASTAdditiveExpression *>(
transform_node_iter(n->children[0]));
node->additive_expression_l =
std::shared_ptr<ASTAdditiveExpression>(expr_node_1);
if (n->children_num == 3) {
auto op_name = n->children[1]->children[0]->name;
if (_STR_EQ(op_name, "<="))
node->op = OP_LE;
else if (_STR_EQ(op_name, "<"))
node->op = OP_LT;
else if (_STR_EQ(op_name, ">"))
node->op = OP_GT;
else if (_STR_EQ(op_name, ">="))
node->op = OP_GE;
else if (_STR_EQ(op_name, "=="))
node->op = OP_EQ;
else if (_STR_EQ(op_name, "!="))
node->op = OP_NEQ;
auto expr_node_2 =
static_cast<ASTAdditiveExpression *>(
transform_node_iter(n->children[2]));
node->additive_expression_r =
std::shared_ptr<ASTAdditiveExpression>(expr_node_2);
}
return node;
} else if (_STR_EQ(n->name, "additive-expression")) {
auto node = new ASTAdditiveExpression();
if (n->children_num == 3) {
auto add_expr_node =
static_cast<ASTAdditiveExpression *>(
transform_node_iter(n->children[0]));
node->additive_expression =
std::shared_ptr<ASTAdditiveExpression>(add_expr_node);
auto op_name = n->children[1]->children[0]->name;
if (_STR_EQ(op_name, "+"))
node->op = OP_PLUS;
else if (_STR_EQ(op_name, "-"))
node->op = OP_MINUS;
auto term_node =
static_cast<ASTTerm *>(
transform_node_iter(n->children[2]));
node->term = std::shared_ptr<ASTTerm>(term_node);
} else {
auto term_node =
static_cast<ASTTerm *>(
transform_node_iter(n->children[0]));
node->term = std::shared_ptr<ASTTerm>(term_node);
}
return node;
} else if (_STR_EQ(n->name, "term")) {
auto node = new ASTTerm();
if (n->children_num == 3) {
auto term_node =
static_cast<ASTTerm *>(
transform_node_iter(n->children[0]));
node->term =
std::shared_ptr<ASTTerm>(term_node);
auto op_name = n->children[1]->children[0]->name;
if (_STR_EQ(op_name, "*"))
node->op = OP_MUL;
else if (_STR_EQ(op_name, "/"))
node->op = OP_DIV;
auto factor_node =
static_cast<ASTFactor *>(
transform_node_iter(n->children[2]));
node->factor = std::shared_ptr<ASTFactor>(factor_node);
} else {
auto factor_node =
static_cast<ASTFactor *>(
transform_node_iter(n->children[0]));
node->factor = std::shared_ptr<ASTFactor>(factor_node);
}
return node;
} else if (_STR_EQ(n->name, "factor")) {
int i = 0;
if (n->children_num == 3)
i = 1;
auto name = n->children[i]->name;
if (_STR_EQ(name, "expression") ||
_STR_EQ(name, "var") ||
_STR_EQ(name, "call"))
return transform_node_iter(n->children[i]);
else {
auto num_node = new ASTNum();
if (_STR_EQ(name, "integer")) {
num_node->type = TYPE_INT;
num_node->i_val = std::stoi(n->children[i]->children[0]->name);
} else if (_STR_EQ(name, "float")) {
num_node->type = TYPE_FLOAT;
num_node->f_val = std::stof(n->children[i]->children[0]->name);
} else {
_AST_NODE_ERROR_
}
return num_node;
}
} else if (_STR_EQ(n->name, "call")) {
auto node = new ASTCall();
node->id = n->children[0]->name;
// flatten args
if (_STR_EQ(n->children[2]->children[0]->name, "arg-list")) {
auto list_ptr = n->children[2]->children[0];
auto s = std::stack<syntax_tree_node *>();
while (list_ptr->children_num == 3) {
s.push(list_ptr->children[2]);
list_ptr = list_ptr->children[0];
}
s.push(list_ptr->children[0]);
while (!s.empty()) {
auto expr_node =
static_cast<ASTExpression *>(
transform_node_iter(s.top()));
auto expr_node_ptr =
std::shared_ptr<ASTExpression>(expr_node);
node->args.push_back(expr_node_ptr);
s.pop();
}
}
return node;
} else {
std::cerr << "[ast]: transform failure!" << std::endl;
std::abort();
}
}
void ASTProgram::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTNum::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTVarDeclaration::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTFunDeclaration::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTParam::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTCompoundStmt::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTExpressionStmt::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTSelectionStmt::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTIterationStmt::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTReturnStmt::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTAssignExpression::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTSimpleExpression::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTAdditiveExpression::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTVar::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTTerm::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTCall::accept(ASTVisitor &visitor) { visitor.visit(*this); }
void ASTFactor::accept(ASTVisitor &visitor) {
auto expr =
dynamic_cast<ASTExpression *>(this);
if (expr) {
expr->accept(visitor);
return;
}
auto var =
dynamic_cast<ASTVar *>(this);
if (var) {
var->accept(visitor);
return;
}
auto call =
dynamic_cast<ASTCall *>(this);
if (call) {
call->accept(visitor);
return;
}
auto num =
dynamic_cast<ASTNum *>(this);
if (num) {
num->accept(visitor);
return;
}
_AST_NODE_ERROR_
}
void ASTDeclaration::accept(ASTVisitor &visitor) {
auto var_decl =
dynamic_cast<ASTVarDeclaration *>(this);
if (var_decl) {
var_decl->accept(visitor);
return;
}
auto fun_decl =
dynamic_cast<ASTFunDeclaration *>(this);
if (fun_decl) {
fun_decl->accept(visitor);
return;
}
_AST_NODE_ERROR_
}
void ASTStatement::accept(ASTVisitor &visitor) {
auto comp_stmt =
dynamic_cast<ASTCompoundStmt *>(this);
if (comp_stmt) {
comp_stmt->accept(visitor);
return;
}
auto expr_stmt =
dynamic_cast<ASTExpressionStmt *>(this);
if (expr_stmt) {
expr_stmt->accept(visitor);
return;
}
auto sele_stmt =
dynamic_cast<ASTSelectionStmt *>(this);
if (sele_stmt) {
sele_stmt->accept(visitor);
return;
}
auto iter_stmt =
dynamic_cast<ASTIterationStmt *>(this);
if (iter_stmt) {
iter_stmt->accept(visitor);
return;
}
auto ret_stmt =
dynamic_cast<ASTReturnStmt *>(this);
if (ret_stmt) {
ret_stmt->accept(visitor);
return;
}
_AST_NODE_ERROR_
}
void ASTExpression::accept(ASTVisitor &visitor) {
auto simple_expr =
dynamic_cast<ASTSimpleExpression *>(this);
if (simple_expr) {
simple_expr->accept(visitor);
return;
}
auto assign_expr =
dynamic_cast<ASTAssignExpression *>(this);
if (assign_expr) {
assign_expr->accept(visitor);
return;
}
_AST_NODE_ERROR_
}
#define _DEBUG_PRINT_N_(N) {\
std::cout << std::string(N, '-');\
}
void ASTPrinter::visit(ASTProgram &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "program" << std::endl;
add_depth();
for (auto decl: node.declarations) {
decl->accept(*this);
}
remove_depth();
}
void ASTPrinter::visit(ASTNum &node) {
_DEBUG_PRINT_N_(depth);
if (node.type == TYPE_INT) {
std::cout << "num (int): " << node.i_val << std::endl;
} else if (node.type == TYPE_FLOAT) {
std::cout << "num (float): " << node.f_val << std::endl;
} else {
_AST_NODE_ERROR_
}
}
void ASTPrinter::visit(ASTVarDeclaration &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "var-declaration: " << node.id;
if (node.num != nullptr) {
std::cout << "[]" << std::endl;
add_depth();
node.num->accept(*this);
remove_depth();
return;
}
std::cout << std::endl;
}
void ASTPrinter::visit(ASTFunDeclaration &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "fun-declaration: " << node.id << std::endl;
add_depth();
for (auto param: node.params) {
param->accept(*this);
}
node.compound_stmt->accept(*this);
remove_depth();
}
void ASTPrinter::visit(ASTParam &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "param: " << node.id;
if (node.isarray)
std::cout << "[]";
std::cout << std::endl;
}
void ASTPrinter::visit(ASTCompoundStmt &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "compound-stmt" << std::endl;
add_depth();
for (auto decl: node.local_declarations) {
decl->accept(*this);
}
for (auto stmt: node.statement_list) {
stmt->accept(*this);
}
remove_depth();
}
void ASTPrinter::visit(ASTExpressionStmt &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "expression-stmt" << std::endl;
add_depth();
if (node.expression != nullptr)
node.expression->accept(*this);
remove_depth();
}
void ASTPrinter::visit(ASTSelectionStmt &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "selection-stmt" << std::endl;
add_depth();
node.expression->accept(*this);
node.if_statement->accept(*this);
if (node.else_statement != nullptr)
node.else_statement->accept(*this);
remove_depth();
}
void ASTPrinter::visit(ASTIterationStmt &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "iteration-stmt" << std::endl;
add_depth();
node.expression->accept(*this);
node.statement->accept(*this);
remove_depth();
}
void ASTPrinter::visit(ASTReturnStmt &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "return-stmt";
if (node.expression == nullptr) {
std::cout << ": void" << std::endl;
} else {
std::cout << std::endl;
add_depth();
node.expression->accept(*this);
remove_depth();
}
}
void ASTPrinter::visit(ASTAssignExpression &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "assign-expression" << std::endl;
add_depth();
node.var->accept(*this);
node.expression->accept(*this);
remove_depth();
}
void ASTPrinter::visit(ASTSimpleExpression &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "simple-expression";
if (node.additive_expression_r == nullptr) {
std::cout << std::endl;
} else {
std::cout << ": ";
if (node.op == OP_LT) {
std::cout << "<";
} else if (node.op == OP_LE) {
std::cout << "<=";
} else if (node.op == OP_GE) {
std::cout << ">=";
} else if (node.op == OP_GT) {
std::cout << ">";
} else if (node.op == OP_EQ) {
std::cout << "==";
} else if (node.op == OP_NEQ) {
std::cout << "!=";
} else {
std::abort();
}
std::cout << std::endl;
}
add_depth();
node.additive_expression_l->accept(*this);
if (node.additive_expression_r != nullptr)
node.additive_expression_r->accept(*this);
remove_depth();
}
void ASTPrinter::visit(ASTAdditiveExpression &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "additive-expression";
if (node.additive_expression == nullptr) {
std::cout << std::endl;
} else {
std::cout << ": ";
if (node.op == OP_PLUS) {
std::cout << "+";
} else if (node.op == OP_MINUS) {
std::cout << "-";
} else {
std::abort();
}
std::cout << std::endl;
}
add_depth();
if (node.additive_expression != nullptr)
node.additive_expression->accept(*this);
node.term->accept(*this);
remove_depth();
}
void ASTPrinter::visit(ASTVar &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "var: " << node.id;
if (node.expression != nullptr) {
std::cout << "[]" << std::endl;
add_depth();
node.expression->accept(*this);
remove_depth();
return;
}
std::cout << std::endl;
}
void ASTPrinter::visit(ASTTerm &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "term";
if (node.term == nullptr) {
std::cout << std::endl;
} else {
std::cout << ": ";
if (node.op == OP_MUL) {
std::cout << "*";
} else if (node.op == OP_DIV) {
std::cout << "/";
} else {
std::abort();
}
std::cout << std::endl;
}
add_depth();
if (node.term != nullptr)
node.term->accept(*this);
node.factor->accept(*this);
remove_depth();
}
void ASTPrinter::visit(ASTCall &node) {
_DEBUG_PRINT_N_(depth);
std::cout << "call: " << node.id << "()" << std::endl;
add_depth();
for (auto arg: node.args) {
arg->accept(*this);
}
remove_depth();
}
#include "logging.hpp"
void LogWriter::operator<(const LogStream &stream) {
std::ostringstream msg;
msg << stream.sstream_->rdbuf();
output_log(msg);
}
void LogWriter::output_log(const std::ostringstream &msg) {
if (log_level_ >= env_log_level)
std::cout << "[" << level2string(log_level_) << "] "
<< "(" << location_.file_
<< ":" << location_.line_
<< "L "<< location_.func_<<")"
<< msg.str() << std::endl;
}
std::string level2string(LogLevel level) {
switch (level)
{
case DEBUG:
return "DEBUG";
case INFO:
return "INFO";
case WARNING:
return "WARNING";
case ERROR:
return "ERROR";
default:
return "";
}
}
std::string get_short_name(const char * file_path) {
std::string short_file_path = file_path;
int index = short_file_path.find_last_of('/');
return short_file_path.substr(index+1);
}
#include <stdlib.h>
#include <string.h>
#include "syntax_tree.h"
syntax_tree_node * new_syntax_tree_node(const char * name)
{
syntax_tree_node * new_node = (syntax_tree_node *)malloc(sizeof(syntax_tree_node));
if (name)
strncpy(new_node->name, name, SYNTAX_TREE_NODE_NAME_MAX);
else
new_node->name[0] = '\0';
new_node->children_num = 0;
return new_node;
}
int syntax_tree_add_child(syntax_tree_node * parent, syntax_tree_node * child)
{
if (!parent || !child) return -1;
parent->children[parent->children_num++] = child;
return parent->children_num;
}
void del_syntax_tree_node(syntax_tree_node * node, int recursive)
{
if (!node) return;
int i;
if (recursive) {
for (i = 0; i < node->children_num; i++) {
del_syntax_tree_node(node->children[i], 1);
}
}
free(node);
}
syntax_tree * new_syntax_tree()
{
return (syntax_tree *)malloc(sizeof(syntax_tree));
}
void del_syntax_tree(syntax_tree * tree)
{
if (!tree) return;
if (tree->root) {
del_syntax_tree_node(tree->root, 1);
}
free(tree);
}
void print_syntax_tree_node(FILE * fout, syntax_tree_node * node, int level)
{
// assume fout valid now
// check if "node" empty pointer
if (!node) return;
// print myself
int i;
for (i = 0; i < level; i++) {
fprintf(fout, "| ");
}
fprintf(fout, ">--%s %s\n", (node->children_num ? "+" : "*"), node->name);
for (i = 0; i < node->children_num; i++) {
print_syntax_tree_node(fout, node->children[i], level + 1);
}
}
void print_syntax_tree(FILE * fout, syntax_tree * tree)
{
if (!fout) return;
print_syntax_tree_node(fout, tree->root, 0);
}
flex_target(lex lexical_analyzer.l ${CMAKE_CURRENT_BINARY_DIR}/lexical_analyzer.c)
bison_target(syntax syntax_analyzer.y
${CMAKE_CURRENT_BINARY_DIR}/syntax_analyzer.c
DEFINES_FILE ${PROJECT_BINARY_DIR}/syntax_analyzer.h)
add_flex_bison_dependency(lex syntax)
add_library(syntax STATIC
${BISON_syntax_OUTPUTS}
${FLEX_lex_OUTPUTS}
)
%option noyywrap
%{
/*****************声明和选项设置 begin*****************/
#include <stdio.h>
#include <stdlib.h>
#include "syntax_tree.h"
#include "syntax_analyzer.h"
int lines;
int pos_start;
int pos_end;
void pass_node(char *text){
yylval.node = new_syntax_tree_node(text);
}
/*****************声明和选项设置 end*****************/
%}
%%
/* to do for students */
/* two cases for you, pass_node will send flex's token to bison */
\+ {pos_start = pos_end; pos_end += 1; pass_node(yytext); return ADD;}
. { pos_start = pos_end; pos_end++; return ERROR; }
/****请在此补全所有flex的模式与动作 end******/
%%
%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include "syntax_tree.h"
// external functions from lex
extern int yylex();
extern int yyparse();
extern int yyrestart();
extern FILE * yyin;
// external variables from lexical_analyzer module
extern int lines;
extern char * yytext;
extern int pos_end;
extern int pos_start;
// Global syntax tree
syntax_tree *gt;
// Error reporting
void yyerror(const char *s);
// Helper functions written for you with love
syntax_tree_node *node(const char *node_name, int children_num, ...);
%}
/* TODO: Complete this definition.
Hint: See pass_node(), node(), and syntax_tree.h.
Use forward declaring. */
%union {}
/* TODO: Your tokens here. */
%token <node> ERROR
%token <node> ADD
%type <node> program
%start program
%%
/* TODO: Your rules here. */
/* Example:
program: declaration-list {$$ = node( "program", 1, $1); gt->root = $$;}
;
*/
program : ;
%%
/// The error reporting function.
void yyerror(const char * s)
{
// TO STUDENTS: This is just an example.
// You can customize it as you like.
fprintf(stderr, "error at line %d column %d: %s\n", lines, pos_start, s);
}
/// Parse input from file `input_path`, and prints the parsing results
/// to stdout. If input_path is NULL, read from stdin.
///
/// This function initializes essential states before running yyparse().
syntax_tree *parse(const char *input_path)
{
if (input_path != NULL) {
if (!(yyin = fopen(input_path, "r"))) {
fprintf(stderr, "[ERR] Open input file %s failed.\n", input_path);
exit(1);
}
} else {
yyin = stdin;
}
lines = pos_start = pos_end = 1;
gt = new_syntax_tree();
yyrestart(yyin);
yyparse();
return gt;
}
/// A helper function to quickly construct a tree node.
///
/// e.g. $$ = node("program", 1, $1);
syntax_tree_node *node(const char *name, int children_num, ...)
{
syntax_tree_node *p = new_syntax_tree_node(name);
syntax_tree_node *child;
if (children_num == 0) {
child = new_syntax_tree_node("epsilon");
syntax_tree_add_child(p, child);
} else {
va_list ap;
va_start(ap, children_num);
for (int i = 0; i < children_num; ++i) {
child = va_arg(ap, syntax_tree_node *);
syntax_tree_add_child(p, child);
}
va_end(ap);
}
return p;
}
add_subdirectory(parser)
add_executable(test_ast test_ast.cpp)
add_executable(test_logging test_logging.cpp)
target_link_libraries(test_logging common)
target_link_libraries(test_ast syntax common)
syntree_easy/
syntree_normal/
syntree_hard/
syntree_lunatic/
include_directories(${PROJECT_BINARY_DIR})
add_executable(parser parser.c)
target_link_libraries(parser syntax common)
add_executable(lexer lexer.c)
target_link_libraries(lexer syntax common)
#!/bin/sh
rm -rf syntree_easy syntree_normal syntree_hard syntree_lunatic
/* unclosed comment
\ No newline at end of file
// cminus dont support comment like that
int main(void){
return 0;
}
\ No newline at end of file
/* unclosed function */
int main(void)
{
\ No newline at end of file
int a1;
int f1(void) {}
int f2(void) {}
/*Basic num part*/
int main(void){
a = 0;
x = 0.0;
x = 1.;
x = .1;
a = 1+1;
a = a-1;
x = x*1;
x = a/x;
return 0;
}
\ No newline at end of file
int a;
int f(void) {}
int g(void) {}
/*
I konw it's weird, even stupid, to code C like this. w(゚Д゚)w
HOWEVER, we have to use some tricky cases to test your answer.
*/
float GVAR;
void NeverEverDeclareLikeThis;
int GARRAY[2333];
void MyFuncA(int floatNum, float intNum, void voidNums[]){
int IKnowYouAreVoid;
return MyFuncB(IKnowYouAreVoid);
}
float MyFuncB(void){
int IAmVoid[0];
return MyFuncA(.0, 0, IAmVoid);
}
int main(void){
int a; int b; int c;
a = b = c = (85 == 84 + 0.4);
if(a = b){
GARRAY[ ( MyFuncB() ) ] = GARRAY[c = 1.*.1 == 1.1];
}else if (MyFuncC(NotDeclared)){
}else;
return 0.;
}
\ No newline at end of file
/* associativity and precedence */
int main(void)
{
a = b = c = 1 + 1 / 2 * 1 * (1 + 1 + 1 - 1 / 1) + 3 + 4 * 3;
}
int gcd (int u, int v) { /* calculate the gcd of u and v */
if (v == 0) return u;
else return gcd(v, u - u / v * v); /* v,u-u/v*v is equals to u mod v*/
}
int main(void) {
int x; int y; int temp;
x = 72;
y = 18;
if (x<y) {
temp = x;
x = y;
y = temp;
}
gcd(x,y);
return 0;
}
void move(int x, int y)
{
putint(x); putch(32); putint(y); putch(44); putch(32);
}
void hanoi(int n, int one, int two, int three)
{
if (n == 1)
move(one, three);
else {
hanoi(n - 1, one, three, two);
move(one, three);
hanoi(n - 1, two, one, three);
}
}
int main(void )
{
int n;
n = getint();
while (n > 0) {
hanoi(getint(), 1, 2, 3);
putch(10);
n = n - 1;
}
return 0;
}
/* else should be bound to the closest if */
int main(void)
{
if (1) {} else if (2) {} else {}
return 0;
}
/* this is the sample program in C- in the book "Compiler Construction" */
/* A program to perform selection sort on a 10 element array. */
int x[10];
int minloc ( int a[], int low, int high )
{ int i; int x; int k;
k = low;
x = a[low];
i = low + 1;
while (i < high)
{ if (a[i] < x)
{ x = a[i];
k = i; }
i = i + 1;
}
return k;
}
void sort( int a[], int low, int high)
{ int i; int k;
i = low;
while ( i < high-1)
{ int t;
k = minloc(a, i, high);
t = a[k];
a[k] = a[i];
a[i] = t;
i = i + 1;
}
}
void main(void)
{ int i;
i = 0;
while ( i < 10)
{ x[i] = input();
i = i + 1; }
sort(x, 0, 10);
i = 0;
while (i < 10)
{ output(x[i]);
i = i + 1; }
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<syntax_analyzer.h>
///
extern int lines;
extern int pos_start;
extern int pos_end;
///
extern FILE *yyin;
extern char *yytext;
extern int yylex();
// Mac-only hack.
YYSTYPE yylval;
///
int main(int argc, const char **argv) {
if (argc != 2) {
printf("usage: lexer input_file\n");
return 0;
}
const char *input_file = argv[1];
yyin = fopen(input_file, "r");
if (!yyin) {
fprintf(stderr, "cannot open file: %s\n", input_file);
return 1;
}
int token;
printf("%5s\t%10s\t%s\t%s\n", "Token", "Text", "Line", "Column (Start,End)");
while ((token = yylex())) {
printf("%-5d\t%10s\t%d\t(%d,%d)\n",
token, yytext,
lines, pos_start, pos_end);
}
return 0;
}
int main(void)
{
a=1;
1=a;
}
int main(void){
int a;
a = 1;
int b;
return 0;
}
\ No newline at end of file
int main(void) {
int array[1];
array[1] = 0;
return 0;
}
float foo(float a, float b[]) {
return 1;
}
int main(void) {
return 0;
}
/*Basic selection part*/
int main(void){
int a; int b;
a = 1;
b = 1;
if(a != b){
if(a == b);
else{
a = b;
}
}
return 0;
}
\ No newline at end of file
int main(void) {
int i; float j;
void v;
return 0;
}
/*
int main() {
int arr[100];
int i;
int sum;
i = 0;
sum = 0;
while (getint()) {
arr[i] = getint();
i = i + 1;
}*/
int main(void) {
int arr[100];
int i;
int sum;
i = 0;
sum = 0;
while (getint()) {
arr[i] = getint();
i = i + 1;
}
while (i) {
i = i - 1;
sum = sum + arr[i];
}
return sum - 79;
}
#include "syntax_tree.h"
extern syntax_tree *parse(const char*);
int main(int argc, char *argv[])
{
syntax_tree *tree = NULL;
const char *input = NULL;
if (argc >= 3) {
printf("usage: %s\n", argv[0]);
printf("usage: %s <cminus_file>\n", argv[0]);
return 1;
}
if (argc == 2) {
input = argv[1];
}
// Call the syntax analyzer.
tree = parse(input);
print_syntax_tree(stdout, tree);
del_syntax_tree(tree);
return 0;
}
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--+ statement-list
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | | >--* 0.0
| | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | >--* 1.
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | >--* .1
| | | | | | | | | | | | | >--* ;
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | >--* ;
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | >--* a
| | | | | | | | | | | | >--* =
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | >--* ;
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* x
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ expression-stmt
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ var
| | | | | | | | | | | >--* x
| | | | | | | | | | >--* =
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | >--* /
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* x
| | | | | | | | | >--* ;
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration-list
| | | | >--+ declaration
| | | | | >--+ var-declaration
| | | | | | >--+ type-specifier
| | | | | | | >--* int
| | | | | | >--* a
| | | | | | >--* ;
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* int
| | | | | >--* f
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--* void
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* g
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--* epsilon
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration-list
| | | | >--+ declaration-list
| | | | | >--+ declaration-list
| | | | | | >--+ declaration-list
| | | | | | | >--+ declaration
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* float
| | | | | | | | | >--* GVAR
| | | | | | | | | >--* ;
| | | | | | >--+ declaration
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* void
| | | | | | | | >--* NeverEverDeclareLikeThis
| | | | | | | | >--* ;
| | | | | >--+ declaration
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* GARRAY
| | | | | | | >--* [
| | | | | | | >--* 2333
| | | | | | | >--* ]
| | | | | | | >--* ;
| | | | >--+ declaration
| | | | | >--+ fun-declaration
| | | | | | >--+ type-specifier
| | | | | | | >--* void
| | | | | | >--* MyFuncA
| | | | | | >--* (
| | | | | | >--+ params
| | | | | | | >--+ param-list
| | | | | | | | >--+ param-list
| | | | | | | | | >--+ param-list
| | | | | | | | | | >--+ param
| | | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | | >--* int
| | | | | | | | | | | >--* floatNum
| | | | | | | | | >--* ,
| | | | | | | | | >--+ param
| | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | >--* float
| | | | | | | | | | >--* intNum
| | | | | | | | >--* ,
| | | | | | | | >--+ param
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* void
| | | | | | | | | >--* voidNums
| | | | | | | | | >--* [
| | | | | | | | | >--* ]
| | | | | | >--* )
| | | | | | >--+ compound-stmt
| | | | | | | >--* {
| | | | | | | >--+ local-declarations
| | | | | | | | >--+ local-declarations
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* IKnowYouAreVoid
| | | | | | | | | >--* ;
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ statement
| | | | | | | | | >--+ return-stmt
| | | | | | | | | | >--* return
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | >--* MyFuncB
| | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* IKnowYouAreVoid
| | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | >--* ;
| | | | | | | >--* }
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* float
| | | | | >--* MyFuncB
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--* void
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--* epsilon
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* IAmVoid
| | | | | | | | >--* [
| | | | | | | | >--* 0
| | | | | | | | >--* ]
| | | | | | | | >--* ;
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ return-stmt
| | | | | | | | | >--* return
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | >--* MyFuncA
| | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | | | | | >--* .0
| | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* IAmVoid
| | | | | | | | | | | | | | | >--* )
| | | | | | | | | >--* ;
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--+ local-declarations
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* a
| | | | | | | | | >--* ;
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* b
| | | | | | | | >--* ;
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* c
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* a
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | >--* b
| | | | | | | | | | | | >--* =
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | >--* c
| | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | >--* 85
| | | | | | | | | | | | | | | | | | | | >--+ relop
| | | | | | | | | | | | | | | | | | | | | >--* ==
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | >--* 84
| | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | | | | >--* 0.4
| | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ selection-stmt
| | | | | | | | | >--* if
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ var
| | | | | | | | | | | >--* a
| | | | | | | | | | >--* =
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* b
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* GARRAY
| | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* MyFuncB
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | >--* GARRAY
| | | | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* c
| | | | | | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1.
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* .1
| | | | | | | | | | | | | | | | | | | | | | | | >--+ relop
| | | | | | | | | | | | | | | | | | | | | | | | | >--* ==
| | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1.1
| | | | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--* }
| | | | | | | | | >--* else
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ selection-stmt
| | | | | | | | | | | >--* if
| | | | | | | | | | | >--* (
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | >--* MyFuncC
| | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | >--* NotDeclared
| | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | >--* )
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--* }
| | | | | | | | | | | >--* else
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | >--* ;
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ float
| | | | | | | | | | | | | | >--* 0.
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ expression-stmt
| | | | | | | | >--+ expression
| | | | | | | | | >--+ var
| | | | | | | | | | >--* a
| | | | | | | | | >--* =
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ var
| | | | | | | | | | | >--* b
| | | | | | | | | | >--* =
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* c
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | | >--* /
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | >--* 2
| | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | | | | | >--* /
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 3
| | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 4
| | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 3
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* int
| | | | | >--* gcd
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--+ param-list
| | | | | | | >--+ param-list
| | | | | | | | >--+ param
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* u
| | | | | | | >--* ,
| | | | | | | >--+ param
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* v
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ selection-stmt
| | | | | | | | | >--* if
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* v
| | | | | | | | | | | >--+ relop
| | | | | | | | | | | | >--* ==
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | >--* 0
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ return-stmt
| | | | | | | | | | | >--* return
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* u
| | | | | | | | | | | >--* ;
| | | | | | | | | >--* else
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ return-stmt
| | | | | | | | | | | >--* return
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | >--* gcd
| | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* v
| | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* u
| | | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* u
| | | | | | | | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | | | | | | | >--* /
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* v
| | | | | | | | | | | | | | | | | | | | | | | >--+ mulop
| | | | | | | | | | | | | | | | | | | | | | | | >--* *
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | >--* v
| | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | >--* ;
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--+ local-declarations
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* x
| | | | | | | | | >--* ;
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* y
| | | | | | | | >--* ;
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* temp
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--+ statement-list
| | | | | | | | | | | >--* epsilon
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | >--* 72
| | | | | | | | | | | | >--* ;
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | >--* y
| | | | | | | | | | | | >--* =
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 18
| | | | | | | | | | | >--* ;
| | | | | | | | >--+ statement
| | | | | | | | | >--+ selection-stmt
| | | | | | | | | | >--* if
| | | | | | | | | | >--* (
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | >--+ relop
| | | | | | | | | | | | | >--* <
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* y
| | | | | | | | | | >--* )
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | >--* {
| | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | >--* temp
| | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* y
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* y
| | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | >--* temp
| | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | >--* }
| | | | | | | >--+ statement
| | | | | | | | >--+ expression-stmt
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | >--* gcd
| | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* y
| | | | | | | | | | | | | | | >--* )
| | | | | | | | | >--* ;
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration-list
| | | | >--+ declaration
| | | | | >--+ fun-declaration
| | | | | | >--+ type-specifier
| | | | | | | >--* void
| | | | | | >--* move
| | | | | | >--* (
| | | | | | >--+ params
| | | | | | | >--+ param-list
| | | | | | | | >--+ param-list
| | | | | | | | | >--+ param
| | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | >--* int
| | | | | | | | | | >--* x
| | | | | | | | >--* ,
| | | | | | | | >--+ param
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* y
| | | | | | >--* )
| | | | | | >--+ compound-stmt
| | | | | | | >--* {
| | | | | | | >--+ local-declarations
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--+ statement-list
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | >--* putint
| | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | >--* putch
| | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 32
| | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | >--* ;
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | >--* putint
| | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* y
| | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | >--* ;
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | >--* putch
| | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | >--* 44
| | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | >--* ;
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | >--* putch
| | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | >--* 32
| | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | >--* ;
| | | | | | | >--* }
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* void
| | | | | >--* hanoi
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--+ param-list
| | | | | | | >--+ param-list
| | | | | | | | >--+ param-list
| | | | | | | | | >--+ param-list
| | | | | | | | | | >--+ param
| | | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | | >--* int
| | | | | | | | | | | >--* n
| | | | | | | | | >--* ,
| | | | | | | | | >--+ param
| | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | >--* int
| | | | | | | | | | >--* one
| | | | | | | | >--* ,
| | | | | | | | >--+ param
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* two
| | | | | | | >--* ,
| | | | | | | >--+ param
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* three
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ selection-stmt
| | | | | | | | | >--* if
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* n
| | | | | | | | | | | >--+ relop
| | | | | | | | | | | | >--* ==
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | >--* 1
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | >--* move
| | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* one
| | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | >--* three
| | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | >--* ;
| | | | | | | | | >--* else
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | | >--* hanoi
| | | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* n
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* one
| | | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* three
| | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* two
| | | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | >--* move
| | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* one
| | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* three
| | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | >--* hanoi
| | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* n
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* two
| | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* one
| | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* three
| | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--* }
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* n
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* n
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | >--* getint
| | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ iteration-stmt
| | | | | | | | | >--* while
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* n
| | | | | | | | | | | >--+ relop
| | | | | | | | | | | | >--* >
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | >--* 0
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | | >--* hanoi
| | | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* getint
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 2
| | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 3
| | | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | >--* putch
| | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* 10
| | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* n
| | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | >--* n
| | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--* }
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ selection-stmt
| | | | | | | | | >--* if
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | >--* 1
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--* }
| | | | | | | | | >--* else
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ selection-stmt
| | | | | | | | | | | >--* if
| | | | | | | | | | | >--* (
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 2
| | | | | | | | | | | >--* )
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--* }
| | | | | | | | | | | >--* else
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--* }
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration-list
| | | | >--+ declaration-list
| | | | | >--+ declaration
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* x
| | | | | | | >--* [
| | | | | | | >--* 10
| | | | | | | >--* ]
| | | | | | | >--* ;
| | | | >--+ declaration
| | | | | >--+ fun-declaration
| | | | | | >--+ type-specifier
| | | | | | | >--* int
| | | | | | >--* minloc
| | | | | | >--* (
| | | | | | >--+ params
| | | | | | | >--+ param-list
| | | | | | | | >--+ param-list
| | | | | | | | | >--+ param-list
| | | | | | | | | | >--+ param
| | | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | | >--* int
| | | | | | | | | | | >--* a
| | | | | | | | | | | >--* [
| | | | | | | | | | | >--* ]
| | | | | | | | | >--* ,
| | | | | | | | | >--+ param
| | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | >--* int
| | | | | | | | | | >--* low
| | | | | | | | >--* ,
| | | | | | | | >--+ param
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* high
| | | | | | >--* )
| | | | | | >--+ compound-stmt
| | | | | | | >--* {
| | | | | | | >--+ local-declarations
| | | | | | | | >--+ local-declarations
| | | | | | | | | >--+ local-declarations
| | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | >--* epsilon
| | | | | | | | | | >--+ var-declaration
| | | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | | >--* int
| | | | | | | | | | | >--* i
| | | | | | | | | | | >--* ;
| | | | | | | | | >--+ var-declaration
| | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | >--* int
| | | | | | | | | | >--* x
| | | | | | | | | | >--* ;
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* k
| | | | | | | | | >--* ;
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--+ statement-list
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* k
| | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | >--* low
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* low
| | | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | >--* ;
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | >--* low
| | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | >--* ;
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ iteration-stmt
| | | | | | | | | | | >--* while
| | | | | | | | | | | >--* (
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | >--+ relop
| | | | | | | | | | | | | | >--* <
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* high
| | | | | | | | | | | >--* )
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | >--+ selection-stmt
| | | | | | | | | | | | | | | | | >--* if
| | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | | | | >--+ relop
| | | | | | | | | | | | | | | | | | | | >--* <
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* k
| | | | | | | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | | | | | | >--* }
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--* }
| | | | | | | | >--+ statement
| | | | | | | | | >--+ return-stmt
| | | | | | | | | | >--* return
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* k
| | | | | | | | | | >--* ;
| | | | | | | >--* }
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* void
| | | | | >--* sort
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--+ param-list
| | | | | | | >--+ param-list
| | | | | | | | >--+ param-list
| | | | | | | | | >--+ param
| | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | >--* int
| | | | | | | | | | >--* a
| | | | | | | | | | >--* [
| | | | | | | | | | >--* ]
| | | | | | | | >--* ,
| | | | | | | | >--+ param
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* low
| | | | | | | >--* ,
| | | | | | | >--+ param
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* high
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--+ local-declarations
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* i
| | | | | | | | | >--* ;
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* k
| | | | | | | | >--* ;
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* i
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* low
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ iteration-stmt
| | | | | | | | | >--* while
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | >--+ relop
| | | | | | | | | | | | >--* <
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* high
| | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | >--* -
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | >--* 1
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ var-declaration
| | | | | | | | | | | | | >--+ type-specifier
| | | | | | | | | | | | | | >--* int
| | | | | | | | | | | | | >--* t
| | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | >--* k
| | | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | | | | | >--* minloc
| | | | | | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* high
| | | | | | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | >--* t
| | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* k
| | | | | | | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* k
| | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | >--* t
| | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--* }
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* void
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* i
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--+ statement-list
| | | | | | | | | | | >--* epsilon
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | | | | >--* ;
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ iteration-stmt
| | | | | | | | | | | >--* while
| | | | | | | | | | | >--* (
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | >--+ relop
| | | | | | | | | | | | | | >--* <
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 10
| | | | | | | | | | | >--* )
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | | | | >--* input
| | | | | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--* }
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | >--* sort
| | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | | | | | | | | | | >--* ,
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | | | >--* 10
| | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ expression-stmt
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ var
| | | | | | | | | | | >--* i
| | | | | | | | | | >--* =
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | >--* ;
| | | | | | >--+ statement
| | | | | | | >--+ iteration-stmt
| | | | | | | | >--* while
| | | | | | | | >--* (
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | >--* i
| | | | | | | | | | >--+ relop
| | | | | | | | | | | >--* <
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 10
| | | | | | | | >--* )
| | | | | | | | >--+ statement
| | | | | | | | | >--+ compound-stmt
| | | | | | | | | | >--* {
| | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | >--* epsilon
| | | | | | | | | | >--+ statement-list
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | >--* output
| | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | >--+ arg-list
| | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* x
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--+ statement
| | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | >--* ;
| | | | | | | | | | >--* }
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* array
| | | | | | | >--* [
| | | | | | | >--* 1
| | | | | | | >--* ]
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ expression-stmt
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ var
| | | | | | | | | | | >--* array
| | | | | | | | | | | >--* [
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | >--* ]
| | | | | | | | | | >--* =
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | >--* ;
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration-list
| | | >--+ declaration
| | | | >--+ fun-declaration
| | | | | >--+ type-specifier
| | | | | | >--* float
| | | | | >--* foo
| | | | | >--* (
| | | | | >--+ params
| | | | | | >--+ param-list
| | | | | | | >--+ param-list
| | | | | | | | >--+ param
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* float
| | | | | | | | | >--* a
| | | | | | | >--* ,
| | | | | | | >--+ param
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* float
| | | | | | | | >--* b
| | | | | | | | >--* [
| | | | | | | | >--* ]
| | | | | >--* )
| | | | | >--+ compound-stmt
| | | | | | >--* {
| | | | | | >--+ local-declarations
| | | | | | | >--* epsilon
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--* epsilon
| | | | | | | >--+ statement
| | | | | | | | >--+ return-stmt
| | | | | | | | | >--* return
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | >--* 1
| | | | | | | | | >--* ;
| | | | | | >--* }
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--* epsilon
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--* epsilon
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* a
| | | | | | | | >--* ;
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* b
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--* epsilon
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | >--* a
| | | | | | | | | | | | >--* =
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | >--* ;
| | | | | | | | >--+ statement
| | | | | | | | | >--+ expression-stmt
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ var
| | | | | | | | | | | | >--* b
| | | | | | | | | | | >--* =
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | >--* ;
| | | | | | | >--+ statement
| | | | | | | | >--+ selection-stmt
| | | | | | | | | >--* if
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | >--+ relop
| | | | | | | | | | | | >--* !=
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* b
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ selection-stmt
| | | | | | | | | | | | | | >--* if
| | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | >--+ relop
| | | | | | | | | | | | | | | | | >--* ==
| | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | >--* b
| | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | >--* else
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | | | | | >--* {
| | | | | | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | >--* a
| | | | | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | >--* b
| | | | | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | | | | >--* }
| | | | | | | | | | | >--* }
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--+ local-declarations
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* i
| | | | | | | | | >--* ;
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* float
| | | | | | | | >--* j
| | | | | | | | >--* ;
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* void
| | | | | | | >--* v
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--* epsilon
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 0
| | | | | | | | >--* ;
| | | | | >--* }
>--+ program
| >--+ declaration-list
| | >--+ declaration
| | | >--+ fun-declaration
| | | | >--+ type-specifier
| | | | | >--* int
| | | | >--* main
| | | | >--* (
| | | | >--+ params
| | | | | >--* void
| | | | >--* )
| | | | >--+ compound-stmt
| | | | | >--* {
| | | | | >--+ local-declarations
| | | | | | >--+ local-declarations
| | | | | | | >--+ local-declarations
| | | | | | | | >--+ local-declarations
| | | | | | | | | >--* epsilon
| | | | | | | | >--+ var-declaration
| | | | | | | | | >--+ type-specifier
| | | | | | | | | | >--* int
| | | | | | | | | >--* arr
| | | | | | | | | >--* [
| | | | | | | | | >--* 100
| | | | | | | | | >--* ]
| | | | | | | | | >--* ;
| | | | | | | >--+ var-declaration
| | | | | | | | >--+ type-specifier
| | | | | | | | | >--* int
| | | | | | | | >--* i
| | | | | | | | >--* ;
| | | | | | >--+ var-declaration
| | | | | | | >--+ type-specifier
| | | | | | | | >--* int
| | | | | | | >--* sum
| | | | | | | >--* ;
| | | | | >--+ statement-list
| | | | | | >--+ statement-list
| | | | | | | >--+ statement-list
| | | | | | | | >--+ statement-list
| | | | | | | | | >--+ statement-list
| | | | | | | | | | >--+ statement-list
| | | | | | | | | | | >--* epsilon
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | | | | >--* ;
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | >--+ expression
| | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | >--* sum
| | | | | | | | | | | | >--* =
| | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | >--* 0
| | | | | | | | | | | >--* ;
| | | | | | | | >--+ statement
| | | | | | | | | >--+ iteration-stmt
| | | | | | | | | | >--* while
| | | | | | | | | | >--* (
| | | | | | | | | | >--+ expression
| | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | >--* getint
| | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | >--* )
| | | | | | | | | | >--+ statement
| | | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | | >--* {
| | | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | >--* arr
| | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ call
| | | | | | | | | | | | | | | | | | | | | | | >--* getint
| | | | | | | | | | | | | | | | | | | | | | | >--* (
| | | | | | | | | | | | | | | | | | | | | | | >--+ args
| | | | | | | | | | | | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | | | | | | | | | | | >--* )
| | | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | >--* }
| | | | | | | >--+ statement
| | | | | | | | >--+ iteration-stmt
| | | | | | | | | >--* while
| | | | | | | | | >--* (
| | | | | | | | | >--+ expression
| | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* i
| | | | | | | | | >--* )
| | | | | | | | | >--+ statement
| | | | | | | | | | >--+ compound-stmt
| | | | | | | | | | | >--* {
| | | | | | | | | | | >--+ local-declarations
| | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | >--+ statement-list
| | | | | | | | | | | | | | >--* epsilon
| | | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | | >--* -
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | | | | | | | | | >--* 1
| | | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | | >--+ statement
| | | | | | | | | | | | | >--+ expression-stmt
| | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | >--* sum
| | | | | | | | | | | | | | | >--* =
| | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | >--* sum
| | | | | | | | | | | | | | | | | | >--+ addop
| | | | | | | | | | | | | | | | | | | >--* +
| | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | >--* arr
| | | | | | | | | | | | | | | | | | | | | >--* [
| | | | | | | | | | | | | | | | | | | | | >--+ expression
| | | | | | | | | | | | | | | | | | | | | | >--+ simple-expression
| | | | | | | | | | | | | | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | | | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | | | | | | | | | | | | | >--* i
| | | | | | | | | | | | | | | | | | | | | >--* ]
| | | | | | | | | | | | | | >--* ;
| | | | | | | | | | | >--* }
| | | | | | >--+ statement
| | | | | | | >--+ return-stmt
| | | | | | | | >--* return
| | | | | | | | >--+ expression
| | | | | | | | | >--+ simple-expression
| | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | >--+ additive-expression
| | | | | | | | | | | | >--+ term
| | | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | | >--+ var
| | | | | | | | | | | | | | | >--* sum
| | | | | | | | | | | >--+ addop
| | | | | | | | | | | | >--* -
| | | | | | | | | | | >--+ term
| | | | | | | | | | | | >--+ factor
| | | | | | | | | | | | | >--+ integer
| | | | | | | | | | | | | | >--* 79
| | | | | | | | >--* ;
| | | | | >--* }
#!/bin/bash
# DO NOT MODIFY!
# If you need customized behavior, please create your own script.
CUR_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
TESTCASE="${1:-testcase}"
TESTCASE_DIR="$CUR_DIR/$TESTCASE"
OUTPUT_DIR="$CUR_DIR/syntree_$TESTCASE"
BUILD_DIR="$CUR_DIR/../../build"
# Make sure $OUTPUT_DIR exists.
mkdir -p "$OUTPUT_DIR"
# Generate a .syntax_tree file for all .cminus files in the testcase dir.
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for testcase in "$TESTCASE_DIR"/*.cminus
do
filename="$(basename $testcase)"
echo "[info] Analyzing $filename"
"$BUILD_DIR"/parser "$testcase" > "$OUTPUT_DIR/${filename%.cminus}.syntax_tree"
done
# Output a summary when requested.
if [[ ${2:-no} != "no" ]]; then
echo "[info] Comparing..."
if [[ ${2:-no} == "verbose" ]]; then
diff "$OUTPUT_DIR" "${OUTPUT_DIR}_std"
else
diff -qr "$OUTPUT_DIR" "${OUTPUT_DIR}_std"
fi
if [ $? -eq 0 ]; then
echo "[info] No difference! Congratulations!"
fi
fi
IFS=$SAVEIFS
#include "ast.hpp"
#include <iostream>
int main(int argc, char **argv)
{
if (argc != 2) {
std::cout << "usage: " << argv[0] << " <cminus_file>" << std::endl;
} else {
auto s = parse(argv[1]);
auto a = AST(s);
auto printer = ASTPrinter();
a.run_visitor(printer);
}
return 0;
}
#include"logging.hpp"
// 引入头文件
int main(){
LOG(DEBUG) << "This is DEBUG log item.";
// 使用关键字LOG,括号中填入要输出的日志等级
// 紧接着就是<<以及日志的具体信息,这一步就跟使用std::cout一样
LOG(INFO) << "This is INFO log item";
LOG(WARNING) << "This is WARNING log item";
LOG(ERROR) << "This is ERROR log item";
return 0;
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment