def R(parent, table): #<条件语句> child = Node('<条件语句>') parent.add(child) if SYM[p] == KEYWORDS['if']: child.add(Node('if')) advance() K(child, table) ret = Code('JPC', 0, None) code.append(ret) if SYM[p] != KEYWORDS['then']: child.add(Node('then')) H(child, table) ret.a = len(code) print(Position[p], "缺少then") global Error Error = 1 else: child.add(Node('then')) advance() H(child, table) ret.a = len(code) # while : else: print(Position[p], "递归错误") Error = 1
def R(parent, table): #<条件语句> child = Node('<条件语句>') parent.add(child) if SYM[p] == KEYWORDS['if']: child.add(Node('if')) advance() K(child, table) ret = Code('JPC', 0, None) code.append(ret) if SYM[p] == KEYWORDS['then']: child.add(Node('then')) advance() H(child, table) ret.a = len(code) else: error() else: error()
def T(parent, table): #<当型循环语句> child = Node('<当型循环语句>') parent.add(child) if SYM[p] == KEYWORDS['while']: child.add(Node('while')) advance() ret = len(code) K(child, table) fret = Code('JPC', 0, None) code.append(fret) if SYM[p] == KEYWORDS['do']: child.add(Node('do')) advance() H(child, table) code.append(Code('JMP', 0, ret)) fret.a = len(code) else: error() else: error()
def T(parent, table): #<当型循环语句> child = Node('<当型循环语句>') parent.add(child) if SYM[p] == KEYWORDS['while']: child.add(Node('while')) advance() ret = len(code) K(child, table) fret = Code('JPC', 0, None) code.append(fret) if SYM[p] == KEYWORDS['do']: child.add(Node('do')) advance() H(child, table) code.append(Code('JMP', 0, ret)) fret.a = len(code) else: print(Position[p], "while后面缺少do") global Error Error = 1 else: print(Position[p], "递归错误") error()