Presentation is loading. Please wait.

Presentation is loading. Please wait.

Compilers I CNS 3490. History Wires Wires Machine Language Machine Language FFBA FFBA No Translation necessary No Translation necessary Assembly Language.

Similar presentations


Presentation on theme: "Compilers I CNS 3490. History Wires Wires Machine Language Machine Language FFBA FFBA No Translation necessary No Translation necessary Assembly Language."— Presentation transcript:

1 Compilers I CNS 3490

2 History Wires Wires Machine Language Machine Language FFBA FFBA No Translation necessary No Translation necessary Assembly Language Assembly Language Mov r1, 0xFB Mov r1, 0xFB Assembler Assembler Compilers Compilers X = 2 X = 2 Fortran (1954-1957) Fortran (1954-1957)

3 Related Programs Interpreters Interpreters Executes source program immediately rather than generating object code. Executes source program immediately rather than generating object code. Linkers Linkers Collects separately compiled code into one executable Collects separately compiled code into one executable Loaders Loaders Often addresses need to be relocated in order for a program to be loaded into a specific spot in memory Often addresses need to be relocated in order for a program to be loaded into a specific spot in memory Preprocessor Preprocessor Output = Source Code Output = Source Code

4 Related Programs Editors Editors Debuggers Debuggers Profilers Profilers Project Managers Project Managers Example: rcs (revision control system) Example: rcs (revision control system) IDE IDE Integrated development environments Integrated development environments

5 Translation Process Parser Code Generator Optimizer Scanner source code tokens syntax tree executable Literal Table Symbol Table Error Handler

6 The Scanner Performs Lexical Analysis Performs Lexical Analysis Example Example a[index] = 4 + 2 a[index] = 4 + 2 Would be translated into Would be translated into aidentifier aidentifier [left bracket [left bracket indexidentifier indexidentifier ]right bracket ]right bracket =assignment =assignment 4number 4number +plus sign +plus sign 2number 2number

7 The Parser Performs Syntax Analysis Performs Syntax Analysis It determines the syntax of the source code It determines the syntax of the source code Turn the expression: a[index] = 4 + 2 into a parse tree Turn the expression: a[index] = 4 + 2 into a parse tree

8 Code Generator Takes an annotated parse tree and turns it into machine code or assembly language. Takes an annotated parse tree and turns it into machine code or assembly language. For example For example The parse Tree for a[index] = 6 The parse Tree for a[index] = 6 could be turned into could be turned into Mov r0, index Mov r0, index Mul r0, 2 Mul r0, 2 Mov r1, &a Mov r1, &a Add r1, r0 Add r1, r0 Mov *r1, 6 Mov *r1, 6

9 Major Data Structures in a Compiler Tokens Tokens Symbolic representation of one lexical component (one symbol) Symbolic representation of one lexical component (one symbol) Syntax Tree Syntax Tree Represents the structure of the source code being parsed Represents the structure of the source code being parsed Symbol Table Symbol Table Collection of all of the variables, class names etc. Collection of all of the variables, class names etc. Literal Table Literal Table Collection of all of the literal values (especially strings) Collection of all of the literal values (especially strings)

10 Error Handling Any good compiler should respond well to static or (compile-time) errors. Any good compiler should respond well to static or (compile-time) errors. The compilation process should terminate gracefully The compilation process should terminate gracefully Ideally, only one error should be reported for each actual error in the source code. Ideally, only one error should be reported for each actual error in the source code.


Download ppt "Compilers I CNS 3490. History Wires Wires Machine Language Machine Language FFBA FFBA No Translation necessary No Translation necessary Assembly Language."

Similar presentations


Ads by Google