DOC PREVIEW
UConn CSE 4100 - Introduction to Compiling

This preview shows page 1-2-3-4-30-31-32-33-34-62-63-64-65 out of 65 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 65 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Chapter 1: Introduction to CompilingIntroduction to CompilersWhat is the Compilation Process? Consider the main.c C Program?Viewing C from Compiler TheoryViewing C from Usage SideWhat are Tokens? Smallest Individual Units that are RecognizedC Lexical Specification in FlexC Flex Continued …Slide 9Slide 10Slide 11Slide 12C Bison SpecificationBison Spec Continued …Slide 15Slide 16Slide 17Reviewing Compilation Process in CFrom Source to Preprocessing: What Does main.e Contain?Slide 20From Preprocessing to Assembly: What Does main.s Contain?What are Final Two Steps?Programming Languages Offer …InterpreterCompilerMixedClassifications of CompilersCompiler STructureImportant NotesSlide 30Summary of Various LanguagesThe Many Phases of a CompilerWhat Does Relocatable Mean?The Analysis Task For CompilationPhase 1. Lexical AnalysisLexical AnalysisPhase 2. Hierarchical Analysis aka Parsing or Syntax AnalysisSyntax Analysis (parsing)What is a Grammar?Summary so far…Semantic AnalysisPhase 3. Semantic AnalysisSlide 43Analysis in Text FormattingSupporting Phases/ Activities for AnalysisSummary so far...From Analysis to SynthesisThe Synthesis Task For CompilationIntermediate CodeIR Code exampleCode OptimizationMachine Code GenerationMachine code generationAssemblersLinker & LoaderReviewing the Entire ProcessSlide 57Compiler Cousins: Preprocessors 1. Macro Preprocessor2. File Inclusion3. Rational Preprocessors4. Language Extensions for a Database SystemThe Grouping of PhasesCompiler Construction ToolsModern CompilersModern Compiler ExampleCH1.1CSE4100Chapter 1: Introduction to CompilingChapter 1: Introduction to CompilingProf. Steven A. DemurjianComputer Science & Engineering DepartmentThe University of Connecticut371 Fairfield Way, Unit 2155Storrs, CT [email protected]://www.engr.uconn.edu/~steve(860) 486 - 4818Material for course thanks to:Laurent MichelAggelos KiayiasRobert LeBarreCH1.2CSE4100Introduction to CompilersIntroduction to CompilersAs a Discipline, Involves Multiple CSE AreasAs a Discipline, Involves Multiple CSE AreasProgramming Languages and Algorithms Software Engineering & Theory / Foundations Computer Architecture & Operating SystemsBut, Has Surprisingly Simplistic Intent:But, Has Surprisingly Simplistic Intent:CompilerSource programTarget ProgramError messagesDiverse & VariedCH1.3CSE4100What is the Compilation Process?What is the Compilation Process?Consider the main.c C Program?Consider the main.c C Program?#include <stdio.h>#include <ctype.h>#include <string.h>main(){char day[10];int m, d, y;m = 9;d = 7;y = 2011;strcpy(day, "Wednesday");printf("Today is: ");printf("%s %d/%d/%d\n", day, m, d, y);}CH1.4CSE4100Viewing C from Compiler TheoryViewing C from Compiler TheoryTokens or Patterns for the “Words” of the Tokens or Patterns for the “Words” of the Programming LanguageProgramming LanguageSpecified in FlexGrammar Rules that Describe the Allowable Grammar Rules that Describe the Allowable Sentences of the Programming LanguageSentences of the Programming LanguageSpecified in BisonOther Stages of CompilationOther Stages of CompilationSemantic and Type Checking AnalysisIntermediate Code GenerationCode OptimizationFinal (Relocatable) Code GenerationCH1.5CSE4100Viewing C from Usage SideViewing C from Usage SideANSI C Specification of Lexical Structure in FlexANSI C Specification of Lexical Structure in FlexANSI C Specification of Grammar Rules in BisonANSI C Specification of Grammar Rules in BisonMulti-Stage Compilation Process from Source Multi-Stage Compilation Process from Source Code to Preprocessed Code to Assembly Code to Code to Preprocessed Code to Assembly Code to Object Code to ExecutableObject Code to ExecutablePreprocess: gcc –E main.c > main.e Assembly: gcc –S main.c Generates main.sObject: gcc –c main.c Generates main.oExecutable: gcc main.c Generates a.outCH1.6CSE4100What are Tokens?What are Tokens?Smallest Individual Units that are RecognizedSmallest Individual Units that are Recognized#include <stdio.h>#include <ctype.h>#include <string.h>main(){char day[10];int m, d, y;m = 9;d = 7;y = 2011;strcpy(day, "Wednesday");printf("Today is: ");printf("%s %d/%d/%d\n", day, m, d, y);}CH1.7CSE4100C Lexical Specification in FlexC Lexical Specification in Flexhttp://www.lysator.liu.se/c/ANSI-C-grammar-l.htmlhttp://www.lysator.liu.se/c/ANSI-C-grammar-l.htmlD [0-9]L [a-zA-Z_]H [a-fA-F0-9]E [Ee][+-]?{D}+FS (f|F|l|L)IS (u|U|l|L)*%{#include <stdio.h>#include "y.tab.h"void count();%}%%"/*" { comment(); }CH1.8CSE4100C Flex Continued …C Flex Continued …"auto" { count(); return(AUTO); }"break" { count(); return(BREAK); }"case" { count(); return(CASE); }"char" { count(); return(CHAR); }"const" { count(); return(CONST); }"continue" { count(); return(CONTINUE); }"default" { count(); return(DEFAULT); }"do" { count(); return(DO); }"double" { count(); return(DOUBLE); }"else" { count(); return(ELSE); }"enum" { count(); return(ENUM); }"extern" { count(); return(EXTERN); }"float" { count(); return(FLOAT); }"for" { count(); return(FOR); }"goto" { count(); return(GOTO); }"if" { count(); return(IF); }"int" { count(); return(INT); }CH1.9CSE4100C Flex Continued …C Flex Continued …"long" { count(); return(LONG); }"register" { count(); return(REGISTER); }"return" { count(); return(RETURN); }"short" { count(); return(SHORT); }"signed" { count(); return(SIGNED); }"sizeof" { count(); return(SIZEOF); }"static" { count(); return(STATIC); }"struct" { count(); return(STRUCT); }"switch" { count(); return(SWITCH); }"typedef" { count(); return(TYPEDEF); }"union" { count(); return(UNION); }"unsigned" { count(); return(UNSIGNED); }"void" { count(); return(VOID); }"volatile" { count(); return(VOLATILE); }"while" { count(); return(WHILE); }What TOKEN is Missing?CH1.10CSE4100C Flex Continued …C Flex Continued …{L}({L}|{D})* { count(); return(check_type()); }0[xX]{H}+{IS}? { count(); return(CONSTANT); }0{D}+{IS}? { count(); return(CONSTANT); }{D}+{IS}? { count(); return(CONSTANT); }L?'(\\.|[^\\'])+' { count(); return(CONSTANT); }{D}+{E}{FS}? { count(); return(CONSTANT); }{D}*"."{D}+({E})?{FS}? { count(); return(CONSTANT); }{D}+"."{D}*({E})?{FS}? { count(); return(CONSTANT); }L?\"(\\.|[^\\"])*\" { count(); return(STRING_LITERAL); }What Do These Represent?CH1.11CSE4100C Flex Continued …C Flex Continued …"..." { count(); return(ELLIPSIS); }">>=" { count(); return(RIGHT_ASSIGN); }"<<=" { count();


View Full Document

UConn CSE 4100 - Introduction to Compiling

Download Introduction to Compiling
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Introduction to Compiling 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 Introduction to Compiling 2 2 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?