Introduction
ICS 40: Compiler Design Principles
This subject is an introduction to the design and implementation of high-level programming language translators and compilers. It will open with a discussion of translators related to compilers, followed by an overview of the phases and data structures involved in compilation. Topics including lexical analysis, parsing techniques, symbol tables, run-time storage allocation, semantic routines, code generation, and optimization will then be covered with a series of projects assigned to illustrate practical issues.
Tuesday, July 29, 2008
Translation Rules
Infix to Prefix
1. If E is a variable or constant then Prefix(E) = E
2. If E is E1 op E2 then Prefix(E) = Prefix(E1 op E2) = op Prefix(E1) Prefix(E2)
3. If E is (E1) then Prefix(E) = Prefix(E1)
Example:
Prefix( ( 9 – 5 ) + 2 )
= + Prefix(( 9 - 5 )) Prefix(2)
= + Prefix( 9 - 5 ) Prefix(2)
= + - Prefix(9) Prefix(5) Prefix(2)
= + - 9 5 2
Postfix to Infix
1. If E is a variable or constant then Infix(E) = E
2. If E is E1 E2 op then Infix(E) = Infix(E1 op E2) = Infix(E1) op Infix(E2)
3. If E is (E1) then Infix(E) = Infix(E1)
Example:
Infix( ( 9 5 – ) 2 + )
= ( Infix(9) - Infix(5) ) + Infix(2)
= ( 9 - 5 ) + 2
Postfix to Prefix
1. If E is a variable or constant then Prefix(E) = E
2. If E is E1 E2 op then Prefix(E) = Prefix(E1 op E2) = op Prefix(E1) Prefix(E2)
3. If E is (E1) then Prefix(E) = Prefix(E1)
Example:
Prefix( 9 5 – 2 + )
= + Prefix( 9 5 ) - Prefix(2)
= + - Prefix(9) Prefix(5) Prefix(2)
= + - 9 5 2
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment