// 统一检查变量类型 public String backString(Exp_mark mark, type_cal match_type) { // String s=null; // 首先检查是否是变量,或者是数字常量 if (mark.type == type_cal.ID || mark.type == type_cal.NORMAL_NUM) { type_cal t = check_define(mark.value); if (t == match_type || mark.type == type_cal.NORMAL_NUM) { // s=mark.value; } else { if (t == null) { // 变量未定义,也不是常量 error.error_print(3, mark.value, mark.line, mark.row); } else { count++; error.error_print(9, t.toString(), mark.line, mark.row); } } } else { // 如果是字符常量 count++; error.error_print(9, mark.type.toString(), mark.line, mark.row); } return mark.value; // return s; }
public void parse_sema_mark(Exp_mark exp_mark) { // a=a+b 等号左边的必须是变量,不能是常量,而且需要匹配类型;右边的可以使常量,但必须匹配类型 if (exp_mark.type == type_cal.ID) { if (check_define(exp_mark.value) == type_cal.NUM) { Exp_Operate operate = null; operate = new Exp_Operate(); if (exp_mark.got != null) { Exp_Operate op_send = new Exp_Operate(); Exp_calcul c = (Exp_calcul) exp_mark.got; operate.s = parse_sema_mark_((Exp_calcul) c.left); while (c.right != null) { c = (Exp_calcul) c.right; if (c.type == type_cal.ADD) { operate.op = type_op.ADD; // System.out.println("+"); } else if (c.type == type_cal.SUB) { operate.op = type_op.SUB; // System.out.println("-"); } operate.d = parse_sema_mark_((Exp_calcul) c.left); operate.result = "$"; list_op.add(operate); operate = clone_Operate(operate); operate.s = operate.result; } op_send.op = type_op.SEND; Exp_calcul cal = (Exp_calcul) exp_mark.got; op_send.s = operate.s; op_send.result = exp_mark.value; list_op.add(op_send); } } else if (check_define(exp_mark.value) == type_cal.STRING) { count++; error.error_print(9, "string", exp_mark.line, exp_mark.row); } else if (check_define(exp_mark.value) == type_cal.BOOL) { count++; error.error_print(9, "bool", exp_mark.line, exp_mark.row); } else { count++; error.error_print(9, null, exp_mark.line, exp_mark.row); } } else { count++; error.error_print(8, exp_mark.type.toString(), exp_mark.line, exp_mark.row); } }