def p_varcte_id(p): '''varcte : ID''' var = symtable.get_var(p[1]) if not var: errors.append("Line {}: Undefined variable '{}'".format(p.lineno(1), p[1])) raise SyntaxError else: p[0] = var
def p_array_index(p): '''array_index : LBRACK expression RBRACK''' var = symtable.get_var(p[-1]) if not var: errors.append("Line {}: Undefined variable '{}'".format(p.lineno(1), p[-1])) raise SyntaxError elif not var['dim']: errors.append("Line {}: Variable '{}' is not an array".format(p.lineno(1), p[-1])) raise SyntaxError exp_res = codegen.opdos.pop() if exp_res['type'] != int: errors.append("Line {}: Index must be integer".format(p.lineno(1))) raise SyntaxError liminf = 0 limsup = var['dim']-1 codegen.gen_quad(dir.verifica, exp_res['dir'], liminf, limsup) basedir = symtable.add_constant(var['dir']) pointer = symtable.newpointer() codegen.gen_quad(dir.suma, basedir['dir'], exp_res['dir'], pointer) res = {'dir':pointer, 'type':int, 'dim':None} #codegen.opdos.append(res) p[0] = res
def p_input(p): 'input : SCAN ID' var = symtable.get_var(p[2]) if not var: var = symtable.add_var(p[2], str, None) codegen.gen_quad(dir.scan, -1, -1, var['dir'])