






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The code for parsing and evaluating expressions in cs 5300 - sjallan's compiler. It includes definitions for expression structure, new expression creation, making expressions from identifiers, constant expressions, string expressions, binary operators, unary minus, and boolean operators. The code demonstrates how to create new expressions, check type compatibility, and generate mips code for various operators.
Typology: Study notes
1 / 12
This page cannot be seen from the preview
Don't miss anything!







CS 5300 - SJAllan 2
typedef enum expr_kind EX_KIND; enum expr_kind {GlobalV, LocalV, LocalA, Cons, RegisterV, RegisterA, FuncRef};
typedef struct expr_info EXPR;
struct expr_info { TYPE *ex_type; EX_KIND ex_kind; int ex_inv; EXPR ex_next; }; / expr_info */
CS 5300 - SJAllan 4
EXPR *makeexpr (ID *st_ptr) { TYPE type; EX_KIND kind; int inv; type = st_ptr->id_type; inv = st_ptr->id_addr; if (st_ptr->id_level == GLOBALSCOPE) kind = GlobalV; else if (st_ptr->id_level == currscope) if (st_ptr->id_kind == RParameter) kind = LocalA; else kind = LocalV; else kind = LocalV; return(newexpr(type, kind, inv)); } / makeexpr */
CS 5300 - SJAllan 5
Expression :... | INTCONSTSY {$$ = newexpr(int_type, Cons, $1);} | CHARCONSTSY {$$ = newexpr(char_type, Cons, $1);} | STRINGCONSTSY {$$ = strexpr($1);}
... ;
CS 5300 - SJAllan 7
LValue :... | IDENTSY {$$ = lvalue($1);} ;
CS 5300 - SJAllan 8
Expression :... | Expression ADDSY Expression {$$ = binop($1, AddOp, $3);} | Expression SUBSY Expression {$$ = binop($1, SubOp, $3);} | Expression MULSY Expression {$$ = binop($1, MulOp, $3);} | Expression DIVSY Expression {$$ = binop($1, DivOp, $3);} | Expression MODSY Expression {$$ = binop($1, ModOp, $3);}
... ;
CS 5300 - SJAllan 10
Expression :... | SUBSY Expression %prec UNMINUSSY {$$ = unop(SubOp, $2);}
... ;
CS 5300 - SJAllan 11
s? DEST, S1, S