LARA

Translating Expressions to Stack Machine

Connection to Postfix

Example: translate expression

(a*b + b*c + a*c) * 2

into posftix form.

Tree:

Postfix expression:

Compare to cubeArea in Compiled Expression Examples

In compiled code what corresponds to:

  • '+'
  • '*'
  • variables, like a,b,c
  • constants, like 2

Conclusion:

Translation Rules

Notation for translation

\begin{equation*}
    [\![ e_1 * e_2 ]\!] = [\![ e_1 ]\!] ::: [\![ e_2 ]\!] ::: List([\![*]\!])
\end{equation*}

and similarly for other operations.

For constant $c$,

\begin{equation*}
    [\![ c ]\!] = List(\textbf{bipush}(c))
\end{equation*}

The iconst is just special case of bipush