Docsity

CSE 401 - Compilers: Overview and Administrivia, Exams of Compiler Design

Partial preview of the text

Download CSE 401 - Compilers: Overview and Administrivia and more Exams Compiler Design in PDF only on Docsity!

CSE 401 – Compilers

Overview and Administrivia

Hal Perkins

Winter 2017

Agenda

  • IntroducCons
  • Administrivia
  • What’s a compiler?
  • Why you want to take this course

Credits

  • Some direct ancestors of this course:
    • UW CSE 401 (Chambers, Snyder, Notkin, Perkins, Ringenburg, Henry, …)
    • UW CSE PMP 582/501 (Perkins)
    • Cornell CS 412-3 (Teitelbaum, Perkins)
    • Rice CS 412 (Cooper, Kennedy, Torczon)
    • Many books (Appel; Cooper/Torczon; Aho, [[Lam,] Sethi,] Ullman [Dragon Book], Fischer, [Cytron ,] LeBlanc; Muchnick, …)
  • [Won’t ajempt to ajribute everything – and

some of the details are lost in the haze of Cme.]

So whadda ya know?

  • Official prerequisites:
    • CSE 332 (data abstracCons)
      • and therefore CSE 311 (FoundaCons)
    • CSE 351 (hardware/sokware interface, x86_64)
  • Also useful, but not required:
    • CSE 331 (sokware design & implementaCon)
    • CSE 341 (programming languages)
    • Who’s taken these?

Staying in touch

  • Course web site
  • Discussion board
    • For anything related to the course
    • Join in! Help each other out. Staff will contribute.
  • Mailing list
    • You are automaCcally subscribed if you are registered
    • Will keep this fairly low-volume; limited to things that everyone needs to read

Requirements & Grading

  • Roughly
    • 50% project, done with a partner
    • 15% individual wrijen homework
    • 15% midterm exam
    • 20% final exam We reserve the right to adjust as needed

CSE 401 Course Project

  • Best way to learn about compilers is to build one
  • Course project
    • MiniJava compiler: classes, objects, etc.
      • Core parts of Java – essenCals only
      • Originally from Appel textbook (but you won’t need that)
    • Generate executable x86-64 code & run it
    • Completed in steps through the quarter
      • Where you wind up at the end is the most important part, but there are intermediate milestone deadlines to keep you on schedule and provide feedback at important points

Project Groups

  • You should work in pairs
    • Pick a partner now to work with throughout quarter – will need this info early next week
  • We’ll provide accounts on department git

server (gitlab) for groups to store and

synchronize their work & we’ll get files from

there for grading/feedback

  • How many people have used gitlab? git?

And the point is…

  • How do we execute something like this? int nPos = 0; int k = 0; while (k < length) { if (a[k] > 0) { nPos++; } }
  • The computer only knows 1’s & 0’s - i.e.,

encodings of instrucCons and data

Structure of a Compiler

  • At a high level, a compiler has two pieces:
    • Front end: analysis
      • Read source program and discover its structure and meaning
    • Back end: synthesis
      • Generate equivalent target language program Source (^) Front End Back End Target

ImplicaCons

  • Phases communicate using some sort of Intermediate RepresentaCon(s) (IR) - Front end maps source into IR - Back end maps IR to target machine code - Oken mulCple IRs – higher level at first, lower level in later phases Source (^) Front End Back End Target

Front End

  • Usually split into two parts
    • Scanner: Responsible for converCng character stream to token stream: keywords, operators, variables, constants, … - Also: strips out white space, comments
    • Parser: Reads token stream; generates IR
      • Either here or shortly aker, perform semanCcs analysis to check for things like type errors, etc.
  • Both of these can be generated automaCcally
    • Use a formal grammar to specify the source language
    • Tools read the grammar and generate scanner & parser (lex/yacc or flex/bison for C/C++, JFlex/CUP for Java) Scanner Parser source tokens IR

Parser Output (IR)

  • Given token stream from scanner, the parser

must produce output that captures the meaning

of the program

  • Most common output from a parser is an

abstract syntax tree

  • EssenCal meaning of program without syntacCc noise
  • Nodes are operaCons, children are operands
  • Many different forms
  • Engineering tradeoffs have changed over Cme
  • Tradeoffs (and IRs) can also vary between different phases of a single compiler

Parser Example

  • Token Stream • Abstract Syntax Tree IF LPAREN ID(x) GEQ ID(y) RPAREN ID(y) BECOMES INT(42) SCOLON ifStmt

= ID(x) ID(y) assign ID(y) INT(42) Original source program: // this statement does very little if (x >= y) y = 42;