MU - Three Address Intermediate Language MU Grammar: <program> ::= <stmtlist> halt <stmtlist> ::= <stmt> <stmtlist> <stmtlist> ::= l <stmt> ::= declare <id>, <typespec> <stmt> ::= read <id> <stmt> ::= write <expr> <stmt> ::= store <expr>, <id> <stmt> ::= iadd <expr>, <expr>, <id> <stmt> ::= isub <expr>, <expr>, <id> <stmt> ::= imult <expr>, <expr>, <id> <stmt> ::= idiv <expr>, <expr>, <id> <stmt> ::= imod <expr>, <expr>, <id> <stmt> ::= radd <expr>, <expr>, <id> <stmt> ::= rsub <expr>, <expr>, <id> <stmt> ::= rmult <expr>, <expr>, <id> <stmt> ::= rdiv <expr>, <expr>, <id> <stmt> ::= low <expr>, <expr>, <id> <stmt> ::= high <expr>, <expr>, <id> <stmt> ::= equ <expr>, <expr>, <id> <stmt> ::= and <expr>, <expr>, <id> <stmt> ::= or <expr>, <expr>, <id> <stmt> ::= not <expr>, <id> <stmt> ::= jt <id>, <label> <stmt> ::= jf <id>, <label> <stmt> ::= jmp <label> <stmt> ::= call <label> <stmt> ::= return <stmt> ::= <label> <stmt> ::= rtoi <id>, <id> <stmt> ::= itor <id>, <id> <typespec> ::= integer | real <label> ::= :<id> <expr> ::= <id> | <literal> <literal> ::= <integer> | <real> <integer> ::= <digit> <end_int> <end_int> ::= <digit> <end_int> <end_int> ::= l <real> ::= <integer>.<integer> <id> ::= <char> <string> <string> ::= <char> <string> <string> ::= <digit> <string> <string> ::= l <digit> ::= [0-9] <char> ::= [a-zA-Z_&] MU - Operational Semantics Program Format: All statements must begin in the first column, and there may be only one statement per line. Comments may follow a semicolon. A space, semicolon, or newline in the first column indicates an unused line - anything else will be considered a statement. Declarative, I/0, and Assignment: declare id, type Inserts id into the symbol table with and gives it the specified type (integer or real). All ids must be declared before they are used. read id Accepts a value from standard input. write expr Outputs a value on standard output. store expr, id Assigns the value of expr to id. Integer Arithmetic Operators: iadd e1, e2, r Adds integer variable or literal el to integer e2 and stores the result in r. isub e1, e2, r Subtracts integer variable or literal e2 from el and stores the result in r. imult e1, e2, r Multiplies integer variable or literal el by e2 and stores the result in r. idiv el, e2, r Divides integer variable or literal el by e2 and stores the result in r. imod el, e2, r Gives the remainder when integer variable or literal el is divided by e2 and stores the result in r. Note: e1 and e2 are always unchanged after these operations. Real Arithmetic Operators: Real arithmetic operators are analogous to integer operations with an initial 'r' instead of 'i' (except imod for which there is no real equivalent.) Relational 0perators: ( f is always integer; e1 and e2 are both integer or both real) high e1, e2, f Sets f to 1 if e1 > e2, 0 otherwise. low e1, e2, f Sets f to 1 if e1 < e2, 0 otherwise. equ e1, e2, f Sets f to 1 if el = e2, 0 otherwise. Boolean 0perators (all operands are integers) and f1, f2, f3 Sets f3 to 1 if fl = f2 = 1, 0 otherwise. or fl, f2, f3 Sets f3 to 1 if either fl = 1 or f2 = 1, 0 otherwise. not fl, f2 Sets f2 to 1 - fl. Transfer of Control: jt f, label Transfers control to the instruction immediately following label iff f = 1. jf f, label Transfers control to the instruction immediately following label iff f = 0. jmp label Unconditionally transfers control to the statement immediately following label. call label Same effect as jmp, except that the address of the call is saved so that a return statement can cause control to be returned to the statement immediately following the call statement. return Transfers control to the statement immediately following the most recent call statement. halt Terminates the program Type conversion: rtoi r, i Converts the value in real variable r to integer variable i. itor i, r Converts the value in integer variable i to real variable r.