fix parser and semantic v2.2
This commit is contained in:
21
src/cminus.y
21
src/cminus.y
@@ -73,7 +73,10 @@ var_declaration : type_specifier name_specifier SEMI {
|
||||
} | type_specifier name_specifier LBRACE number_specifier RBRACE SEMI {
|
||||
$$ = newDeclNode(ArrVarK);
|
||||
$$->lineno = savedLineNo;
|
||||
$$->type = IntegerArray;
|
||||
if ($1->type == Integer)
|
||||
$$->type = IntegerArray;
|
||||
else
|
||||
$$->type = Void;
|
||||
$$->attr.name = savedName;
|
||||
free($1);
|
||||
$$->child[0] = newExpNode(ConstK);
|
||||
@@ -219,7 +222,7 @@ var : name_specifier {
|
||||
|
||||
simple_expression : additive_expression relop additive_expression {
|
||||
$$ = $2;
|
||||
$$->lineno = lineno;
|
||||
$$->lineno = $2->lineno;
|
||||
$$->child[0] = $1;
|
||||
$$->child[1] = $3;
|
||||
$$->type = Integer;
|
||||
@@ -227,51 +230,61 @@ simple_expression : additive_expression relop additive_expression {
|
||||
|
||||
relop : LE {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = LE;
|
||||
} | LT {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = LT;
|
||||
} | GT {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = GT;
|
||||
} | GE {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = GE;
|
||||
} | EQ {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = EQ;
|
||||
} | NE {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = NE;
|
||||
};
|
||||
|
||||
additive_expression : additive_expression addop term {
|
||||
$$ = $2;
|
||||
$$->lineno = lineno;
|
||||
$$->lineno = $2->lineno;
|
||||
$$->child[0] = $1;
|
||||
$$->child[1] = $3;
|
||||
} | term { $$ = $1; };
|
||||
|
||||
addop : PLUS {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = PLUS;
|
||||
} | MINUS {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = MINUS;
|
||||
};
|
||||
|
||||
term : term mulop factor {
|
||||
$$ = $2;
|
||||
$$->lineno = lineno;
|
||||
$$->lineno = $2->lineno;
|
||||
$$->child[0] = $1;
|
||||
$$->child[1] = $3;
|
||||
} | factor { $$ = $1; };
|
||||
|
||||
mulop : TIMES {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = TIMES;
|
||||
} | OVER {
|
||||
$$ = newExpNode(OpK);
|
||||
$$->lineno = lineno;
|
||||
$$->attr.op = OVER;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user