Presentation is loading. Please wait.

Presentation is loading. Please wait.

CMPE 152: Compiler Design August 21/23 Lab

Similar presentations


Presentation on theme: "CMPE 152: Compiler Design August 21/23 Lab"— Presentation transcript:

1 CMPE 152: Compiler Design August 21/23 Lab
Department of Computer Engineering San Jose State University Fall 2018 Instructor: Ron Mak

2 Conceptual Design (Version 1)
Parser Controls the translation process. Repeatedly asks the scanner for the next token. Scanner Repeatedly reads characters from the source to construct tokens for the parser. Token A source language element identifier (name) number special symbol (+ - * / = etc.) reserved word Also reads from the source Source The source program

3 Token A low-level element of the source language.
AKA lexeme Pascal language tokens Identifiers names of variables, types, procedures, functions, enumeration values, etc. Numbers integer and real (floating-point) Reserved words BEGIN END IF THEN ELSE AND OR NOT etc. Special symbols + - * / := < <= = >= > . , .. : ( ) [ ] { } ′

4 Parser Controls the translation process.
Repeatedly asks the scanner for the next token. Knows the syntax (“grammar”) of the source language’s statements and expressions. Analyzes the sequence of tokens to determine what kind of statement or expression it is translating. Verifies that what it’s seeing is syntactically correct. Flags any syntax errors that it finds and attempts to recover from them.

5 Parser, cont’d What the parser does is called parsing.
It parses the source program in order to translate it. AKA syntax analyzer

6 Scanner Reads characters sequentially from the source in order to construct and return the next token whenever requested by the parser. Knows the syntax of the source language’s tokens. What the scanner does is called scanning. It scans the source program in order to extract tokens. AKA lexical analyzer

7 Conceptual Design (Version 2)
We can architect a compiler with three major parts:

8 Major Parts of a Compiler
Front end Parser, Scanner, Source, Token Intermediate tier Intermediate code (icode) “Predigested” form of the source code that the back end can process efficiently. Example: parse trees AKA intermediate representation (IR) Symbol table (symtab) Stores information about the symbols (such as the identifiers) contained in the source program. Back end Code generator Processes the icode and the symtab in order to generate the object code. Only the front end needs to be source language-specific. The intermediate tier and the back end can be language-independent!


Download ppt "CMPE 152: Compiler Design August 21/23 Lab"

Similar presentations


Ads by Google