Assignment Solution Sketch PowerPoint PPT Presentation

presentation player overlay
About This Presentation
Transcript and Presenter's Notes

Title: Assignment Solution Sketch


1
Assignment Solution Sketch
  • Translation to
  • MSIL and Javabyte Code

2
  • Constant Expression Infix to postfix
  • 2 3 4
  • ( 2 (3 4 ) )
  • 2 3 4
  • Evaluating postfix expression using stack
  • 2
  • 2 3 4
  • 2 12
  • 14

3
  • Evaluating postfix expression using stack
  • 2
  • 2 3 4
  • 2 12
  • 14
  • Compiling constant expression for a stack machine
  • Push 2
  • Push 3
  • Push 4
  • Mul
  • Add

4
  • Generalizing to expressions with variables
  • i j k
  • Push i
  • Push j
  • Push k
  • Mul
  • Add
  • Conversion to abstract syntax tree
  • i
  • j k

5
  • Generalizing to expressions with variables
  • i j k
  • Push i
  • Push j
  • Push k
  • Mul
  • Add
  • Byte code generation for static f(int i,j,k)
  • ldarg.0
  • ldarg.1
  • ldarg.2
  • mul
  • add

6
Byte code for i j k for static f(int
i,j,k)
  • Right associative
  • ldarg.0
  • ldarg.1
  • ldarg.2
  • add
  • add
  • Left associative
  • ldarg.0
  • ldarg.1
  • add
  • ldarg.2
  • add

7
  • Introducing numeric types with real variables
    a b
  • Push a
  • Push b
  • Add
  • Byte code generation for static f(double a,b)
  • ldarg.0
  • ldarg.1
  • add

8
  • Mixing int and double variables (requiring
    coercion code) for static f(double a,int i, j)
  • i j a
  • ldarg.1
  • conv.r8
  • ldarg.2
  • conv.r8
  • ldarg.0
  • mul
  • add

9
  • Translation algorithm essence
  • trans (e1 e2)
  • trans(e1)
  • type coercion code?
  • trans(e2)
  • type coercion code?
  • trans()
  • Map grammar rules to control structures
  • E.g., alternatives, while-loop, etc

10
  • Mixing int and double variables (requiring
    coercion code) for static f(double a,int i, j)
  • i j a
  • iload_2
  • i2d
  • iload_3
  • i2d
  • dload_0
  • dmul
  • dadd
Write a Comment
User Comments (0)
About PowerShow.com