EECS483 D1: Project 1 Overview

Similar documents
The Decaf Language. 1 Lexical considerations

The Decaf language 1

COMPILER CONSTRUCTION LAB 2 THE SYMBOL TABLE. Tutorial 2 LABS. PHASES OF A COMPILER Source Program. Lab 2 Symbol table

CS143 Handout 03 Summer 2012 June 27, 2012 Decaf Specification

Lexical and Syntax Analysis

Fundamentals of Programming Session 4

CSC 467 Lecture 3: Regular Expressions

10/4/18. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntactic Analysis

CS143 Handout 04 Summer 2011 June 22, 2011 flex In A Nutshell

Lexical Analysis. Lexical analysis is the first phase of compilation: The file is converted from ASCII to tokens. It must be fast!

Flex and lexical analysis. October 25, 2016

A Short Summary of Javali

Syntax. Syntax. We will study three levels of syntax Lexical Defines the rules for tokens: literals, identifiers, etc.

Module 8 - Lexical Analyzer Generator. 8.1 Need for a Tool. 8.2 Lexical Analyzer Generator Tool

CS415 Compilers. Lexical Analysis

Project 2 Interpreter for Snail. 2 The Snail Programming Language

Syntax Intro and Overview. Syntax

Programming Assignment I Due Thursday, October 7, 2010 at 11:59pm

CS143 Handout 05 Summer 2011 June 22, 2011 Programming Project 1: Lexical Analysis

Lexical Analysis. Introduction

Programming Assignment II

CSE302: Compiler Design

Flex and lexical analysis

Introduction to Compiler Design

CS Lecture 2. The Front End. Lecture 2 Lexical Analysis

About the Tutorial. Audience. Prerequisites. Copyright & Disclaimer. Compiler Design

CPS 506 Comparative Programming Languages. Syntax Specification

Lexical Analysis. Chapter 1, Section Chapter 3, Section 3.1, 3.3, 3.4, 3.5 JFlex Manual

Programming Assignment I Due Thursday, October 9, 2008 at 11:59pm

10/5/17. Lexical and Syntactic Analysis. Lexical and Syntax Analysis. Tokenizing Source. Scanner. Reasons to Separate Lexical and Syntax Analysis

KU Compilerbau - Programming Assignment

Prof. Mohamed Hamada Software Engineering Lab. The University of Aizu Japan

Defining Program Syntax. Chapter Two Modern Programming Languages, 2nd ed. 1

1 Lexical Considerations

COLLEGE OF ENGINEERING, NASHIK. LANGUAGE TRANSLATOR

CSEP 501 Compilers. Languages, Automata, Regular Expressions & Scanners Hal Perkins Winter /8/ Hal Perkins & UW CSE B-1

Compiler Design. Computer Science & Information Technology (CS) Rank under AIR 100

Lecture Outline. COMP-421 Compiler Design. What is Lex? Lex Specification. ! Lexical Analyzer Lex. ! Lex Examples. Presented by Dr Ioanna Dionysiou

Regular Expressions. Agenda for Today. Grammar for a Tiny Language. Programming Language Specifications

Syntax. A. Bellaachia Page: 1

THE COMPILATION PROCESS EXAMPLE OF TOKENS AND ATTRIBUTES

EXPERIMENT NO : M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM,500GB HDD

COMPILER CONSTRUCTION Seminar 02 TDDB44

Figure 2.1: Role of Lexical Analyzer

Syntactic Analysis. The Big Picture Again. Grammar. ICS312 Machine-Level and Systems Programming

COMP 181 Compilers. Administrative. Last time. Prelude. Compilation strategy. Translation strategy. Lecture 2 Overview

Programming Project 1: Lexical Analyzer (Scanner)

Introduction to Programming Using Java (98-388)

Assignment 1 (Lexical Analyzer)

Lexical Considerations

Lexical Analysis. Note by Baris Aktemur: Our slides are adapted from Cooper and Torczon s slides that they prepared for COMP 412 at Rice.

CSE 3302 Programming Languages Lecture 2: Syntax

Simple Lexical Analyzer

CS 403: Scanning and Parsing

CS 4240: Compilers and Interpreters Project Phase 1: Scanner and Parser Due Date: October 4 th 2015 (11:59 pm) (via T-square)

Introduction to Lexical Analysis

Fundamentals of Programming. Lecture 3: Introduction to C Programming

Languages, Automata, Regular Expressions & Scanners. Winter /8/ Hal Perkins & UW CSE B-1

CS 241 Data Organization. August 21, 2018

Lex & Yacc. By H. Altay Güvenir. A compiler or an interpreter performs its task in 3 stages:

Lexical Analysis. Implementing Scanners & LEX: A Lexical Analyzer Tool

Lexical Analysis (ASU Ch 3, Fig 3.1)

flex is not a bad tool to use for doing modest text transformations and for programs that collect statistics on input.

CSE302: Compiler Design

Lex & Yacc. by H. Altay Güvenir. A compiler or an interpreter performs its task in 3 stages:

Lexical analysis. Syntactical analysis. Semantical analysis. Intermediate code generation. Optimization. Code generation. Target specific optimization

Decaf Language Reference

Dr. D.M. Akbar Hussain

Lexical and Parser Tools

The Front End. The purpose of the front end is to deal with the input language. Perform a membership test: code source language?

Lexical Considerations

Type 3 languages. Regular grammars Finite automata. Regular expressions. Deterministic Nondeterministic. a, a, ε, E 1.E 2, E 1 E 2, E 1*, (E 1 )

Interpreter. Scanner. Parser. Tree Walker. read. request token. send token. send AST I/O. Console

Part 5 Program Analysis Principles and Techniques

YAGL: Yet Another Graphing Language Language Reference Manual

Structure of a compiler. More detailed overview of compiler front end. Today we ll take a quick look at typical parts of a compiler.

Languages and Compilers

A programming language requires two major definitions A simple one pass compiler

EECS483 D6: Project 3 Overview

COMPILER DESIGN LECTURE NOTES

Semantic Analysis. Lecture 9. February 7, 2018

TDDD55- Compilers and Interpreters Lesson 2

PRINCIPLES OF COMPILER DESIGN UNIT II LEXICAL ANALYSIS 2.1 Lexical Analysis - The Role of the Lexical Analyzer

Lexical Analysis. Lecture 2-4

Edited by Himanshu Mittal. Lexical Analysis Phase

1. INTRODUCTION TO LANGUAGE PROCESSING The Language Processing System can be represented as shown figure below.

CSE 413 Programming Languages & Implementation. Hal Perkins Autumn 2012 Grammars, Scanners & Regular Expressions

CMPE 152 Compiler Design

Syntax Errors; Static Semantics

Structure of Programming Languages Lecture 3

Preparing for the ACW Languages & Compilers

Chapter 3 Lexical Analysis

Examples of attributes: values of evaluated subtrees, type information, source file coordinates,

Chapter 3. Describing Syntax and Semantics ISBN

COMP 202 Java in one week

CSE 401 Midterm Exam Sample Solution 2/11/15

Implementation of Lexical Analysis

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

Introduction to Lex & Yacc. (flex & bison)

ECS 142 Spring Project (part 2): Lexical and Syntactic Analysis Due Date: April 22, 2011: 11:59 PM.

Transcription:

EECS483 D1: Project 1 Overview Chun-Hung Hsiao Jan 11, 2013 Special thanks to Ashutosh 1

Course Websites http://www.eecs.umich.edu/courses/eecs483/ Schedule, lecture slides https://piazza.com/class#winter2013/ eecs483001w13 Piazza forum for discussions and teammate lookup CTools Project & homework materials and grades NO homework/project submission on CTools! 2

Office Hours Prof. Satish Narayanasamy MoWe 3-4p @ 4721 BBB Chun-Hung Hsiao TuTh 3-5p @ NE CAEN cluster, 3F Duderstadt Center Supriya Rao Fr 3-5p @ NE CAEN cluster, 3F Duderstadt Center 3

Discussion Sessions We ll add a new discussion session starting on next week Supriya Rao TBD on Thursdays Chun-Hung Hsiao Fr 1:30-2:30p @ 1200 EECS The two sessions in the same week will cover the same materials Feel free to choose any one of them! 4

Announcements IMPORTANT: Form a group and mail me by Jan 18 Email: chhsiao _AT_ umich _DOT_ edu Add [EECS483] at the beginning of the subject Project 1 will be announced on Jan 14 Sign up on Piazza if you haven t done so 5

Introduction to Projects #projects in this course = 5 Cover 5 parts of constructing a compiler Source language: Decaf A smaller subset of features from Java/C++ Target language: MIPS Review it if you forget what you ve learned in 370! Project submission procedure will be explained in the next discussion session 6

Important Notes Honor Code You can interact with other students for discussing course materials, provide each other with limited debugging assistance, and help each other learn development tools. Though you can discuss homeworks with others, you have to write it up individually. Do not refer to others source code for the projects. We use sophisticated automated program to correlate projects of different groups and check for plagiarism. The Engineering Honor Code obligates you not only to abide by this policy, but also to report any violations that you become aware of. Violations of this policy will be brought to the College of Engineering's Honor Council. For more information on the Honor Code, see Honor Council web page. If you have any doubts about whether a certain level of collaboration is permissible, or any other questions, contact the professor. Copyright Infringement Understand the scope of copyright law. Don't take anything from the Internet, or anywhere else, because it is almost always copyrighted, by default. Don't confuse copyrights, trademarks, and other forms of "intellectual property." Learn about the public domain laws for your jurisdiction. 7

Stages of the Projects Stages of compilation Lexical analysis: scanner (Project 1) Syntax analysis: parser Semantic analysis Code generation Code optimization By the end of this term... You would own a compiler! 8

About Programming Languages... Which languages have you used? Any idea about compiling programs written in these languages? What do you do when you want to read a program written in a language you are not familiar with? 9

Elements of a Language Alphabet Characters on a standard keyboard (in most cases) Tokens Keywords, identifiers (names of variables, functions, and classes, etc.), operators, literals Grammar Expressions and statements Semantic What is the meaning of a keyword? What does an identifier refers to? 10

Decaf Language Features (1/3) Strongly typed, object oriented Similar to Java/C++, with a smaller feature set Case sensitive, both types of comments are allowed Library functions are available for I/O Detailed overview available on the course website http://www.eecs.umich.edu/courses/eecs483/ decafoverview.pdf 11

Decaf Language Features (2/3) Scoping Global scope Function scope Pair of braces defines a nested scope Java-like scoping rules are followed Data types Bulit-in base types: int, double, boolean, string Special base type for functions: void Array type Named type for objects 12

Decaf Language Features (3/3) Supports classes All variables are private Classes are declared globally this is optional when accessing a member variable Single inheritance with multiple interfaces All methods are virtual Control structure, operator precedence 13

Decaf Grammar A glimpse on Decaf grammar StmtBlock ::= { VariableDecl* Stmt* } Stmt ::= Expr ; IfStmt WhileStmt ForStmt BreakStmt ReturnStmt PrintStmt StmtBlock IfStmt ::= if ( Expr ) Stmt else Stmt Consists of tokens (in Courier font) and syntactic variables (in italic) Comprehensive reference on the course website http://www.eecs.umich.edu/courses/eecs483/ decafoverview.pdf 14

What s Project 1 All About? Use lex to create a lexical analyzer for Decaf Tow parts: preprocessor + scanner The preprocessor takes out comments and handles #define macros You just need to implement the scanner Implementing the preprocessor is optional Recognize tokens in the order they appear Set attributes for every recognized token The information will be used in future projects 15

Lexical Analysis (1/2) In English: Alice! ate! apples!. Noun, Alice Verb, ate Noun, apples Period In C++/Java/Decaf: i! =! j! +! 1! ; Identifier, i AssignOp Identifier, j AddOp Literal, int 1 Semicolon Why is lexical analysis on English more difficult? 16

Lexical Analysis (2/2) In a programming language, each symbol is associated with a pattern Token: pair of symbol and attribute Lexeme: sequence of characters matching the pattern In lex, the pattern of a symbol is specified with a regular expression Syntax similar to POSIX Extended Regular Expression Similar but not exactly the same as the mathematical notations in your writing homework! 17

Regular Expression in Lex a match a in the string [a-z] match any lowercase letter from a to z [0-9a-zA-Z] match any alphanumerical letters [^a-z] match any character but not a to z. match any character a* match 0 or more times of a a+ match at least once of a a? match at most once of a a{n} match exactly n times of a a b match either a or b ab match ab \ escape character () change precedence 18

Regex Examples Date [0-1][0-9]\.[0-3][0-9]\.[0-9]{4} May, Mary and Harry. [MH]ar*y (Mar? Harr)y if you want to match nothing more Email id with only small alphabets @ domain name.com Regular expression for a URL? 19

Lex Tool for generating scanners Specify the rules of scanning and corresponding action for every rule It automatically generates a scanner that would do the trick! The scanner is basically a DFA program written in C flex: a lex-compatible variant accessible on each CAEN linux machine 20

Lex Syntax Structure of a.l file: DEFINITIONS %% RULES %% USERCODE 21

Lex Definitions Define names for regular expressions used in the RULE section for convenience Examples: DIGIT! [0-9] CommentStart! "/*" IDENTIFIER! [a-za-z][a-za-z0-9]* Necessary user code can be placed here %{ #include <stdio.h> %} 22

Lex Rules Each line consists of a rule in the following form: PATTERN ACTION Pattern: a combination of defined names and regex Action: a piece of C code describing what to do Example {DIGIT}+ 0x[0-9A-Fa-f]+! val=strtol(yytext,null,0); 23

Lex Example: Line Count %{ #include <stdio.h> int num_lines = 0, num_chars = 0; %} %% \n ++num_lines; ++num_chars;. ++num_chars; %% int main() { yylex(); printf("# of lines = %d, # of chars = %d\n", num_lines, num_chars); return 0; } 24

References http://flex.sourceforge.net/manual/ http://dinosaur.compilertools.net/#lex http://dinosaur.compilertools.net/#flex http://epaperpress.com/lexandyacc http://www.cs.rug.nl/~jjan/vb/lextut.pdf 25

Thank you & all the best :) 26