Presentation is loading. Please wait.

Presentation is loading. Please wait.

Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.

Similar presentations


Presentation on theme: "Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003."— Presentation transcript:

1 Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003

2 Machine Language The only language that is “understood” by a computer Varies from machine to machine The only choice in the 1940s 0001 01 00 00001111 0011 01 10 00000010 0010 01 00 00010011 b = a + 2

3 Assembly Languages Also known as symbolic languages First developed in the 1950s Easier to read and write Assembler converts to machine code Still different for each type of machine MOV a, R1 ADD #2, R1 MOV R1, b b = a + 2

4 High-Level Languages Developed in 1960s and later Much easier to read and write Potable to many different computers Languages include C, Pascal, C++, Java, Perl, etc. Still must be converted to machine code!

5 Compilers

6 Some tools often work in conjunction with compilers (e.g. assemblers, linkers, pre-processors) Often, they are coupled with compiler

7 Analysis and Synthesis Two parts to compilation Synthesis requires more specialized techniques Many tools perform similar analysis and/or synthesis (e.g. pretty printers, interpreters, text formatters)

8 Syntax Trees Often (not always) produced by analysis Children of operation nodes are arguments for the operation

9 Phases of Analysis Lexical analysis Syntactic analysis Semantic analysis

10 Lexical Analysis Also known as linear analysis or scanning Groups input into tokens Example: b = a + 2 1.The identifier b 2.The assignment symbol = 3.The identifier a 4.The plus sign + 5.The number 2 Blanks are typically ignored Character sequence forming token is called the “lexeme” for the token

11 Syntactic Analysis Also called hierarchical analysis or parsing Groups tokens into grammatical phrases, often represented by a parse tree Often uses recursive rules (e.g. expression + expression is expression) Division between lexical and syntactic analysis is somewhat arbitrary

12 Semantic Analysis Checks source program for semantic errors (e.g. type checking) Uses hierarchical structure determined by syntactic analysis to determine operators and operands

13 Typical phases of a compiler shown here All phases may communicate with symbol table manager and/or error handler

14 Symbol Tables Data structure containing a record for each identifier with fields specifying attributes Attributes for variables include storage, type, scope, etc. Attributes for procedures include name, parameters, etc. Often don’t know certain attributes the first time identifier is seen When a lexical analyzer sees an identifier for the first time, it adds it to the symbol table

15 Intermediate Code Should have at least two qualities: –Easy to produce –Easy to translate into target program Three-address code is common –At most three operands per instruction –At most one operator (plus assignment) temp1 := 2 temp2 := a + temp1 b = temp2 b = a + 2

16 Final Phases Code optimization operates on intermediate code –General –Not really optimal Code generation generates target code –Usually assembly code or machine code –Crucial aspect is assignment of variables to registers

17 Front End vs. Back End Front end deals with source language –Includes analysis, creation of symbol table, generation of intermediate code, some optimization –Independent of target machine Back end deals with target code –Includes some optimization, code generation –Depends on target machine, not on source language

18 Passes Many compilers make multiple passes –Several phases often grouped into single pass (e.g. all of analysis and intermediate code generation) –Desirable to have relatively few passes Backpatching –Leaves blanks for unknown values to be filled in later –Allows merging of phases

19 Useful Tools Writing compilers used to be extremely complicated Now tools make the task much easier; can be done in a single semester! –Lexical analyzers (e.g. Lex) –Compiler-compilers (e.g. Yacc)

20 Relevance to Other Subjects Natural Language Processing –Summarization, Translation, QA, Search –Also often separates analysis and generation –Also deals with syntax and semantics Theoretical (Regular Expressions, Finite Automata, Context-free Grammars, etc.) Applications (e.g. latex)


Download ppt "Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003."

Similar presentations


Ads by Google