40 lines
797 B
Plaintext
40 lines
797 B
Plaintext
lenguaje orga-straight-line
|
|
|
|
prgm -> stms
|
|
stms -> stm; stm (s = s1;s2) -> compound
|
|
stms -> stms; stm -> compound
|
|
stm -> id = exp (asignacion) -> assign
|
|
exp -> numero (literal) -> number
|
|
exp -> id (idExp) -> id
|
|
exp -> exp op exp (operacion) -> opexp
|
|
op -> + (suma) -> plus
|
|
op -> - (resta) -> minus
|
|
|
|
IR:
|
|
example:
|
|
a = 2 + 2
|
|
=>
|
|
a = 4
|
|
=>
|
|
MOV a, 0x0004
|
|
|
|
a = b + 2
|
|
=>
|
|
stmAssign('a', opexp(exp('b'), '+', exp('2')))
|
|
=>
|
|
assign('a' binop('b' + 2, scope))
|
|
=>
|
|
MOV r1, [b]
|
|
ADD r1, 0x0002
|
|
MOV a, r1
|
|
=>
|
|
MOV r1, [0xf000]
|
|
ADD r1, 0x0002
|
|
MOV 0xf001, r1
|
|
|
|
equiv representation
|
|
=>
|
|
MOV TMP, 0x0002 exp('2')
|
|
ADD TMP, [b] exp('b') '+'
|
|
MOV a, TMP
|