def p_start_while(p): '''start_while : WHILE''' global labelNum symboltable.block(1) print(";LABEL label" + str(labelNum)) ll.insert("LABEL", "label" + str(labelNum), "", "") q.put(labelNum) stack.append("label" + str(labelNum)) labelNum = labelNum + 1
def p_end_while(p): '''end_while : ENDWHILE''' symboltable.block(0) temp = q.get() print(";JUMP label" + str(temp)) ll.insert("JUMP", "label" + str(temp), "", "") global labelNum labelNum = labelNum + 1 temp = q.get() print(";LABEL label" + str(temp)) ll.insert("LABEL", "label" + str(temp), "", "")
def p_start_else(p): '''start_else : ELSE''' global labelNum symboltable.block(1) # print(labelNum) print(";JUMP label"+ str(labelNum)) ll.insert("JUMP", "label" + str(labelNum), "", "") temp = stack.pop() print(";LABEL label" + str(temp)) ll.insert("LABEL", "label" + str(temp), "", "") stack.append(labelNum) # print(";LABEL label" + str(queue)) labelNum = labelNum + 1
def p_start_else(p): '''start_else : ELSE''' global labelNum symboltable.block(1) # print(labelNum) print(";JUMP label" + str(labelNum)) ll.insert("JUMP", "label" + str(labelNum), "", "") temp = stack.pop() print(";LABEL label" + str(temp)) ll.insert("LABEL", "label" + str(temp), "", "") stack.append(labelNum) # print(";LABEL label" + str(queue)) labelNum = labelNum + 1
def p_else_part(p): '''else_part : start_else decl stmt_list | empty''' global labelNum if len(p) > 3: symboltable.block(0)
def p_start_if(p): '''start_if : IF''' symboltable.block(1)
def p_if_stmt(p): '''if_stmt : start_if LPAREN cond RPAREN decl stmt_list else_part end_if''' symboltable.block(0)