Princeton COS 320 - Compilers (44 pages)

Previewing pages 1, 2, 3, 21, 22, 23, 42, 43, 44 of 44 page document View the full content.
View Full Document

Compilers



Previewing pages 1, 2, 3, 21, 22, 23, 42, 43, 44 of actual document.

View the full content.
View Full Document
View Full Document

Compilers

87 views


Pages:
44
School:
Princeton University
Course:
Cos 320 - Compiling Techniques
Compiling Techniques Documents

Unformatted text preview:

COS 320 Compilers David Walker Outline Last Week Introduction to ML Today Lexical Analysis Reading Chapter 2 of Appel The Front End stream of characters stream of tokens Lexer abstract syntax Parser Type Checker Lexical Analysis Create sequence of tokens from characters Syntax Analysis Create abstract syntax tree from sequence of tokens Type Checking Check program for wellformedness constraints Lexical Analysis Lexical Analysis Breaks stream of ASCII characters source into tokens Token An atomic unit of program syntax i e a word as opposed to a sentence Tokens and their types Characters Recognized foo x listcount 10 45 3 14 2 1 50 100 if Type ID REAL SEMI LPAREN NUM IF Token ID foo ID x REAL 10 45 REAL 3 14 SEMI LPAREN NUM 50 NUM 100 IF Lexical Analysis Example x y 4 0 Lexical Analysis Example x y 4 0 Lexical Analysis ID x Lexical Analysis Example x y 4 0 Lexical Analysis ID x ASSIGN Lexical Analysis Example x y 4 0 Lexical Analysis ID x ASSIGN LPAREN ID y PLUS REAL 4 0 RPAREN SEMI Lexer Implementation Implementation Options 1 Write a Lexer from scratch Boring error prone and too much work Lexer Implementation Implementation Options 1 Write a Lexer from scratch Boring error prone and too much work 2 Use a Lexer Generator Quick and easy Good for lazy compiler writers Lexer Specification Lexer Implementation Implementation Options 1 Write a Lexer from scratch Boring error prone and too much work 2 Use a Lexer Generator Quick and easy Good for lazy compiler writers Lexer Specification Lexer lexer generator Lexer Implementation Implementation Options 1 Write a Lexer from scratch Boring error prone and too much work 2 Use a Lexer Generator Quick and easy Good for lazy compiler writers stream of characters Lexer Specification Lexer lexer generator stream of tokens How do we specify the lexer Develop another language We ll use a language involving regular expressions to specify tokens What is a lexer generator Another compiler Some Definitions We will want to define the



View Full Document

Access the best Study Guides, Lecture Notes and Practice Exams

Loading Unlocking...
Login

Join to view Compilers and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Compilers and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?