1 2 0 4 8 Com pilers I I 1 2 0 4 8 Com pilers I I Computer - - PowerPoint PPT Presentation

1 2 0 4 8 com pilers i i 1 2 0 4 8 com pilers i i
SMART_READER_LITE
LIVE PREVIEW

1 2 0 4 8 Com pilers I I 1 2 0 4 8 Com pilers I I Computer - - PowerPoint PPT Presentation

1 2 0 4 8 Com pilers I I 1 2 0 4 8 Com pilers I I Computer Science Engineering, 8 semester Mandatory, 2 Cycle Theoretical credits: 3.0 Theoretical credits: 3.0 Lab credits: 1.5 Lab credits: 1.5 Theory: Jos Neira Labs: David


slide-1
SLIDE 1

1

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

1 2 0 4 8 Com pilers I I 1 2 0 4 8 Com pilers I I

Computer Science Engineering, 8º semester Mandatory, 2º Cycle Theory: José Neira Labs: David Ken Vallejo, Javier Fabra, Luis Carlos Gallego

Theoretical credits: 3.0 Lab credits: 1.5 Theoretical credits: 3.0 Lab credits: 1.5

slide-2
SLIDE 2

2

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Schedule Schedule

Compilers II Year 2007-2008

Monday Tuesday Wednesday Thursday Friday

8-9 A 9-10 A 10-11 11-12 C C Tutoring 12-13 Tutoring 13-14 Tutoring 14-15 15-16 16-17 Tutoring 17-18 Tutoring 18-19 Tutoring B 19-20 B 20-21

slide-3
SLIDE 3

3

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

1 2 0 4 8 , English group ( C, 4 6 ) 1 2 0 4 8 , English group ( C, 4 6 )

  • Classes

– Classes will be taught in English – Slides are available in Spanish and English – Students can ask questions in Spanish or English – Students can answ er questions in Spanish or English

  • Lab w ork:

– Lab instructions will be in Spanish – Review ing will be in Spanish

  • Exam s:

– Exam s will be in Spanish – Students can answer in Spanish

http://webdiis.unizar.es/~neira/

slide-4
SLIDE 4

4

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Prelim inaries Prelim inaries

  • Compilers I y II:

Compilers I:

theory

Compilers II:

pragmatics

  • Lexical analysis
  • Syntactic analysis
  • Semantic analysis
  • Code generation
  • Optimization

‘Back-ends’ ‘Back-ends’

C C++ ADA Fortran .... Compiler 68000 80386 SPARC ....

‘Front-ends’ ‘Front-ends’ Synthesis Synthesis Analysis Analysis

slide-5
SLIDE 5

5

1 2 0 4 8 -

  • J. Neira – University of Zaragoza
  • Prerequisites:

– 1 2 0 2 5 Languages, Gram m ars y Autom ata – 1 2 0 4 4 Com pilers I

  • Grammars:
  • What should I know beforehand?

– Lexical analysis using lex – Syntax analysis using yacc

Prelim inaries Prelim inaries

regular LR(0) SLR(1) LALR(1) LR(1) LR(k) unambiguous Context free

slide-6
SLIDE 6

6

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Prelim inaries Prelim inaries

  • Prerequisites:

– 12015 Computer Architecture

  • What should I know

beforehand? – Elements of an architecture – Instruction set – Addressing modes

Activation block BP Dynamic link Size of static link of

  • uter block (l)

Return address Parameter 1 Parameter n local 1 local m display p display p-l+1 display p-1 + 1 + 2 + 3 + 4 l

STC n push(n) SRF n1 n2 push(display[DP - n1] + n2) DRF push (frames[pop()]) ASG frames[pop2()] = pop1() ASGI frames[pop1()] = pop2()

slide-7
SLIDE 7

7

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Prelim inaries Prelim inaries

  • Prerequisites:

– 12021 Algorithms and data structures: Sym bol tables

  • What should I know

beforehand? – Tree structures – Search algorithms » Hashing, … .

program main { int W; int X; void A() { int W; int Y; int Z; void B() { int X ; ... } void C() { int X; int Y ;...} ... } - end of A void D() { int Z ; ... } }

X 2 X 1 Λ W 1 A W 2 Z 1Λ Λ B 2 A 1Λ Λ W 1 C 1 W 2

Λ

slide-8
SLIDE 8

8

1 2 0 4 8 -

  • J. Neira – University of Zaragoza
  • What can I learn?

– Sem antic analysis using yacc (use of attributes) – Code generation for stack machines – General techniques for code optim ization

  • What is left out?

– I nterpreters » Other execution modes – Debuggers » Increase efficiency in use of space » Increase efficiency in execution time – Unassem blers » Software recovery

Prelim inaries Prelim inaries

slide-9
SLIDE 9

9

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Prelim inaries: program Prelim inaries: program

  • I ntroduction
  • Part 1 : Sem antic analysis

– Lesson 1: Symbol tables – Lesson 2: Type checking – Lesson 3: Semantic analysis using attributed grammars

  • Part 2 : Code generation

– Lesson 4: Abstract machines – Lesson 5: Generation of intermediate code – Lesson 6: Code optimization

  • Exercises and problems in each lesson
slide-10
SLIDE 10

10

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Lab w ork Lab w ork

  • Practical credits: 1.5

5 sessions 3 hour sessions in merlin (L0.04, Building A) 5 sessions 3 hour sessions in merlin (L0.04, Building A)

Compiladores II Curso 2007-2008 Lunes Martes Miércoles Jueves Viernes 8-9 9-10 10-11 11-12 Pr 3,6 Pr 1,2 12-13 Pr 3,6 Pr 1,2 13-14 Pr 3,6 Pr 1,2 14-15 15-16 Pr 4,5 Pr 7,8 16-17 Pr 4,5 Pr 7,8 17-18 Pr 4,5 Pr 7,8 18-19 19-20 20-21

slide-11
SLIDE 11

11

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Lab w ork Lab w ork

  • Teachers
  • Javier Fabra

– Acerete to Dom inguez

  • Luis Carlos Gallego

– Elbal to Muro

  • David Ken Vallejo

– Noé to Viñuales

slide-12
SLIDE 12

12

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Lab w ork Lab w ork

  • What is done in lab work in Compilers I I ?

– A Pascual Compiler to P(ortable) Code – A P Code assemblers – A P Code interpreter

  • W e have chosen Pascal even if:

– It is a reasonably simple but complete subset of Pascal

  • W e have chosen the P m achine because:

– Code generation is very simple – Stack machines are in use at present Why Pascal is Not My Favorite Programming Language Brian W. Kernighan, AT&T Bell Laboratories, 1981 Algorithms + Data Structures = Programs N. Wirth, P-H 1976

slide-13
SLIDE 13

13

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Lab Lab w ork w ork : : com m ents com m ents

  • Lab work is individual
  • Learn from your colleagues, they are your best

resource.

  • You know perfectly well what constitutes copying
  • Everything you submit must be your ow n
  • Copying in lab work means grade 0 in lab work
slide-14
SLIDE 14

14

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Evaluation Evaluation

  • Final grade:
  • You must pass BOTH lab work and one exam

if (exam >= 5) and (lab_work >= 5) then grade := exam * 0.6 + lab_work * 0.4; else grade := ’Suspenso’; end if (exam >= 5) and (lab_work >= 5) then grade := exam * 0.6 + lab_work * 0.4; else grade := ’Suspenso’; end

slide-15
SLIDE 15

15

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Evaluation Evaluation

  • Lab w ork:

– Submit the day specified in the instructions – W e penalize late lab work (one point per week,

  • r fraction, maximum 5 weeks of delay).

– If lab work is ok, the m inim um grade will be 5 .0 – Lab grades are valid for all exams – Lab work is different for each exam

  • Exam :

– Grade only valid for one exam – If you pass the exam but not the lab work, your grade will be fail (you will have to take another exam and submit new lab work). – No notes, books, exercises…

slide-16
SLIDE 16

16

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

Bibliography Bibliography

Compiladores: principios, técnicas y

  • herramientas. A. Aho, R. Sethi, J.
  • Ullman. Addison-Wesley Iberoamericana,

1993 Compiladores: principios, técnicas y

  • herramientas. A. Aho, R. Sethi, J.
  • Ullman. Addison-Wesley Iberoamericana,

1993 Reference manual Reference manual lex & yacc. J. Levine, T. Mason, D.

  • Brown. O’Reilly & Associates, 1992

lex & yacc. J. Levine, T. Mason, D.

  • Brown. O’Reilly & Associates, 1992

The dragon book The dragon book Advanced Compiler Design and Implementation. S.S. Muchnick. Morgan Kaufmann Publishers, 1997 Advanced Compiler Design and Implementation. S.S. Muchnick. Morgan Kaufmann Publishers, 1997 The whale book The whale book Programming Language Pragmatics. M.L. Scott. Morgan Kaufmann Publishers, 2000 Engineering a Compiler. K.D. Cooper & L.

  • Torczon. Morgan Kaufmann Publishers, 2004

Programming Language Pragmatics. M.L. Scott. Morgan Kaufmann Publishers, 2000 Engineering a Compiler. K.D. Cooper & L.

  • Torczon. Morgan Kaufmann Publishers, 2004

State of the art State of the art

slide-17
SLIDE 17

17

1 2 0 4 8 -

  • J. Neira – University of Zaragoza

More inform ation at More inform ation at

  • Web page:

http: / / www.cps.unizar.es/ ~ neira/ compii.htm

  • Anillo Digital Docente:

http: / / add.unizar.es

  • Moodle:

http: / / moodle.unizar.es