CS530.Chap5 - Systems Programming SDSU, CS530 Chapter 5 Guy...

Info iconThis preview shows pages 1–10. Sign up to view the full content.

View Full Document Right Arrow Icon
Systems Programming SDSU, CS530 Chapter 5 Guy E Leonard
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Structure of a compiler Lexical Analysis Syntactic Analysis Semantic Analysis Code Optimization Code Generation Lexical tokens Symbol Table Other Tables Parse Tree / stack Intermediate Code / program listing Optimized intermediate code source code linking Object code Executable code Object code from other compilations Error Processing
Background image of page 2
Compilers -- Definitions Lexical Analysis – scan source, classify into tokens Scanner – perform lexical analysis – FA/FSA/BNF Tokens – fundamental building unit for syntax – keyword, var-name, operator, assign, etc Syntactic Analysis – recognizes source statements as language constructs Parser - builds parse/syntax tree/stack – LR(k) {shift-reduce} parser Grammar = formal description of syntax (BNF) Semantics - the meaning of the statement Semantic Analysis – generates intermediate code using grammar Production | Semantic Rules – Perform CSG transforms quadruples – intermediate level representation of executable instructions Code Optimization – removes unnecessary processing work and memory usage Code Generator – creates object file
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Lexical Analysis Compiler “front end (a)” Scans & analyzes input routine for translator Recognizes & classifies (FA/FSA/BNF): identifiers, delimiters, operator symbols, numbers, keywords, noise words, blanks, comments, etc. Produces tokens converts into internal representation, identifiers, and symbol table entries Lex -1
Background image of page 4
Scanner: id using BNF <id> ::= <char>|<id><char>|<id><digit> <digit> ::= 0|1|2|3|4|5|6|7|8|9 <char> ::= a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x| y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V| W|X|Y|Z note -- alternate specification using EBNF, replace <id> with: <id> ::= <char>{<char>|<digit>}* Lex -2
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Scanner: id using FA 1 2 a-zA-Z a-zA-Z 0-9 Lex -3
Background image of page 6
Token Coding Scheme (C) Alphabet: a b c d e f g h i j k l m n o p q r s t u v w x y z A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 0 1 2 3 4 5 6 7 8 9 ! " # % & ' ( ) * + , - . /: ; < = > ? [ \ ] ^ _ { | } ~ SPACE NL TAB VT Keywords: auto, break, case, char, const, continue, default, do, double, else, enum, extern, float, for, goto, if, int, long, register, return, short, signed, sizeof, static, struct, switch, typedef, union, unsigned, void, volatile, while Operators & punctuators: ; , + - * / ~ ... && . [ ] <<= >>= ? << >> % < > &= %= |= != ^= <= >= == += -= *= /= & = ^ { } ++ -- # ## | || ! : ( ) Identifiers (names): Up to 31 char/digit/underscore as long as it starts with a char or underscore Others: integer-constant floating-point-constant character-constant string-literal escape-sequence Lex -4
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
_a-zA-Z Scanner: FA 1 2 a-zA-Z _0-9 Lex -5 3 0-9 0-9 4 ;,()~{}[]?:.=# unary operators integer-constant id (name) 5 <>|!%^&+-*/ unary operators 6 = compound operators etc…
Background image of page 8
Scanner: BNF Lex -6 <id> ::= <char>|_|<id><char>|<id><digit>|<id>_ <int-const> ::= <digit>|<int-const><digit> <compound> ::= <u-basic>= <unary> ::= <u-basic>|<u-extend>|<unary><u-basic>|<unary><u-extend> <u-extend> ::= ;|,|(|)|~|{|}|[|]|?|:|.|=|# <u-basic> ::= <|>|`|`|!|%|^|&|+|-|*|/ <digit> ::= 0|1|2|3|4|5|6|7|8|9 <char>
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 10
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 01/12/2012 for the course CS 530 taught by Professor Staff during the Spring '08 term at San Diego State.

Page1 / 48

CS530.Chap5 - Systems Programming SDSU, CS530 Chapter 5 Guy...

This preview shows document pages 1 - 10. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online