diff --git a/report/code generation.md b/report/code generation.md new file mode 100644 index 0000000..74da107 --- /dev/null +++ b/report/code generation.md @@ -0,0 +1,581 @@ +# 5 Code Generation + +> 陈俊儒 + + + +## 5.1 Overview + +  为了考虑开发效率,我们将语义分析和代码生成完全分开,语义分析负责所有的正确性检测和常数折叠。代码生成则是基于语义分析后新产生的语法树进行的,主要分为几大部分`control statement`、`assignment statement`、`routine statement`、`expression statement`,分别对应条件语句、赋值语句、函数及过程语句、算术表达式语句。 + +  我们使用的语言为`Pascal`语法子集,代码生成为`three-address code`中间代码,符号基本沿用教材定义,对于支持的功能、语法原生不支持的功能、语法支持但未实现的功能,会在以下展示出来,报告顺序基本按照我们定义的`yacc`语句顺序展开。 + +  关于主要类和函数: + +- **class Quadruple(object)** — 四元组数据结构,存储形如(op, target, right_1, right_2)四元组,根据需要任何一个都可以为`None`。 +- **class CodeGenerator(object)** — 供主函数调用的类。 +- **def _add_new_quad(...)** — 添加新的四元组。 +- **def _traverse_ast_gen_code(self, root_node)** — 主循环,几乎所有的判断都在这里实现,不断被递归调用。 +- **def gen_quad_list_in_expression_node(self, expression_node)** — 专门为`expression`结点设计处理函数,这是由于其他语句不需要返回值,但这里作为算术运算部分,自成生态,这里面的所有语句都需要拥有返回值,要么直接是值本身,要么是存储这个值的临时变量名,供其他语句调用,这个函数使用非常频繁。 +- **def gen_quad_list_from_expression_node(self, expression_node)** — 为`expression`结点下设计的处理函数,主要包含`expr/term/factor`语句。被上面的函数调用。 +- **def traverse_skew_tree_gen(node, stop_node_type=None)** — 将`node`结点左递归展平,按照`stop_node_type`为准则决定何时停止进程。 +- **def traverse_skew_tree_bool(node, stop_node_type, target_node_type)** — 此处和上面不同,专用于`term-AND/expr-OR`条件语句,这里是为了辅助从左至右只要有一个语句满足了退出条件,则需要退出,因此,此处是按照连续的同名结点展开,当结点为下一级或同级非同名时,需要退出递归过程。 + + + +## 5.2 Routine Statement + +  此部分展示关于`function/procedure`部分,包含了定义和调用模块,实现严格按照教材示例用法,由于只生成中间代码,因此此处没有考虑返回值及返回地址的传递和堆栈。 + +### 5.2.1 定义部分 + +**宏观调度** + +```python +# routine : routine_head routine_body +``` + +```python + if root_node.type == 'routine': + self._traverse_ast_gen_code(root_node.children[0]) + self._traverse_ast_gen_code(root_node.children[1]) + if len(self._routine_stack) > 0: + if self._routine_stack[-1][1]: + self._add_new_quad('return', self._routine_stack[-1][0]) + self._add_new_quad('end_define', self._routine_stack[-1][0]) + self._routine_stack.pop() +``` + +> `routine`是声明与执行语句的连接点,Pascal语言要求声明和定义必须在执行语句之前,而`routine_head`则包含了基本声明(名称、参数、返回值?,局部临时变量?),`routine_body`则是执行代码部分,如果`routine_head`的儿子全为空,则说明这是主函数,而非声明或定义。 + +此处由于函数嵌套定义的存在,因此必须借助堆栈来记录函数名称,这是由于Pascal语言没有`return`这样的保留字,默认为将函数名称视为返回值,因此,我必须记录返回值(即函数名)来完成返回语句。加上嵌套,因此选用堆栈,处理完声明部分,再处理执行语句,最后加一个返回语句。 + +**声明部分** + +```python +# function_head : kFUNCTION ID parameters COLON simple_type_decl +``` + +```python + elif root_node.type == 'function_head': + self._add_new_quad('entry', root_node.children[0]) + self._routine_stack.append((root_node.children[0], True)) +``` + +```python +# procedure_head : kPROCEDURE ID parameters +``` + +```python + elif root_node.type == 'procedure_head': + self._add_new_quad('entry', root_node.children[0]) + self._routine_stack.append((root_node.children[0], False)) +``` + +> 此部分就是输出函数入口语句,然后将函数名堆栈,这里只存在声明,不存在执行语句,因此与生成代码无关,主要是语义分析需要使用。 +> +> - True -- 表示函数声明,需要加返回语句。 +> - False -- 表示过程声明,不需要返回语句。 + +--- + +### 5.2.2 调用部分 + +**procedure** + +```python +# proc_stmt : ID +# | SYS_PROC +``` + +```python + if root_node.type == 'proc_stmt-simple': + self._add_new_quad('call', children[0]) +``` + +> 此处直接产生`call+name`即可,表示无条件跳转到procedure执行代码部分。 + +```python +# proc_stmt : ID LP args_list RP +# | SYS_PROC LP expression_list RP +# | kREAD LP factor RP +``` + +```python + if children[0] == 'read': + self._add_new_quad('begin_args', None) + args_val = self.gen_quad_list_from_expression_node(children[1]) + self._add_new_quad('read', args_val) +``` + +> 这是专门给`read`函数的执行语句,形式为`read args`,由于这个语法本身拥有这个语句,所以单独处理了。 + +```python +# expression_list : expression_list COMMA expression +# | expression +# args_list : args_list COMMA expression +# | expression +``` + +```python + else: + self._add_new_quad('begin_args', None) + args_list = traverse_skew_tree_gen(children[1], 'expression') + for args in args_list: + if isinstance(args, Node): + ret_val = self.gen_quad_list_in_expression_node(args) + self._add_new_quad('args', ret_val) + else: + self._add_new_quad('args', args) + self._add_new_quad('call', children[0]) +``` + +> 这里主要处理前两种语句,由于`args_list`和`expression_list`本质是一样的,因此可以联合处理。先计算参数值,这里通过将左递归语法树展平,再来从左至右逐一扫描,每一个`expression`均代表一个参数的计算,最后调用即可,不存在返回值。 + +**function** + +```python +# factor : SYS_FUNCT +# | ID LP args_list RP +# | SYS_FUNCT LP args_list RP +``` + +```python + elif expression_node.type == 'factor-func': + target = self.new_tmp_var + if len(expression_node.children) == 1: + self._add_new_quad('call', expression_node.children[0], target) + else: + func_name, args_list_node = expression_node.children + self._add_new_quad('begin_args', None) + args_list = traverse_skew_tree_gen(args_list_node, 'expression') + for args in args_list: + ret_val = self.gen_quad_list_in_expression_node(args) + self._add_new_quad('args', ret_val) + self._add_new_quad('call', func_name, target) + return target +``` + +> 函数调用位于`expression`系列中,这是因为函数调用存在返回值,可以作为赋值语句的右端。基本思路和过程调用类似,区分处理了系统自带无参函数和其余有参函数。只不过在最后需要返回存储函数返回值的临时变量名。 + +--- + + + +## 5.3 Assignment Statement + +  这是比较简单的一部分,只需要分为几种不同的左值处理即可。 + +### 5.3.1 普通变量 + +```python +# ID ASSIGN expression +``` + +```python + if root_node.type == 'assign_stmt': + if len(children) == 2: + id_, maybe_expression_node = children + if not isinstance(maybe_expression_node, Node): + self._add_new_quad(None, id_, maybe_expression_node) + else: + val = self.gen_quad_list_in_expression_node(maybe_expression_node) + self._add_new_quad(None, id_, val) +``` + +> 此处直接通过`expression`处理函数,当然首先是保证右值不是常数而是结点的前提下。最后直接赋值即可。 + +--- + +### 5.3.2 数组变量 + +```python +# ID LB expression RB assign expression +``` + +```python + elif root_node.type == 'assign_stmt-arr': + id_, index_expression_node, val_expression_node = children + index_val = self.gen_quad_list_in_expression_node(index_expression_node) + assign_val = self.gen_quad_list_in_expression_node(val_expression_node) + self._add_new_quad(None, f'{id_}[{index_val}]', assign_val) +``` + +> 此处也是直接进行两次`expression`调用获取索引值和右端值,按照教材写法,这里直接使用数组写法作为三段码输出即可。 + +--- + +### 5.3.3 结构体变量 + +```python +# assign_stmt : ID DOT ID ASSIGN expression +``` + +```python + else: + record_name, field_name, val_expression = root_node.children + address_var = self.new_tmp_var + self._add_new_quad('address', address_var, record_name, field_name) + ret_val = self.gen_quad_list_in_expression_node(val_expression) + self._add_new_quad(None, '*' + address_var, ret_val) +``` + +> 此处唯一要讲的是按照教材关于结构体成员取值的写法: +> +> ​ t = &x + field_offset(x, field_name) + +--- + + + +## 5.4 Control Statement + +  这一部分算是生成代码比较核心的一部分,主要贯穿着与汇编基本相同的写法,处理情况较多,Pascal包含了很多种循环体结构语句。但一旦厘清顺序和逻辑,本身并不复杂,由于这部分主要是控制语句,下面不会贴上代码,因为冗杂而不易理解,只展示控制流。 + +### 5.4.1 if statement + +```python +# if_stmt : kIF expression kTHEN stmt else_clause +# else_clause : kELSE stmt +# | empty +``` + +``` +t <- if_expression +if_false t goto else_label + +{if_stmt part} + +goto exit_label +else_label + +{else_stmt part}?(if exist) + +exit_label +``` + +--- + +### 5.4.2 repeat statement + +```python +# repeat_stmt : kREPEAT stmt_list kUNTIL expression +# stmt_list : stmt_list stmt SEMICON +# | empty +``` + +``` +enter_label + +{repeat_stmt} + +t <- repeat_expression +if_false t goto exit_label +goto enter_label +exit_label +``` + +--- + +### 5.4.3 while statement + +```python +# while_stmt : kWHILE expression kDO stmt +``` + +``` +judge_label +t <- while_expression +if_false t goto exit_label + +{while_stmt} + +goto judge_label +exit_label +``` + +--- + +### 5.4.4 for statement + +```python +# for_stmt : kFOR ID ASSIGN expression direction expression kDO stmt +# direction : kTO +# | kDOWNTO +``` + +``` +ID <- start_value_expression +bound_var <- end_value_expression + +judge_label + +*'to': t <- ID <= bound_var +*'downto': t <- ID >= bound_var + +if_false t goto exit_label + +{for_stmt} + +*'to': ID <- ID + 1 +*'downto': ID <- ID - 1 + +goto judge_label +exit_label +``` + +--- + +### 5.4.5 case statement + +```python +# case_stmt : kCASE expression kOF case_expr_list kEND +# case_expr_list : case_expr_list case_expr +# | case_expr +# case_expr : const_value COLON stmt SEMICON +# | ID COLON stmt SEMICON +# | kELSE COLON stmt SEMICON +``` + +``` +choose_var <- case_expression +case_list <- flatten the case_expr_list tree +for case_expr in case_list + +{judge_value <- case_expr.children[0] + next_label <- new_label + t <- choose_var == judge_value + if_false t goto next_label + {case_expr_stmt} + goto exit_label + next_label} + + exit_label +``` + +### 5.4.6 goto statement + +> 我们没有支持`goto`指令,因为这对语义分析带来了麻烦。 + +--- + + + +## 5.5 Expression Statement + +  这部分也是非常重要的部分,涉及到所有的算术运算,也是非常基本的分析部分。这块内容主要包含两个函数 + +- **def gen_quad_list_in_expression_node(self, expression_node)** +- **def gen_quad_list_from_expression_node(self, expression_node)** + +### 5.5.1 expression node + +这个函数是专门针对expression结点进行的,由于yacc中我们要求expression必须有结点,因此这里本质是算术运算的入口。 + +```python +# expression : expression GE expr +# | expression GT expr +# | expression LE expr +# | expression LT expr +# | expression EQUAL expr +# | expression UNEQUAL expr +# | expr +``` + +```python +def gen_quad_list_in_expression_node(self, expression_node): + if not isinstance(expression_node, Node): + return expression_node + if len(expression_node.children) == 1: + return self.gen_quad_list_from_expression_node(expression_node.children[0]) + else: + left_val = self.gen_quad_list_in_expression_node(expression_node.children[0]) + right_val = self.gen_quad_list_from_expression_node(expression_node.children[2]) + target = self.new_tmp_var + op = expression_node.children[1] + if op == '=': + self._add_new_quad('==', target, left_val, right_val) + elif op == '<>': + self._add_new_quad('!=', target, left_val, right_val) + else: + self._add_new_quad(op, target, left_val, right_val) + return target +``` + +> 此处只区分了是否含有一个以上的孩子结点,若没有,则根据是否为结点直接返回相应值或者临时变量;若有,则递归调用自己或者处理后部分的函数,得到后做判断即可。 + +--- + +### 5.5.2 expr/term/factor node + +这里分为四大部分,分别为`internal expression node`、`factor node`、`expr-OR/term-AND node`、`left node`。 + +**internal expression node** + +```python +# factor : LP expression RP +``` + +```python + if expression_node.type == 'expression': + return self.gen_quad_list_in_expression_node(expression_node) +``` + +> 这是一种特殊情况,虽然实际应用中,这个内部的expression node会直接接在外层的expression node下,但为了保险起见,还是在这里加一句。 + +--- + +**factor node** + +这里又分为几种不同的右值情况,与`assignment statement`左值情况类似。 + +```python +# kNOT factor +# SUBSTRACT factor +``` + +```python + elif expression_node.type == 'factor': + children = expression_node.children + unary_op, right_child = children + right_val = self.gen_quad_list_from_expression_node(right_child) + target = self.new_tmp_var + self._add_new_quad(unary_op, target, right_val) + return target +``` + +> 这是单操作符(not, -)运算。 + + + +```python +# factor : ID LB expression RB +``` + +```python + elif expression_node.type == 'factor-arr': + arr_id, right_child_node = expression_node.children + index_val = self.gen_quad_list_from_expression_node(right_child_node) + target = self.new_tmp_var + self._add_new_quad(None, target, f'{arr_id}[{index_val}]') + return target +``` + +> 这是数组元素取值。 + + + +```python +# factor : ID DOT ID +``` + +```python + elif expression_node.type == 'factor-member': + record_name, field_name = expression_node.children + target = self.new_tmp_var + self._add_new_quad('address', target, record_name, field_name) + return '*' + target +``` + +> 这是结构体取成员变量。 + + + +> `factor-func`见函数调用部分。 + +--- + +**expr-OR/term-AND node** + +这里要这么区分的原因在于,`and/or`操作连续出现时,我们必须按顺序从左往右逐一判断,对于`and`操作而言,本质是连续满足条件,一旦有一个条件不满足就需要直接结束判断,这是因为后续条件很可能需要这个前序条件成立。当然,这也是一种优化,我们不必一定要从头判断到尾,只要中间有一个打破或者满足条件了,就能离开或者进入。 + +```python +# expr : expr kOR term +``` + +```python + if expression_node.type == 'expr-OR': + bool_list = traverse_skew_tree_bool(expression_node, 'term', 'expr-OR') + jump_label = self.new_label + for or_node in bool_list: + condition_value = self.gen_quad_list_from_expression_node(or_node) + self._add_new_quad('goto', jump_label, 'if', condition_value) + target = self.new_tmp_var + self._add_new_quad(None, target, 0) + exit_label = self.new_label + self._add_new_quad('goto', exit_label) + self._add_new_quad(jump_label, None) + self._add_new_quad(None, target, 1) + self._add_new_quad(exit_label, None) + return target +``` + +> 这里最关键的就是 +> +> - **def traverse_skew_tree_bool(node, stop_node_type, target_node_type)** +> +> 这个函数功能在`overview`部分已经有介绍,目的是根据连续的`and/or`结点将表达式打断,形成一条长串,然后按照之前说的情形进行判断。 +> +> `term-AND`类似不再赘述。 + + + +⚠ 这里有一个语法本身的问题出现。 + +```pascal +if (a = 1 and a = 2 and a = 3) then +``` + +  在这个语句里,我们的语法图中为 + +![CG_00](.\imgs\CG_00.png) + +我们可以看到,在我们的语法中,`expression`的优先级高于`term`,因此产生`shitf-reduce`冲突时,优先进行`shift`操作,比如栈中出现`$a=1`时,这里有两个选择,一个是规约产生`expression`,一个是继续移入再规约产生`term`,由于默认移入,因此右值就被`term`结点抢走了,没有达到我们的要求,我们应当优先规约。 + +但我们可以换一种写法,即每一个判断式都加上括号 + +```pascal +if ((a = 1) and (a = 2) and (a = 3)) then +``` + +这样就会导致始终按照`(factor)`规约,保证`expression`的产生。 + +--- + +**left node** + +这里指的是剩余的结点操作可以统一起来 + +```python +# expr : expr ADD term +# | expr SUBTRACT term +# | term +# term : term MUL factor +# | term kDIV factor +# | term DIV factor +# | term kMOD factor +# | factor +``` + +```python +else: + if len(expression_node.children) == 1: + return self.gen_quad_list_from_expression_node(expression_node.children[0]) + left_child, right_child = expression_node.children + left_val, right_val = self.gen_quad_list_from_expression_node(left_child), \ + self.gen_quad_list_from_expression_node(right_child) + + bin_op = type_to_bin_op[expression_node.type] + target = self.new_tmp_var + self._add_new_quad(bin_op, target, left_val, right_val) + return target +``` + +> 此处处理很基本,不再赘述。 + +--- + + + +## 5.6 Optimization + diff --git a/report/imgs/CG_00.png b/report/imgs/CG_00.png new file mode 100644 index 0000000..13d1fc7 Binary files /dev/null and b/report/imgs/CG_00.png differ diff --git a/yapc/CodeGenerator.py b/yapc/CodeGenerator.py index 7eb3af2..35ada64 100644 --- a/yapc/CodeGenerator.py +++ b/yapc/CodeGenerator.py @@ -69,6 +69,11 @@ def __init__(self, ast, symbol_table): self._next_tmp_var = 0 self._routine_stack = [] + def write_file(self, file_path): + out = open(file_path, 'w') + out.writelines([str(quad) + '\n' for quad in self._quad_list]) + out.close() + @property def abstract_syntax_tree(self): return self._ast @@ -134,7 +139,7 @@ def _traverse_ast_gen_code(self, root_node): children = root_node.children if root_node.type == 'assign_stmt': # ID ASSIGN expression - if len(children) == 2: # ID ASSIGN expression + if len(children) == 2: # maybe_expression_node, because it may have been a constant folding result id_, maybe_expression_node = children if not isinstance(maybe_expression_node, Node): diff --git a/yapc/parselog.txt b/yapc/parselog.txt index 5bff3bd..90a6c34 100644 --- a/yapc/parselog.txt +++ b/yapc/parselog.txt @@ -5,471 +5,791 @@ yacc.py: 445:Action : Shift and goto state 3 yacc.py: 410: yacc.py: 411:State : 3 - yacc.py: 435:Stack : kPROGRAM . LexToken(ID,'test_1',1,8) + yacc.py: 435:Stack : kPROGRAM . LexToken(ID,'if_statement',1,8) yacc.py: 445:Action : Shift and goto state 9 yacc.py: 410: yacc.py: 411:State : 9 - yacc.py: 435:Stack : kPROGRAM ID . LexToken(SEMICON,';',1,14) + yacc.py: 435:Stack : kPROGRAM ID . LexToken(SEMICON,';',1,20) yacc.py: 445:Action : Shift and goto state 21 yacc.py: 410: yacc.py: 411:State : 21 - yacc.py: 435:Stack : kPROGRAM ID SEMICON . LexToken(kTYPE,'type',2,16) - yacc.py: 471:Action : Reduce rule [program_head -> kPROGRAM ID SEMICON] with ['program','test_1',';'] and goto state 2 - yacc.py: 506:Result : ('test_1') + yacc.py: 435:Stack : kPROGRAM ID SEMICON . LexToken(kVAR,'var',2,22) + yacc.py: 471:Action : Reduce rule [program_head -> kPROGRAM ID SEMICON] with ['program','if_statement',';'] and goto state 2 + yacc.py: 506:Result : ('if_statement') yacc.py: 410: yacc.py: 411:State : 2 - yacc.py: 435:Stack : program_head . LexToken(kTYPE,'type',2,16) + yacc.py: 435:Stack : program_head . LexToken(kVAR,'var',2,22) yacc.py: 474:Action : Reduce rule [empty -> ] with [] and goto state 8 - yacc.py: 548:Result : (None) + yacc.py: 548:Result : (None) yacc.py: 410: yacc.py: 411:State : 8 - yacc.py: 435:Stack : program_head empty . LexToken(kTYPE,'type',2,16) + yacc.py: 435:Stack : program_head empty . LexToken(kVAR,'var',2,22) yacc.py: 471:Action : Reduce rule [const_part -> empty] with [None] and goto state 6 - yacc.py: 506:Result : (None) + yacc.py: 506:Result : (None) yacc.py: 410: yacc.py: 411:State : 6 - yacc.py: 435:Stack : program_head const_part . LexToken(kTYPE,'type',2,16) - yacc.py: 445:Action : Shift and goto state 15 + yacc.py: 435:Stack : program_head const_part . LexToken(kVAR,'var',2,22) + yacc.py: 474:Action : Reduce rule [empty -> ] with [] and goto state 16 + yacc.py: 548:Result : (None) yacc.py: 410: - yacc.py: 411:State : 15 - yacc.py: 435:Stack : program_head const_part kTYPE . LexToken(ID,'arr',3,25) - yacc.py: 445:Action : Shift and goto state 30 + yacc.py: 411:State : 16 + yacc.py: 435:Stack : program_head const_part empty . LexToken(kVAR,'var',2,22) + yacc.py: 471:Action : Reduce rule [type_part -> empty] with [None] and goto state 14 + yacc.py: 506:Result : (None) yacc.py: 410: - yacc.py: 411:State : 30 - yacc.py: 435:Stack : program_head const_part kTYPE ID . LexToken(EQUAL,'=',3,29) - yacc.py: 445:Action : Shift and goto state 72 - yacc.py: 410: - yacc.py: 411:State : 72 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL . LexToken(kARRAY,'array',3,31) - yacc.py: 445:Action : Shift and goto state 122 - yacc.py: 410: - yacc.py: 411:State : 122 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL kARRAY . LexToken(LB,'[',3,37) - yacc.py: 445:Action : Shift and goto state 175 - yacc.py: 410: - yacc.py: 411:State : 175 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL kARRAY LB . LexToken(INTEGER,50,3,38) - yacc.py: 445:Action : Shift and goto state 74 - yacc.py: 410: - yacc.py: 411:State : 74 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL kARRAY LB INTEGER . LexToken(RB,']',3,41) - yacc.py: 471:Action : Reduce rule [const_value -> INTEGER] with [50] and goto state 121 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 121 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL kARRAY LB const_value . LexToken(RB,']',3,41) - yacc.py: 580:Error : program_head const_part kTYPE ID EQUAL kARRAY LB const_value . LexToken(RB,']',3,41) - yacc.py: 410: - yacc.py: 411:State : 121 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL kARRAY LB const_value . error - yacc.py: 580:Error : program_head const_part kTYPE ID EQUAL kARRAY LB const_value . error - yacc.py: 410: - yacc.py: 411:State : 175 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL kARRAY LB . error - yacc.py: 580:Error : program_head const_part kTYPE ID EQUAL kARRAY LB . error - yacc.py: 410: - yacc.py: 411:State : 122 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL kARRAY . error - yacc.py: 580:Error : program_head const_part kTYPE ID EQUAL kARRAY . error - yacc.py: 410: - yacc.py: 411:State : 72 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL . error - yacc.py: 445:Action : Shift and goto state 115 - yacc.py: 410: - yacc.py: 411:State : 115 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL error . LexToken(RB,']',3,41) - yacc.py: 580:Error : program_head const_part kTYPE ID EQUAL error . LexToken(RB,']',3,41) - yacc.py: 410: - yacc.py: 411:State : 115 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL error . LexToken(kOF,'of',3,43) - yacc.py: 580:Error : program_head const_part kTYPE ID EQUAL error . LexToken(kOF,'of',3,43) - yacc.py: 410: - yacc.py: 411:State : 115 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL error . LexToken(SYS_TYPE,'integer',3,46) - yacc.py: 580:Error : program_head const_part kTYPE ID EQUAL error . LexToken(SYS_TYPE,'integer',3,46) - yacc.py: 410: - yacc.py: 411:State : 115 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL error . LexToken(SEMICON,';',3,53) - yacc.py: 445:Action : Shift and goto state 172 - yacc.py: 410: - yacc.py: 411:State : 172 - yacc.py: 435:Stack : program_head const_part kTYPE ID EQUAL error SEMICON . LexToken(ID,'MailingListRecord',4,58) - yacc.py: 471:Action : Reduce rule [type_definition -> ID EQUAL error SEMICON] with ['arr','=',,';'] and goto state 29 - yacc.py: 506:Result : (None) - yacc.py: 410: - yacc.py: 411:State : 29 - yacc.py: 435:Stack : program_head const_part kTYPE type_definition . LexToken(ID,'MailingListRecord',4,58) - yacc.py: 471:Action : Reduce rule [type_decl_list -> type_definition] with [None] and goto state 28 - yacc.py: 506:Result : (None) - yacc.py: 410: - yacc.py: 411:State : 28 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list . LexToken(ID,'MailingListRecord',4,58) - yacc.py: 445:Action : Shift and goto state 30 - yacc.py: 410: - yacc.py: 411:State : 30 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID . LexToken(EQUAL,'=',4,76) - yacc.py: 445:Action : Shift and goto state 72 - yacc.py: 410: - yacc.py: 411:State : 72 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL . LexToken(kRECORD,'record',4,78) - yacc.py: 445:Action : Shift and goto state 123 - yacc.py: 410: - yacc.py: 411:State : 123 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD . LexToken(ID,'FirstName',5,90) - yacc.py: 445:Action : Shift and goto state 70 - yacc.py: 410: - yacc.py: 411:State : 70 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD ID . LexToken(COLON,':',5,99) - yacc.py: 471:Action : Reduce rule [name_list -> ID] with ['FirstName'] and goto state 179 - yacc.py: 506:Result : ('FirstName') - yacc.py: 410: - yacc.py: 411:State : 179 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD name_list . LexToken(COLON,':',5,99) - yacc.py: 445:Action : Shift and goto state 235 - yacc.py: 410: - yacc.py: 411:State : 235 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD name_list COLON . LexToken(ID,'string',5,101) - yacc.py: 445:Action : Shift and goto state 113 - yacc.py: 410: - yacc.py: 411:State : 113 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD name_list COLON ID . LexToken(SEMICON,';',5,107) - yacc.py: 471:Action : Reduce rule [simple_type_decl -> ID] with ['string'] and goto state 116 - yacc.py: 506:Result : () + yacc.py: 411:State : 14 + yacc.py: 435:Stack : program_head const_part type_part . LexToken(kVAR,'var',2,22) + yacc.py: 445:Action : Shift and goto state 26 yacc.py: 410: - yacc.py: 411:State : 116 - yacc.py: 430:Defaulted state 116: Reduce using 22 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD name_list COLON simple_type_decl . LexToken(SEMICON,';',5,107) - yacc.py: 471:Action : Reduce rule [type_decl -> simple_type_decl] with [] and goto state 261 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 261 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD name_list COLON type_decl . LexToken(SEMICON,';',5,107) - yacc.py: 445:Action : Shift and goto state 272 - yacc.py: 410: - yacc.py: 411:State : 272 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD name_list COLON type_decl SEMICON . LexToken(ID,'LastName',6,114) - yacc.py: 471:Action : Reduce rule [field_decl -> name_list COLON type_decl SEMICON] with ['FirstName',':',,';'] and goto state 178 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 178 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl . LexToken(ID,'LastName',6,114) - yacc.py: 471:Action : Reduce rule [field_decl_list -> field_decl] with [] and goto state 176 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 176 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list . LexToken(ID,'LastName',6,114) + yacc.py: 411:State : 26 + yacc.py: 435:Stack : program_head const_part type_part kVAR . LexToken(ID,'x',2,26) yacc.py: 445:Action : Shift and goto state 70 yacc.py: 410: yacc.py: 411:State : 70 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list ID . LexToken(COLON,':',6,122) - yacc.py: 471:Action : Reduce rule [name_list -> ID] with ['LastName'] and goto state 179 - yacc.py: 506:Result : ('LastName') - yacc.py: 410: - yacc.py: 411:State : 179 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list . LexToken(COLON,':',6,122) - yacc.py: 445:Action : Shift and goto state 235 + yacc.py: 435:Stack : program_head const_part type_part kVAR ID . LexToken(COMMA,',',2,27) + yacc.py: 471:Action : Reduce rule [name_list -> ID] with ['x'] and goto state 68 + yacc.py: 506:Result : ('x') yacc.py: 410: - yacc.py: 411:State : 235 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON . LexToken(ID,'string',6,124) - yacc.py: 445:Action : Shift and goto state 113 + yacc.py: 411:State : 68 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list . LexToken(COMMA,',',2,27) + yacc.py: 445:Action : Shift and goto state 111 yacc.py: 410: - yacc.py: 411:State : 113 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON ID . LexToken(SEMICON,';',6,130) - yacc.py: 471:Action : Reduce rule [simple_type_decl -> ID] with ['string'] and goto state 116 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 116 - yacc.py: 430:Defaulted state 116: Reduce using 22 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON simple_type_decl . LexToken(SEMICON,';',6,130) - yacc.py: 471:Action : Reduce rule [type_decl -> simple_type_decl] with [] and goto state 261 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 261 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl . LexToken(SEMICON,';',6,130) - yacc.py: 445:Action : Shift and goto state 272 - yacc.py: 410: - yacc.py: 411:State : 272 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl SEMICON . LexToken(ID,'Address',7,137) - yacc.py: 471:Action : Reduce rule [field_decl -> name_list COLON type_decl SEMICON] with ['LastName',':',,';'] and goto state 231 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 231 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list field_decl . LexToken(ID,'Address',7,137) - yacc.py: 471:Action : Reduce rule [field_decl_list -> field_decl_list field_decl] with [,] and goto state 176 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 176 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list . LexToken(ID,'Address',7,137) - yacc.py: 445:Action : Shift and goto state 70 + yacc.py: 411:State : 111 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list COMMA . LexToken(ID,'y',2,29) + yacc.py: 445:Action : Shift and goto state 170 yacc.py: 410: - yacc.py: 411:State : 70 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list ID . LexToken(COLON,':',7,144) - yacc.py: 471:Action : Reduce rule [name_list -> ID] with ['Address'] and goto state 179 - yacc.py: 506:Result : ('Address') + yacc.py: 411:State : 170 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list COMMA ID . LexToken(COLON,':',2,30) + yacc.py: 471:Action : Reduce rule [name_list -> name_list COMMA ID] with ['x',',','y'] and goto state 68 + yacc.py: 506:Result : () yacc.py: 410: - yacc.py: 411:State : 179 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list . LexToken(COLON,':',7,144) - yacc.py: 445:Action : Shift and goto state 235 + yacc.py: 411:State : 68 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list . LexToken(COLON,':',2,30) + yacc.py: 445:Action : Shift and goto state 110 yacc.py: 410: - yacc.py: 411:State : 235 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON . LexToken(ID,'string',7,146) - yacc.py: 445:Action : Shift and goto state 113 + yacc.py: 411:State : 110 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list COLON . LexToken(SYS_TYPE,'integer',2,32) + yacc.py: 445:Action : Shift and goto state 119 yacc.py: 410: - yacc.py: 411:State : 113 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON ID . LexToken(SEMICON,';',7,152) - yacc.py: 471:Action : Reduce rule [simple_type_decl -> ID] with ['string'] and goto state 116 - yacc.py: 506:Result : () + yacc.py: 411:State : 119 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list COLON SYS_TYPE . LexToken(SEMICON,';',2,39) + yacc.py: 471:Action : Reduce rule [simple_type_decl -> SYS_TYPE] with ['integer'] and goto state 116 + yacc.py: 506:Result : () yacc.py: 410: yacc.py: 411:State : 116 yacc.py: 430:Defaulted state 116: Reduce using 22 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON simple_type_decl . LexToken(SEMICON,';',7,152) - yacc.py: 471:Action : Reduce rule [type_decl -> simple_type_decl] with [] and goto state 261 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 261 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl . LexToken(SEMICON,';',7,152) - yacc.py: 445:Action : Shift and goto state 272 - yacc.py: 410: - yacc.py: 411:State : 272 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl SEMICON . LexToken(ID,'City',8,159) - yacc.py: 471:Action : Reduce rule [field_decl -> name_list COLON type_decl SEMICON] with ['Address',':',,';'] and goto state 231 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 231 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list field_decl . LexToken(ID,'City',8,159) - yacc.py: 471:Action : Reduce rule [field_decl_list -> field_decl_list field_decl] with [,] and goto state 176 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 176 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list . LexToken(ID,'City',8,159) - yacc.py: 445:Action : Shift and goto state 70 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list COLON simple_type_decl . LexToken(SEMICON,';',2,39) + yacc.py: 471:Action : Reduce rule [type_decl -> simple_type_decl] with [] and goto state 169 + yacc.py: 506:Result : () yacc.py: 410: - yacc.py: 411:State : 70 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list ID . LexToken(COLON,':',8,163) - yacc.py: 471:Action : Reduce rule [name_list -> ID] with ['City'] and goto state 179 - yacc.py: 506:Result : ('City') + yacc.py: 411:State : 169 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list COLON type_decl . LexToken(SEMICON,';',2,39) + yacc.py: 445:Action : Shift and goto state 226 yacc.py: 410: - yacc.py: 411:State : 179 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list . LexToken(COLON,':',8,163) - yacc.py: 445:Action : Shift and goto state 235 + yacc.py: 411:State : 226 + yacc.py: 435:Stack : program_head const_part type_part kVAR name_list COLON type_decl SEMICON . LexToken(kBEGIN,'begin',3,41) + yacc.py: 471:Action : Reduce rule [var_decl -> name_list COLON type_decl SEMICON] with [,':',,';'] and goto state 67 + yacc.py: 506:Result : () yacc.py: 410: - yacc.py: 411:State : 235 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON . LexToken(ID,'string',8,165) - yacc.py: 445:Action : Shift and goto state 113 + yacc.py: 411:State : 67 + yacc.py: 435:Stack : program_head const_part type_part kVAR var_decl . LexToken(kBEGIN,'begin',3,41) + yacc.py: 471:Action : Reduce rule [var_decl_list -> var_decl] with [] and goto state 66 + yacc.py: 506:Result : () yacc.py: 410: - yacc.py: 411:State : 113 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON ID . LexToken(SEMICON,';',8,171) - yacc.py: 471:Action : Reduce rule [simple_type_decl -> ID] with ['string'] and goto state 116 - yacc.py: 506:Result : () + yacc.py: 411:State : 66 + yacc.py: 435:Stack : program_head const_part type_part kVAR var_decl_list . LexToken(kBEGIN,'begin',3,41) + yacc.py: 471:Action : Reduce rule [var_part -> kVAR var_decl_list] with ['var',] and goto state 25 + yacc.py: 506:Result : () yacc.py: 410: - yacc.py: 411:State : 116 - yacc.py: 430:Defaulted state 116: Reduce using 22 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON simple_type_decl . LexToken(SEMICON,';',8,171) - yacc.py: 471:Action : Reduce rule [type_decl -> simple_type_decl] with [] and goto state 261 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 261 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl . LexToken(SEMICON,';',8,171) - yacc.py: 445:Action : Shift and goto state 272 - yacc.py: 410: - yacc.py: 411:State : 272 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl SEMICON . LexToken(ID,'State',9,178) - yacc.py: 471:Action : Reduce rule [field_decl -> name_list COLON type_decl SEMICON] with ['City',':',,';'] and goto state 231 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 231 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list field_decl . LexToken(ID,'State',9,178) - yacc.py: 471:Action : Reduce rule [field_decl_list -> field_decl_list field_decl] with [,] and goto state 176 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 176 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list . LexToken(ID,'State',9,178) - yacc.py: 445:Action : Shift and goto state 70 + yacc.py: 411:State : 25 + yacc.py: 435:Stack : program_head const_part type_part var_part . LexToken(kBEGIN,'begin',3,41) + yacc.py: 474:Action : Reduce rule [empty -> ] with [] and goto state 61 + yacc.py: 548:Result : (None) yacc.py: 410: - yacc.py: 411:State : 70 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list ID . LexToken(COLON,':',9,183) - yacc.py: 471:Action : Reduce rule [name_list -> ID] with ['State'] and goto state 179 - yacc.py: 506:Result : ('State') + yacc.py: 411:State : 61 + yacc.py: 435:Stack : program_head const_part type_part var_part empty . LexToken(kBEGIN,'begin',3,41) + yacc.py: 471:Action : Reduce rule [routine_part -> empty] with [None] and goto state 58 + yacc.py: 506:Result : (None) yacc.py: 410: - yacc.py: 411:State : 179 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list . LexToken(COLON,':',9,183) - yacc.py: 445:Action : Shift and goto state 235 + yacc.py: 411:State : 58 + yacc.py: 435:Stack : program_head const_part type_part var_part routine_part . LexToken(kBEGIN,'begin',3,41) + yacc.py: 471:Action : Reduce rule [routine_head -> const_part type_part var_part routine_part] with [None,None,,None] and goto state 5 + yacc.py: 506:Result : () yacc.py: 410: - yacc.py: 411:State : 235 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON . LexToken(ID,'string',9,185) - yacc.py: 445:Action : Shift and goto state 113 + yacc.py: 411:State : 5 + yacc.py: 435:Stack : program_head routine_head . LexToken(kBEGIN,'begin',3,41) + yacc.py: 445:Action : Shift and goto state 13 yacc.py: 410: - yacc.py: 411:State : 113 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON ID . LexToken(SEMICON,';',9,191) - yacc.py: 471:Action : Reduce rule [simple_type_decl -> ID] with ['string'] and goto state 116 - yacc.py: 506:Result : () + yacc.py: 411:State : 13 + yacc.py: 435:Stack : program_head routine_head kBEGIN . LexToken(ID,'x',4,48) + yacc.py: 474:Action : Reduce rule [empty -> ] with [] and goto state 24 + yacc.py: 548:Result : (None) yacc.py: 410: - yacc.py: 411:State : 116 - yacc.py: 430:Defaulted state 116: Reduce using 22 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON simple_type_decl . LexToken(SEMICON,';',9,191) - yacc.py: 471:Action : Reduce rule [type_decl -> simple_type_decl] with [] and goto state 261 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 261 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl . LexToken(SEMICON,';',9,191) - yacc.py: 445:Action : Shift and goto state 272 - yacc.py: 410: - yacc.py: 411:State : 272 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl SEMICON . LexToken(ID,'Zip',10,198) - yacc.py: 471:Action : Reduce rule [field_decl -> name_list COLON type_decl SEMICON] with ['State',':',,';'] and goto state 231 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 231 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list field_decl . LexToken(ID,'Zip',10,198) - yacc.py: 471:Action : Reduce rule [field_decl_list -> field_decl_list field_decl] with [,] and goto state 176 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 176 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list . LexToken(ID,'Zip',10,198) - yacc.py: 445:Action : Shift and goto state 70 + yacc.py: 411:State : 24 + yacc.py: 435:Stack : program_head routine_head kBEGIN empty . LexToken(ID,'x',4,48) + yacc.py: 471:Action : Reduce rule [stmt_list -> empty] with [None] and goto state 22 + yacc.py: 506:Result : (None) yacc.py: 410: - yacc.py: 411:State : 70 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list ID . LexToken(COLON,':',10,201) - yacc.py: 471:Action : Reduce rule [name_list -> ID] with ['Zip'] and goto state 179 - yacc.py: 506:Result : ('Zip') + yacc.py: 411:State : 22 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list . LexToken(ID,'x',4,48) + yacc.py: 445:Action : Shift and goto state 48 yacc.py: 410: - yacc.py: 411:State : 179 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list . LexToken(COLON,':',10,201) - yacc.py: 445:Action : Shift and goto state 235 + yacc.py: 411:State : 48 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID . LexToken(ASSIGN,':=',4,50) + yacc.py: 445:Action : Shift and goto state 83 yacc.py: 410: - yacc.py: 411:State : 235 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON . LexToken(ID,'Integer',10,203) - yacc.py: 445:Action : Shift and goto state 113 + yacc.py: 411:State : 83 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN . LexToken(INTEGER,2,4,53) + yacc.py: 445:Action : Shift and goto state 74 yacc.py: 410: - yacc.py: 411:State : 113 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON ID . LexToken(SEMICON,';',10,210) - yacc.py: 471:Action : Reduce rule [simple_type_decl -> ID] with ['Integer'] and goto state 116 - yacc.py: 506:Result : () + yacc.py: 411:State : 74 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN INTEGER . LexToken(SEMICON,';',4,54) + yacc.py: 471:Action : Reduce rule [const_value -> INTEGER] with [2] and goto state 96 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 96 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN const_value . LexToken(SEMICON,';',4,54) + yacc.py: 471:Action : Reduce rule [factor -> const_value] with [] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN factor . LexToken(SEMICON,';',4,54) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 90 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN term . LexToken(SEMICON,';',4,54) + yacc.py: 471:Action : Reduce rule [expr -> term] with [] and goto state 89 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN expr . LexToken(SEMICON,';',4,54) + yacc.py: 471:Action : Reduce rule [expression -> expr] with [] and goto state 127 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 127 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN expression . LexToken(SEMICON,';',4,54) + yacc.py: 471:Action : Reduce rule [assign_stmt -> ID ASSIGN expression] with ['x',':=',] and goto state 39 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 39 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list assign_stmt . LexToken(SEMICON,';',4,54) + yacc.py: 471:Action : Reduce rule [non_label_stmt -> assign_stmt] with [] and goto state 38 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 38 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list non_label_stmt . LexToken(SEMICON,';',4,54) + yacc.py: 471:Action : Reduce rule [stmt -> non_label_stmt] with [] and goto state 35 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 35 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list stmt . LexToken(SEMICON,';',4,54) + yacc.py: 445:Action : Shift and goto state 79 + yacc.py: 410: + yacc.py: 411:State : 79 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list stmt SEMICON . LexToken(ID,'y',5,60) + yacc.py: 471:Action : Reduce rule [stmt_list -> stmt_list stmt SEMICON] with [None,,';'] and goto state 22 + yacc.py: 506:Result : () yacc.py: 410: - yacc.py: 411:State : 116 - yacc.py: 430:Defaulted state 116: Reduce using 22 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON simple_type_decl . LexToken(SEMICON,';',10,210) - yacc.py: 471:Action : Reduce rule [type_decl -> simple_type_decl] with [] and goto state 261 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 261 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl . LexToken(SEMICON,';',10,210) - yacc.py: 445:Action : Shift and goto state 272 - yacc.py: 410: - yacc.py: 411:State : 272 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list name_list COLON type_decl SEMICON . LexToken(kEND,'end',11,215) - yacc.py: 471:Action : Reduce rule [field_decl -> name_list COLON type_decl SEMICON] with ['Zip',':',,';'] and goto state 231 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 231 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list field_decl . LexToken(kEND,'end',11,215) - yacc.py: 471:Action : Reduce rule [field_decl_list -> field_decl_list field_decl] with [,] and goto state 176 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 176 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list . LexToken(kEND,'end',11,215) - yacc.py: 445:Action : Shift and goto state 230 - yacc.py: 410: - yacc.py: 411:State : 230 - yacc.py: 430:Defaulted state 230: Reduce using 30 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL kRECORD field_decl_list kEND . None - yacc.py: 471:Action : Reduce rule [record_type_decl -> kRECORD field_decl_list kEND] with ['record',,'end'] and goto state 118 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 118 - yacc.py: 430:Defaulted state 118: Reduce using 24 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL record_type_decl . None - yacc.py: 471:Action : Reduce rule [type_decl -> record_type_decl] with [] and goto state 114 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 114 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL type_decl . LexToken(SEMICON,';',11,218) - yacc.py: 445:Action : Shift and goto state 171 - yacc.py: 410: - yacc.py: 411:State : 171 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list ID EQUAL type_decl SEMICON . LexToken(kBEGIN,'begin',13,221) - yacc.py: 471:Action : Reduce rule [type_definition -> ID EQUAL type_decl SEMICON] with [,'=',,';'] and goto state 71 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 71 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list type_definition . LexToken(kBEGIN,'begin',13,221) - yacc.py: 471:Action : Reduce rule [type_decl_list -> type_decl_list type_definition] with [None,] and goto state 28 - yacc.py: 506:Result : () - yacc.py: 410: - yacc.py: 411:State : 28 - yacc.py: 435:Stack : program_head const_part kTYPE type_decl_list . LexToken(kBEGIN,'begin',13,221) - yacc.py: 471:Action : Reduce rule [type_part -> kTYPE type_decl_list] with ['type',] and goto state 14 - yacc.py: 506:Result : () + yacc.py: 411:State : 22 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list . LexToken(ID,'y',5,60) + yacc.py: 445:Action : Shift and goto state 48 yacc.py: 410: - yacc.py: 411:State : 14 - yacc.py: 435:Stack : program_head const_part type_part . LexToken(kBEGIN,'begin',13,221) - yacc.py: 474:Action : Reduce rule [empty -> ] with [] and goto state 27 - yacc.py: 548:Result : (None) + yacc.py: 411:State : 48 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID . LexToken(ASSIGN,':=',5,62) + yacc.py: 445:Action : Shift and goto state 83 yacc.py: 410: - yacc.py: 411:State : 27 - yacc.py: 435:Stack : program_head const_part type_part empty . LexToken(kBEGIN,'begin',13,221) - yacc.py: 471:Action : Reduce rule [var_part -> empty] with [None] and goto state 25 - yacc.py: 506:Result : (None) + yacc.py: 411:State : 83 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN . LexToken(INTEGER,15,5,65) + yacc.py: 445:Action : Shift and goto state 74 yacc.py: 410: - yacc.py: 411:State : 25 - yacc.py: 435:Stack : program_head const_part type_part var_part . LexToken(kBEGIN,'begin',13,221) - yacc.py: 474:Action : Reduce rule [empty -> ] with [] and goto state 61 - yacc.py: 548:Result : (None) + yacc.py: 411:State : 74 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN INTEGER . LexToken(SEMICON,';',5,67) + yacc.py: 471:Action : Reduce rule [const_value -> INTEGER] with [15] and goto state 96 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 96 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN const_value . LexToken(SEMICON,';',5,67) + yacc.py: 471:Action : Reduce rule [factor -> const_value] with [] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN factor . LexToken(SEMICON,';',5,67) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 90 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN term . LexToken(SEMICON,';',5,67) + yacc.py: 471:Action : Reduce rule [expr -> term] with [] and goto state 89 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN expr . LexToken(SEMICON,';',5,67) + yacc.py: 471:Action : Reduce rule [expression -> expr] with [] and goto state 127 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 127 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list ID ASSIGN expression . LexToken(SEMICON,';',5,67) + yacc.py: 471:Action : Reduce rule [assign_stmt -> ID ASSIGN expression] with ['y',':=',] and goto state 39 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 39 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list assign_stmt . LexToken(SEMICON,';',5,67) + yacc.py: 471:Action : Reduce rule [non_label_stmt -> assign_stmt] with [] and goto state 38 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 38 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list non_label_stmt . LexToken(SEMICON,';',5,67) + yacc.py: 471:Action : Reduce rule [stmt -> non_label_stmt] with [] and goto state 35 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 35 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list stmt . LexToken(SEMICON,';',5,67) + yacc.py: 445:Action : Shift and goto state 79 + yacc.py: 410: + yacc.py: 411:State : 79 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list stmt SEMICON . LexToken(kIF,'if',6,70) + yacc.py: 471:Action : Reduce rule [stmt_list -> stmt_list stmt SEMICON] with [,,';'] and goto state 22 + yacc.py: 506:Result : () yacc.py: 410: - yacc.py: 411:State : 61 - yacc.py: 435:Stack : program_head const_part type_part var_part empty . LexToken(kBEGIN,'begin',13,221) - yacc.py: 471:Action : Reduce rule [routine_part -> empty] with [None] and goto state 58 - yacc.py: 506:Result : (None) + yacc.py: 411:State : 22 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list . LexToken(kIF,'if',6,70) + yacc.py: 445:Action : Shift and goto state 51 + yacc.py: 410: + yacc.py: 411:State : 51 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF . LexToken(LP,'(',6,73) + yacc.py: 445:Action : Shift and goto state 95 + yacc.py: 410: + yacc.py: 411:State : 95 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP . LexToken(LP,'(',6,75) + yacc.py: 445:Action : Shift and goto state 95 + yacc.py: 410: + yacc.py: 411:State : 95 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP . LexToken(ID,'x',6,76) + yacc.py: 445:Action : Shift and goto state 94 + yacc.py: 410: + yacc.py: 411:State : 94 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP ID . LexToken(LT,'<',6,78) + yacc.py: 471:Action : Reduce rule [factor -> ID] with ['x'] and goto state 92 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP factor . LexToken(LT,'<',6,78) + yacc.py: 471:Action : Reduce rule [term -> factor] with ['x'] and goto state 90 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP term . LexToken(LT,'<',6,78) + yacc.py: 471:Action : Reduce rule [expr -> term] with ['x'] and goto state 89 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expr . LexToken(LT,'<',6,78) + yacc.py: 471:Action : Reduce rule [expression -> expr] with ['x'] and goto state 154 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 154 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expression . LexToken(LT,'<',6,78) + yacc.py: 445:Action : Shift and goto state 138 + yacc.py: 410: + yacc.py: 411:State : 138 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expression LT . LexToken(ID,'y',6,80) + yacc.py: 445:Action : Shift and goto state 94 + yacc.py: 410: + yacc.py: 411:State : 94 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expression LT ID . LexToken(RP,')',6,81) + yacc.py: 471:Action : Reduce rule [factor -> ID] with ['y'] and goto state 92 + yacc.py: 506:Result : ('y') + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expression LT factor . LexToken(RP,')',6,81) + yacc.py: 471:Action : Reduce rule [term -> factor] with ['y'] and goto state 90 + yacc.py: 506:Result : ('y') + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expression LT term . LexToken(RP,')',6,81) + yacc.py: 471:Action : Reduce rule [expr -> term] with ['y'] and goto state 191 + yacc.py: 506:Result : ('y') + yacc.py: 410: + yacc.py: 411:State : 191 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expression LT expr . LexToken(RP,')',6,81) + yacc.py: 471:Action : Reduce rule [expression -> expression LT expr] with [,'<','y'] and goto state 154 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 154 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expression . LexToken(RP,')',6,81) + yacc.py: 445:Action : Shift and goto state 206 + yacc.py: 410: + yacc.py: 411:State : 206 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP LP expression RP . LexToken(kAND,'and',6,83) + yacc.py: 471:Action : Reduce rule [factor -> LP expression RP] with ['(',,')'] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP factor . LexToken(kAND,'and',6,83) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 90 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term . LexToken(kAND,'and',6,83) + yacc.py: 445:Action : Shift and goto state 148 + yacc.py: 410: + yacc.py: 411:State : 148 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND . LexToken(LP,'(',6,87) + yacc.py: 445:Action : Shift and goto state 95 + yacc.py: 410: + yacc.py: 411:State : 95 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP . LexToken(ID,'x',6,88) + yacc.py: 445:Action : Shift and goto state 94 + yacc.py: 410: + yacc.py: 411:State : 94 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP ID . LexToken(GT,'>',6,90) + yacc.py: 471:Action : Reduce rule [factor -> ID] with ['x'] and goto state 92 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP factor . LexToken(GT,'>',6,90) + yacc.py: 471:Action : Reduce rule [term -> factor] with ['x'] and goto state 90 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP term . LexToken(GT,'>',6,90) + yacc.py: 471:Action : Reduce rule [expr -> term] with ['x'] and goto state 89 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expr . LexToken(GT,'>',6,90) + yacc.py: 471:Action : Reduce rule [expression -> expr] with ['x'] and goto state 154 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 154 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression . LexToken(GT,'>',6,90) + yacc.py: 445:Action : Shift and goto state 136 + yacc.py: 410: + yacc.py: 411:State : 136 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT . LexToken(ID,'y',6,92) + yacc.py: 445:Action : Shift and goto state 94 + yacc.py: 410: + yacc.py: 411:State : 94 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT ID . LexToken(SUBTRACT,'-',6,94) + yacc.py: 471:Action : Reduce rule [factor -> ID] with ['y'] and goto state 92 + yacc.py: 506:Result : ('y') + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT factor . LexToken(SUBTRACT,'-',6,94) + yacc.py: 471:Action : Reduce rule [term -> factor] with ['y'] and goto state 90 + yacc.py: 506:Result : ('y') + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT term . LexToken(SUBTRACT,'-',6,94) + yacc.py: 471:Action : Reduce rule [expr -> term] with ['y'] and goto state 189 + yacc.py: 506:Result : ('y') + yacc.py: 410: + yacc.py: 411:State : 189 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT expr . LexToken(SUBTRACT,'-',6,94) + yacc.py: 445:Action : Shift and goto state 142 + yacc.py: 410: + yacc.py: 411:State : 142 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT expr SUBTRACT . LexToken(INTEGER,3,6,96) + yacc.py: 445:Action : Shift and goto state 74 yacc.py: 410: - yacc.py: 411:State : 58 - yacc.py: 435:Stack : program_head const_part type_part var_part routine_part . LexToken(kBEGIN,'begin',13,221) - yacc.py: 471:Action : Reduce rule [routine_head -> const_part type_part var_part routine_part] with [None,,None,None] and goto state 5 - yacc.py: 506:Result : () + yacc.py: 411:State : 74 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT expr SUBTRACT INTEGER . LexToken(RP,')',6,97) + yacc.py: 471:Action : Reduce rule [const_value -> INTEGER] with [3] and goto state 96 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 96 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT expr SUBTRACT const_value . LexToken(RP,')',6,97) + yacc.py: 471:Action : Reduce rule [factor -> const_value] with [] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT expr SUBTRACT factor . LexToken(RP,')',6,97) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 195 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 195 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT expr SUBTRACT term . LexToken(RP,')',6,97) + yacc.py: 471:Action : Reduce rule [expr -> expr SUBTRACT term] with ['y','-',] and goto state 189 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 189 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression GT expr . LexToken(RP,')',6,97) + yacc.py: 471:Action : Reduce rule [expression -> expression GT expr] with [,'>',] and goto state 154 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 154 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression . LexToken(RP,')',6,97) + yacc.py: 445:Action : Shift and goto state 206 + yacc.py: 410: + yacc.py: 411:State : 206 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND LP expression RP . LexToken(kOR,'or',6,99) + yacc.py: 471:Action : Reduce rule [factor -> LP expression RP] with ['(',,')'] and goto state 201 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 201 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term kAND factor . LexToken(kOR,'or',6,99) + yacc.py: 471:Action : Reduce rule [term -> term kAND factor] with [,'and',] and goto state 90 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP term . LexToken(kOR,'or',6,99) + yacc.py: 471:Action : Reduce rule [expr -> term] with [] and goto state 89 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr . LexToken(kOR,'or',6,99) + yacc.py: 445:Action : Shift and goto state 143 + yacc.py: 410: + yacc.py: 411:State : 143 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR . LexToken(LP,'(',6,102) + yacc.py: 445:Action : Shift and goto state 95 + yacc.py: 410: + yacc.py: 411:State : 95 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP . LexToken(ID,'x',6,103) + yacc.py: 445:Action : Shift and goto state 94 + yacc.py: 410: + yacc.py: 411:State : 94 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP ID . LexToken(SUBTRACT,'-',6,105) + yacc.py: 471:Action : Reduce rule [factor -> ID] with ['x'] and goto state 92 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP factor . LexToken(SUBTRACT,'-',6,105) + yacc.py: 471:Action : Reduce rule [term -> factor] with ['x'] and goto state 90 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP term . LexToken(SUBTRACT,'-',6,105) + yacc.py: 471:Action : Reduce rule [expr -> term] with ['x'] and goto state 89 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expr . LexToken(SUBTRACT,'-',6,105) + yacc.py: 445:Action : Shift and goto state 142 + yacc.py: 410: + yacc.py: 411:State : 142 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expr SUBTRACT . LexToken(ID,'y',6,107) + yacc.py: 445:Action : Shift and goto state 94 + yacc.py: 410: + yacc.py: 411:State : 94 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expr SUBTRACT ID . LexToken(GE,'>=',6,109) + yacc.py: 471:Action : Reduce rule [factor -> ID] with ['y'] and goto state 92 + yacc.py: 506:Result : ('y') + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expr SUBTRACT factor . LexToken(GE,'>=',6,109) + yacc.py: 471:Action : Reduce rule [term -> factor] with ['y'] and goto state 195 + yacc.py: 506:Result : ('y') + yacc.py: 410: + yacc.py: 411:State : 195 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expr SUBTRACT term . LexToken(GE,'>=',6,109) + yacc.py: 471:Action : Reduce rule [expr -> expr SUBTRACT term] with ['x','-','y'] and goto state 89 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expr . LexToken(GE,'>=',6,109) + yacc.py: 471:Action : Reduce rule [expression -> expr] with [] and goto state 154 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 154 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression . LexToken(GE,'>=',6,109) + yacc.py: 445:Action : Shift and goto state 135 + yacc.py: 410: + yacc.py: 411:State : 135 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression GE . LexToken(INTEGER,5,6,112) + yacc.py: 445:Action : Shift and goto state 74 yacc.py: 410: - yacc.py: 411:State : 5 - yacc.py: 435:Stack : program_head routine_head . LexToken(kBEGIN,'begin',13,221) - yacc.py: 445:Action : Shift and goto state 13 + yacc.py: 411:State : 74 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression GE INTEGER . LexToken(RP,')',6,113) + yacc.py: 471:Action : Reduce rule [const_value -> INTEGER] with [5] and goto state 96 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 96 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression GE const_value . LexToken(RP,')',6,113) + yacc.py: 471:Action : Reduce rule [factor -> const_value] with [] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression GE factor . LexToken(RP,')',6,113) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 90 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression GE term . LexToken(RP,')',6,113) + yacc.py: 471:Action : Reduce rule [expr -> term] with [] and goto state 188 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 188 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression GE expr . LexToken(RP,')',6,113) + yacc.py: 471:Action : Reduce rule [expression -> expression GE expr] with [,'>=',] and goto state 154 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 154 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression . LexToken(RP,')',6,113) + yacc.py: 445:Action : Shift and goto state 206 + yacc.py: 410: + yacc.py: 411:State : 206 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR LP expression RP . LexToken(RP,')',6,114) + yacc.py: 471:Action : Reduce rule [factor -> LP expression RP] with ['(',,')'] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR factor . LexToken(RP,')',6,114) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 196 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 196 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr kOR term . LexToken(RP,')',6,114) + yacc.py: 471:Action : Reduce rule [expr -> expr kOR term] with [,'or',] and goto state 89 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expr . LexToken(RP,')',6,114) + yacc.py: 471:Action : Reduce rule [expression -> expr] with [] and goto state 154 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 154 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expression . LexToken(RP,')',6,114) + yacc.py: 445:Action : Shift and goto state 206 + yacc.py: 410: + yacc.py: 411:State : 206 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF LP expression RP . LexToken(kTHEN,'then',6,116) + yacc.py: 471:Action : Reduce rule [factor -> LP expression RP] with ['(',,')'] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF factor . LexToken(kTHEN,'then',6,116) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 90 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF term . LexToken(kTHEN,'then',6,116) + yacc.py: 471:Action : Reduce rule [expr -> term] with [] and goto state 89 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expr . LexToken(kTHEN,'then',6,116) + yacc.py: 471:Action : Reduce rule [expression -> expr] with [] and goto state 88 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 88 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression . LexToken(kTHEN,'then',6,116) + yacc.py: 445:Action : Shift and goto state 134 + yacc.py: 410: + yacc.py: 411:State : 134 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN . LexToken(ID,'x',7,123) + yacc.py: 445:Action : Shift and goto state 48 + yacc.py: 410: + yacc.py: 411:State : 48 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID . LexToken(ASSIGN,':=',7,125) + yacc.py: 445:Action : Shift and goto state 83 + yacc.py: 410: + yacc.py: 411:State : 83 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN . LexToken(ID,'x',7,128) + yacc.py: 445:Action : Shift and goto state 94 + yacc.py: 410: + yacc.py: 411:State : 94 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN ID . LexToken(ADD,'+',7,130) + yacc.py: 471:Action : Reduce rule [factor -> ID] with ['x'] and goto state 92 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN factor . LexToken(ADD,'+',7,130) + yacc.py: 471:Action : Reduce rule [term -> factor] with ['x'] and goto state 90 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN term . LexToken(ADD,'+',7,130) + yacc.py: 471:Action : Reduce rule [expr -> term] with ['x'] and goto state 89 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN expr . LexToken(ADD,'+',7,130) + yacc.py: 445:Action : Shift and goto state 141 + yacc.py: 410: + yacc.py: 411:State : 141 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN expr ADD . LexToken(INTEGER,1,7,132) + yacc.py: 445:Action : Shift and goto state 74 yacc.py: 410: - yacc.py: 411:State : 13 - yacc.py: 435:Stack : program_head routine_head kBEGIN . LexToken(kEND,'end',15,228) - yacc.py: 474:Action : Reduce rule [empty -> ] with [] and goto state 24 - yacc.py: 548:Result : (None) + yacc.py: 411:State : 74 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN expr ADD INTEGER . LexToken(kELSE,'else',8,138) + yacc.py: 471:Action : Reduce rule [const_value -> INTEGER] with [1] and goto state 96 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 96 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN expr ADD const_value . LexToken(kELSE,'else',8,138) + yacc.py: 471:Action : Reduce rule [factor -> const_value] with [] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN expr ADD factor . LexToken(kELSE,'else',8,138) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 194 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 194 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN expr ADD term . LexToken(kELSE,'else',8,138) + yacc.py: 471:Action : Reduce rule [expr -> expr ADD term] with ['x','+',] and goto state 89 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN expr . LexToken(kELSE,'else',8,138) + yacc.py: 471:Action : Reduce rule [expression -> expr] with [] and goto state 127 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 127 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN ID ASSIGN expression . LexToken(kELSE,'else',8,138) + yacc.py: 471:Action : Reduce rule [assign_stmt -> ID ASSIGN expression] with ['x',':=',] and goto state 39 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 39 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN assign_stmt . LexToken(kELSE,'else',8,138) + yacc.py: 471:Action : Reduce rule [non_label_stmt -> assign_stmt] with [] and goto state 38 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 38 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN non_label_stmt . LexToken(kELSE,'else',8,138) + yacc.py: 471:Action : Reduce rule [stmt -> non_label_stmt] with [] and goto state 187 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 187 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt . LexToken(kELSE,'else',8,138) + yacc.py: 445:Action : Shift and goto state 241 + yacc.py: 410: + yacc.py: 411:State : 241 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE . LexToken(ID,'x',8,143) + yacc.py: 445:Action : Shift and goto state 48 + yacc.py: 410: + yacc.py: 411:State : 48 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID . LexToken(ASSIGN,':=',8,145) + yacc.py: 445:Action : Shift and goto state 83 + yacc.py: 410: + yacc.py: 411:State : 83 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN . LexToken(ID,'x',8,148) + yacc.py: 445:Action : Shift and goto state 94 + yacc.py: 410: + yacc.py: 411:State : 94 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN ID . LexToken(SUBTRACT,'-',8,150) + yacc.py: 471:Action : Reduce rule [factor -> ID] with ['x'] and goto state 92 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN factor . LexToken(SUBTRACT,'-',8,150) + yacc.py: 471:Action : Reduce rule [term -> factor] with ['x'] and goto state 90 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 90 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN term . LexToken(SUBTRACT,'-',8,150) + yacc.py: 471:Action : Reduce rule [expr -> term] with ['x'] and goto state 89 + yacc.py: 506:Result : ('x') + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN expr . LexToken(SUBTRACT,'-',8,150) + yacc.py: 445:Action : Shift and goto state 142 + yacc.py: 410: + yacc.py: 411:State : 142 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN expr SUBTRACT . LexToken(INTEGER,1,8,152) + yacc.py: 445:Action : Shift and goto state 74 yacc.py: 410: - yacc.py: 411:State : 24 - yacc.py: 435:Stack : program_head routine_head kBEGIN empty . LexToken(kEND,'end',15,228) - yacc.py: 471:Action : Reduce rule [stmt_list -> empty] with [None] and goto state 22 - yacc.py: 506:Result : (None) + yacc.py: 411:State : 74 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN expr SUBTRACT INTEGER . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [const_value -> INTEGER] with [1] and goto state 96 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 96 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN expr SUBTRACT const_value . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [factor -> const_value] with [] and goto state 92 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 92 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN expr SUBTRACT factor . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [term -> factor] with [] and goto state 195 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 195 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN expr SUBTRACT term . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [expr -> expr SUBTRACT term] with ['x','-',] and goto state 89 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 89 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN expr . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [expression -> expr] with [] and goto state 127 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 127 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE ID ASSIGN expression . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [assign_stmt -> ID ASSIGN expression] with ['x',':=',] and goto state 39 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 39 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE assign_stmt . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [non_label_stmt -> assign_stmt] with [] and goto state 38 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 38 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE non_label_stmt . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [stmt -> non_label_stmt] with [] and goto state 263 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 263 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt kELSE stmt . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [else_clause -> kELSE stmt] with ['else',] and goto state 240 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 240 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kIF expression kTHEN stmt else_clause . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [if_stmt -> kIF expression kTHEN stmt else_clause] with ['if',,'then',,] and goto state 42 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 42 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list if_stmt . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [non_label_stmt -> if_stmt] with [] and goto state 38 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 38 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list non_label_stmt . LexToken(SEMICON,';',8,153) + yacc.py: 471:Action : Reduce rule [stmt -> non_label_stmt] with [] and goto state 35 + yacc.py: 506:Result : () + yacc.py: 410: + yacc.py: 411:State : 35 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list stmt . LexToken(SEMICON,';',8,153) + yacc.py: 445:Action : Shift and goto state 79 + yacc.py: 410: + yacc.py: 411:State : 79 + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list stmt SEMICON . LexToken(kEND,'end',9,155) + yacc.py: 471:Action : Reduce rule [stmt_list -> stmt_list stmt SEMICON] with [,,';'] and goto state 22 + yacc.py: 506:Result : () yacc.py: 410: yacc.py: 411:State : 22 - yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list . LexToken(kEND,'end',15,228) + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list . LexToken(kEND,'end',9,155) yacc.py: 445:Action : Shift and goto state 34 yacc.py: 410: yacc.py: 411:State : 34 - yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kEND . LexToken(DOT,'.',15,231) - yacc.py: 471:Action : Reduce rule [compound_stmt -> kBEGIN stmt_list kEND] with ['begin',None,'end'] and goto state 12 - yacc.py: 506:Result : (None) + yacc.py: 435:Stack : program_head routine_head kBEGIN stmt_list kEND . LexToken(DOT,'.',9,158) + yacc.py: 471:Action : Reduce rule [compound_stmt -> kBEGIN stmt_list kEND] with ['begin',,'end'] and goto state 12 + yacc.py: 506:Result : () yacc.py: 410: yacc.py: 411:State : 12 - yacc.py: 435:Stack : program_head routine_head compound_stmt . LexToken(DOT,'.',15,231) - yacc.py: 471:Action : Reduce rule [routine_body -> compound_stmt] with [None] and goto state 11 - yacc.py: 506:Result : (None) + yacc.py: 435:Stack : program_head routine_head compound_stmt . LexToken(DOT,'.',9,158) + yacc.py: 471:Action : Reduce rule [routine_body -> compound_stmt] with [] and goto state 11 + yacc.py: 506:Result : () yacc.py: 410: yacc.py: 411:State : 11 - yacc.py: 435:Stack : program_head routine_head routine_body . LexToken(DOT,'.',15,231) - yacc.py: 471:Action : Reduce rule [routine -> routine_head routine_body] with [,None] and goto state 4 - yacc.py: 506:Result : () + yacc.py: 435:Stack : program_head routine_head routine_body . LexToken(DOT,'.',9,158) + yacc.py: 471:Action : Reduce rule [routine -> routine_head routine_body] with [,] and goto state 4 + yacc.py: 506:Result : () yacc.py: 410: yacc.py: 411:State : 4 - yacc.py: 435:Stack : program_head routine . LexToken(DOT,'.',15,231) + yacc.py: 435:Stack : program_head routine . LexToken(DOT,'.',9,158) yacc.py: 445:Action : Shift and goto state 10 yacc.py: 410: yacc.py: 411:State : 10 yacc.py: 430:Defaulted state 10: Reduce using 1 yacc.py: 435:Stack : program_head routine DOT . None - yacc.py: 471:Action : Reduce rule [program -> program_head routine DOT] with ['test_1',,'.'] and goto state 1 - yacc.py: 506:Result : () + yacc.py: 471:Action : Reduce rule [program -> program_head routine DOT] with ['if_statement',,'.'] and goto state 1 + yacc.py: 506:Result : () yacc.py: 410: yacc.py: 411:State : 1 yacc.py: 435:Stack : program . $end - yacc.py: 571:Done : Returning () + yacc.py: 571:Done : Returning () yacc.py: 572:PLY: PARSE DEBUG END diff --git a/yapc/yacc_pas.py b/yapc/yacc_pas.py index 21dc2b8..fa15a0a 100644 --- a/yapc/yacc_pas.py +++ b/yapc/yacc_pas.py @@ -66,11 +66,11 @@ def p_const_expr(p): p[0] = Node('const_expr', p.lexer.lineno, p[1], p[3]) -#常量定义出错 +# 常量定义出错 def p_const_expr_error(p): 'const_expr : error SEMICON' SemanticLogger.error(p[1].lineno, - f"Syntax error at token `{p[1].value}`in const expression.") + f"Syntax error at token `{p[1].value}`in const expression.") # const_value : INTEGER | REAL | CHAR | STRING | SYS_CON @@ -122,11 +122,11 @@ def p_type_definition(p): p[0] = Node("type_definition", p.lexer.lineno, p[1], p[3]) -#type定义出错 +# type定义出错 def p_type_definition_error(p): 'type_definition : ID EQUAL error SEMICON' SemanticLogger.error(p[3].lineno, - f"Syntax error at token `{p[3].value}` in type definition.") + f"Syntax error at token `{p[3].value}` in type definition.") def p_type_decl(p): @@ -175,11 +175,13 @@ def p_record_type_decl(p): 'record_type_decl : kRECORD field_decl_list kEND' p[0] = Node("record", p.lexer.lineno, p[2]) -#record定义出错 + +# record定义出错 def p_record_type_decl_error(p): 'record_type_decl : kRECORD error kEND' SemanticLogger.error(p[2].lineno, - f"Syntax error at token `{p[2].value}` in record definition.") + f"Syntax error at token `{p[2].value}` in record definition.") + def p_field_decl_list(p): '''field_decl_list : field_decl_list field_decl @@ -194,11 +196,13 @@ def p_field_decl(p): 'field_decl : name_list COLON type_decl SEMICON' p[0] = Node("field_decl", p.lexer.lineno, p[1], p[3]) -#record的成员变量定义出错 + +# record的成员变量定义出错 def p_field_decl_error(p): 'field_decl : error SEMICON' SemanticLogger.error(p[1].lineno, - f"Syntax error at token `{p[1].value}` in record member definition.") + f"Syntax error at token `{p[1].value}` in record member definition.") + def p_name_list(p): '''name_list : name_list COMMA ID @@ -231,7 +235,7 @@ def p_var_decl(p): p[0] = Node("var_decl", p.lexer.lineno, p[1], p[3]) -#var定义出错 +# var定义出错 def p_var_decl_error(p): 'var_decl : error SEMICON' SemanticLogger.error(p[1].lineno, @@ -263,7 +267,7 @@ def p_function_decl(p): p[0] = Node("function_decl", p.lexer.lineno, p[1], p[3]) -#函数体出错 +# 函数体出错 def p_function_decl_error(p): """ function_decl : function_head SEMICON error SEMICON @@ -271,6 +275,7 @@ def p_function_decl_error(p): SemanticLogger.error(p[3].lineno, f"Syntax error at token `{p[3].value}` in function definition.") + def p_function_head(p): 'function_head : kFUNCTION ID parameters COLON simple_type_decl' p[0] = Node("function_head", p.lexer.lineno, p[2], p[3], p[5]) @@ -280,7 +285,8 @@ def p_procedure_decl(p): 'procedure_decl : procedure_head SEMICON sub_routine SEMICON' p[0] = Node("procedure_decl", p.lexer.lineno, p[1], p[3]) -#procedure体出错 + +# procedure体出错 def p_procedure_decl_error(p): 'procedure_decl : procedure_head SEMICON error SEMICON' SemanticLogger.error(p[3].lineno, @@ -355,7 +361,7 @@ def p_stmt_list(p): p[0] = Node("stmt_list", p.lexer.lineno, p[1], p[2]) -#statement list出错 +# statement list出错 def p_stmt_list_error(p): 'stmt_list : stmt_list error SEMICON' SemanticLogger.error(p[2].lineno, @@ -639,18 +645,15 @@ def p_empty(p): logging.basicConfig( - level=logging.DEBUG, - filename="parselog.txt", - filemode="w", - format="%(filename)10s:%(lineno)4d:%(message)s" - ) - + level=logging.DEBUG, + filename="parselog.txt", + filemode="w", + format="%(filename)10s:%(lineno)4d:%(message)s" +) log = logging.getLogger() parser = yacc.yacc(debug=yacc.NullLogger(), debuglog=log) - if __name__ == '__main__': raise NotImplementedError("{} is just a module".format(__file__)) - diff --git a/yapc/yapc.py b/yapc/yapc.py index ba7b2d0..ce9a7fc 100755 --- a/yapc/yapc.py +++ b/yapc/yapc.py @@ -16,9 +16,10 @@ # test_file = 'test_yacc/simple.pas' test_file = 'demo_test_cases/assign_demo.pas' +out_file = './yapc.out' arg_parser = argparse.ArgumentParser() arg_parser.add_argument('--input', help='input pascal file', default=test_file) -arg_parser.add_argument('--output', help='output intermediate code path', default='./yapc.out') +arg_parser.add_argument('--output', help='output intermediate code path', default=out_file) args = arg_parser.parse_args() start = time.clock() @@ -41,7 +42,11 @@ SemanticLogger.info(None, 'producing three address code') code_generator = CodeGenerator(parse_tree_root, static_semantic_analyzer.symbol_table) code_generator.gen_three_address_code() - _ = [print(quadruple) for quadruple in code_generator.quadruple_list] + if args.output: + out_file = args.output + code_generator.write_file(out_file) + else: + _ = [print(quadruple) for quadruple in code_generator.quadruple_list] SemanticLogger.info(None, 'done') end = time.clock()