CMPE 152: Compiler Design December 5 Class Meeting

Slides:



Advertisements
Similar presentations
CS 153: Concepts of Compiler Design August 25 Class Meeting Department of Computer Science San Jose State University Fall 2014 Instructor: Ron Mak
Advertisements

C Chuen-Liang Chen, NTUCS&IE / 1 COMPILER Chuen-Liang Chen Department of Computer Science and Information Engineering National Taiwan University Taipei,
CS 153: Concepts of Compiler Design August 24 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
1 COMP 3438 – Part II-Lecture 1: Overview of Compiler Design Dr. Zili Shao Department of Computing The Hong Kong Polytechnic Univ.
CS 153: Concepts of Compiler Design October 5 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design August 26 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design September 16 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Introduction Lecture 1 Wed, Jan 12, The Stages of Compilation Lexical analysis. Syntactic analysis. Semantic analysis. Intermediate code generation.
Topic #1: Introduction EE 456 – Compiling Techniques Prof. Carl Sable Fall 2003.
1 Compiler Design (40-414)  Main Text Book: Compilers: Principles, Techniques & Tools, 2 nd ed., Aho, Lam, Sethi, and Ullman, 2007  Evaluation:  Midterm.
CS 153: Concepts of Compiler Design October 10 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
Introduction CPSC 388 Ellen Walker Hiram College.
CS 153: Concepts of Compiler Design October 21 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design November 25 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 153: Concepts of Compiler Design December 7 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
PL&C Lab, DongGuk University Compiler Lecture Note, MiscellaneousPage 1 Yet Another Compiler-Compiler Stephen C. Johnson July 31, 1978 YACC.
CS 152: Programming Language Paradigms April 7 Class Meeting Department of Computer Science San Jose State University Spring 2014 Instructor: Ron Mak
CS 153: Concepts of Compiler Design October 12 Class Meeting Department of Computer Science San Jose State University Fall 2015 Instructor: Ron Mak
CS 404Ahmed Ezzat 1 CS 404 Introduction to Compiler Design Lecture 1 Ahmed Ezzat.
Compiler Summary Lexical analysis—scanner – String of characters  token – Finite automata. Syntactical analysis – parser – Sequence of tokens –> language.
CHAPTER 1 INTRODUCTION TO COMPILER SUNG-DONG KIM, DEPT. OF COMPUTER ENGINEERING, HANSUNG UNIVERSITY.
CS 153: Concepts of Compiler Design September 14 Class Meeting
Compiler Design (40-414) Main Text Book:
CS 153: Concepts of Compiler Design August 24 Class Meeting
CS 3304 Comparative Languages
CS 326 Programming Languages, Concepts and Implementation
CS 153: Concepts of Compiler Design August 29 Class Meeting
CS 153: Concepts of Compiler Design October 17 Class Meeting
CS 153: Concepts of Compiler Design October 5 Class Meeting
Context-free Languages
CS 153: Concepts of Compiler Design October 3 Class Meeting
CS 153: Concepts of Compiler Design November 28 Class Meeting
Chapter 1: Introduction to Compiling (Cont.)
CS 153: Concepts of Compiler Design December 5 Class Meeting
CS 153: Concepts of Compiler Design November 30 Class Meeting
Compiler Lecture 1 CS510.
Bison: Parser Generator
CMPE 152: Compiler Design January 25 Class Meeting
CS416 Compiler Design lec00-outline September 19, 2018
Introduction CI612 Compiler Design CI612 Compiler Design.
CPSC 388 – Compiler Design and Construction
CMPE 152: Compiler Design September 18 Class Meeting
CMPE 152: Compiler Design September 13 Class Meeting
CMPE 152: Compiler Design October 4 Class Meeting
CMPE 152: Compiler Design September 11/13 Lab
CMPE 152: Compiler Design October 4 Class Meeting
CMPE 152: Compiler Design August 23 Class Meeting
CMPE 152: Compiler Design August 21/23 Lab
Subject: Language Processor
CMPE 152: Compiler Design December 6 Class Meeting
CS 153: Concepts of Compiler Design October 30 Class Meeting
CS 153: Concepts of Compiler Design November 6 Class Meeting
CS416 Compiler Design lec00-outline February 23, 2019
CMPE 152: Compiler Design March 7 Class Meeting
CMPE 152: Compiler Design April 9 Class Meeting
CMPE 152: Compiler Design January 29 Class Meeting
CMPE 152: Compiler Design February 7 Class Meeting
CMPE 152: Compiler Design March 21 Class Meeting
CMPE 152: Compiler Design February 21/26 Lab
Compiler Design Yacc Example "Yet Another Compiler Compiler"
Lec00-outline May 18, 2019 Compiler Design CS416 Compiler Design.
CMPE 152: Compiler Design April 18 – 30 Labs
CMPE 152: Compiler Design April 16 Class Meeting
CMPE 152: Compiler Design December 4 Class Meeting
CMPE 152: Compiler Design March 19 Class Meeting
COP 4620 / 5625 Programming Language Translation / Compiler Writing Fall 2003 Lecture 2, 09/04/2003 Prof. Roy Levow.
CMPE 152: Compiler Design April 30 Class Meeting
CMPE 152: Compiler Design August 27 Class Meeting
CMPE 152: Compiler Design September 17 Class Meeting
CMPE 152: Compiler Design September 19 Class Meeting
Presentation transcript:

CMPE 152: Compiler Design December 5 Class Meeting Department of Computer Engineering San Jose State University Fall 2017 Instructor: Ron Mak www.cs.sjsu.edu/~mak

Final Exam Wednesday, December 13 It will be similar to the midterm. 2:45-5:00 PM in ENG 403 It will be similar to the midterm. Covers the entire semester. Emphasis on the second half.

Presentation Schedule Today Mak & Cheese Thursday, Dec. 7 Cold Brew Last Minute No Name 1 Compile Nation

Lex and Yacc Lex and Yacc “Standard” compiler-compiler for Unix and Linux systems. Lex automatically generates a scanner written in C. Flex: free GNU version Yacc (“Yet another compiler-compiler”) automatically generates a parser written in C. Bison: free GNU version Generates a bottom-up shift-reduce parser.

Example: Simple Interpretive Calculator Yacc file (production rules): calc.y ... %token NUMBER %left '+' '-' /* left associative, same precedence */ %left '*' '/' /* left associative, higher precedence */ %% exprlist: /* empty list */ | exprlist '\n' | exprlist expr '\n' {printf("\t%lf\n", $2);} ; expr: NUMBER {$$ = $1;} | expr '+' expr {$$ = $1 + $3;} | expr '-' expr {$$ = $1 - $3;} | expr '*' expr {$$ = $1 * $3;} | expr '/' expr {$$ = $1 / $3;} | '(' expr ')' {$$ = $2;} We’ll need to define the NUMBER token. #include <stdio.h> #include <ctype.h> int main(int argc, char *argv[]) { progname = argv[0]; yyparse(); }

Example: Simple Calculator, cont’d Lex file (token definitions): calc.l %{ #include "calc.tab.h" extern lineno; %} %option noyywrap %% [ \t] {;} /* skip blanks and tabs */ [0-9]+\.?|[0-9]*\.[0-9]+ {sscanf(yytext, "%lf", &yylval); return NUMBER;} \n {lineno++; return '\n';} . {return yytext[0];} /* everything else */ Commands: yacc –d calc.y lex calc.l cc –c *.c cc –o calc *.o ./calc Demo

Course Review Lectures and PowerPoint slide sets Reading assignments Homework assignments Compiler project

Course Review Good understanding of compiler concepts Front end: parser, scanner, and tokens Intermediate tier: symbol table and parse trees Back end: interpreter and code generator The ANTLR 4 compiler-compiler Basic understanding of Pascal

Course Review What is the overall architecture of a compiler or an interpreter? What are the source language-independent and -dependent parts? What are the target machine-independent and -dependent parts? How can we manage the size and complexity of a compiler or an interpreter during its development?

Course Review What are the main characteristics of a top-down recursive-descent parser? Of a bottom-up parser? What is the basic control flow through an interpreter as a source program is read, translated, and executed? Through a compiler for code generation?

Course Review How do the various components work with each other? parser  scanner scanner  source program parser  symbol table parser  parse tree executor code generator symbol table parse tree 

Course Review What information is kept in a symbol table? When is a symbol table created? How is this information structured? How is this information accessed? What information is kept in a parse tree? When is a parse tree created?

Course Review What is the purpose of the symbol table stack runtime stack runtime display operand stack parse stack

Course Review Define or explain syntax and semantics syntax diagrams and BNF syntax error handling runtime error handling type checking

Course Review Deterministic finite automaton (DFA) start state accepting state transitions state transition table table-driven DFA scanner

Course Review What information is kept in an activation record or stack frame? How is this information initialized? What happens during a procedure or function call? How to pass parameters by value by reference ... with an interpreter vs. with generated object code.

Course Review The Java Virtual Machine (JVM) architecture Runtime stack Stack frame operand stack local variables array program counter

Course Review The Jasmin assembly language instructions explicit operands operands on the stack standard and “short cut” type descriptors

Course Review Jasmin assembler directives: .class .super .limit .field .var .method .line .end

Course Review Basic concepts of the ANTLR 4 compiler-compiler Tokens specification with regular expressions Production rules labelled alternates Tree node visitors Overriding visit methods.

Course Review Code generation and code templates expressions assignment statements conditional statements looping statements arrays and records

Course Review Compiling procedures and functions fields and local variables call and return passing parameters

Course Review Multipass compilers type checking pass with the visitor pattern optimization pass code generation pass with the visitor pattern

Course Review Integrating Jasmin routines with Java routines Pascal runtime library Instruction selection Instruction scheduling Register allocation spilling values live variables

Course Review Optimization for performance constant folding constant propagation strength reduction dead code elimination loop unrolling common subexpression elimination