Should be done. Do Soon. Structure of a Typical Compiler. Plan for Today. Lab hours and Office hours. Quiz 1 is due tonight, was posted Tuesday night

Similar documents
Languages. L((a (b)(c))*) = { ε,a,bc,aa,abc,bca,... } εw = wε = w. εabba = abbaε = abba. (a (b)(c)) *

Deterministic. Finite Automata. And Regular Languages. Fall 2018 Costas Busch - RPI 1

CS412/413. Introduction to Compilers Tim Teitelbaum. Lecture 4: Lexical Analyzers 28 Jan 08

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών

Lexical analysis, scanners. Construction of a scanner

Some Thoughts on Grad School. Undergraduate Compilers Review and Intro to MJC. Structure of a Typical Compiler. Lexing and Parsing

Definition of Regular Expression

CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Fig.25: the Role of LEX

CS 432 Fall Mike Lam, Professor a (bc)* Regular Expressions and Finite Automata

Topic 2: Lexing and Flexing

In the last lecture, we discussed how valid tokens may be specified by regular expressions.

CS 430 Spring Mike Lam, Professor. Parsing

CS321 Languages and Compiler Design I. Winter 2012 Lecture 5

Implementing Automata. CSc 453. Compilers and Systems Software. 4 : Lexical Analysis II. Department of Computer Science University of Arizona

Dr. D.M. Akbar Hussain

CMPSC 470: Compiler Construction

Lexical Analysis: Constructing a Scanner from Regular Expressions

ΕΠΛ323 - Θεωρία και Πρακτική Μεταγλωττιστών. Lecture 3b Lexical Analysis Elias Athanasopoulos

Finite Automata. Lecture 4 Sections Robb T. Koether. Hampden-Sydney College. Wed, Jan 21, 2015

Assignment 4. Due 09/18/17

CS143 Handout 07 Summer 2011 June 24 th, 2011 Written Set 1: Lexical Analysis

Reducing a DFA to a Minimal DFA

CS 340, Fall 2014 Dec 11 th /13 th Final Exam Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

TO REGULAR EXPRESSIONS

Lexical Analysis. Amitabha Sanyal. ( as) Department of Computer Science and Engineering, Indian Institute of Technology, Bombay

CSCE 531, Spring 2017, Midterm Exam Answer Key

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University of the Negev

this grammar generates the following language: Because this symbol will also be used in a later step, it receives the

CS 241. Fall 2017 Midterm Review Solutions. October 24, Bits and Bytes 1. 3 MIPS Assembler 6. 4 Regular Languages 7.

CSCI 3130: Formal Languages and Automata Theory Lecture 12 The Chinese University of Hong Kong, Fall 2011

ASTs, Regex, Parsing, and Pretty Printing

CS453 Compiler Construction

From Dependencies to Evaluation Strategies

Compiler Construction D7011E

COMP 423 lecture 11 Jan. 28, 2008

Principles of Programming Languages

Example: Source Code. Lexical Analysis. The Lexical Structure. Tokens. What do we really care here? A Sample Toy Program:

Quiz2 45mins. Personal Number: Problem 1. (20pts) Here is an Table of Perl Regular Ex

Lexical Analysis and Lexical Analyzer Generators

Applied Databases. Sebastian Maneth. Lecture 13 Online Pattern Matching on Strings. University of Edinburgh - February 29th, 2016

LEX5: Regexps to NFA. Lexical Analysis. CMPT 379: Compilers Instructor: Anoop Sarkar. anoopsarkar.github.io/compilers-class

CSE 401 Midterm Exam 11/5/10 Sample Solution

Theory of Computation CSE 105

acronyms possibly used in this test: CFG :acontext free grammar CFSM :acharacteristic finite state machine DFA :adeterministic finite automata

Fall Compiler Principles Lecture 1: Lexical Analysis. Roman Manevich Ben-Gurion University

Compilation

CS 241 Week 4 Tutorial Solutions

Virtual Machine (Part I)

CS 340, Fall 2016 Sep 29th Exam 1 Note: in all questions, the special symbol ɛ (epsilon) is used to indicate the empty string.

CS201 Discussion 10 DRAWTREE + TRIES

COS 333: Advanced Programming Techniques

COS 333: Advanced Programming Techniques

ECE 468/573 Midterm 1 September 28, 2012

Scanner Termination. Multi Character Lookahead. to its physical end. Most parsers require an end of file token. Lex and Jlex automatically create an

12 <= rm <digit> 2 <= rm <no> 2 <= rm <no> <digit> <= rm <no> <= rm <number>

Qubit allocation for quantum circuit compilers

Lecture T1: Pattern Matching

CMSC 331 First Midterm Exam

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFORMATICS 1 COMPUTATION & LOGIC INSTRUCTIONS TO CANDIDATES

CS 321 Programming Languages and Compilers. Bottom Up Parsing

Midterm I Solutions CS164, Spring 2006

Midterm 2 Sample solution

Context-Free Grammars

Sample Midterm Solutions COMS W4115 Programming Languages and Translators Monday, October 12, 2009

Compilers Spring 2013 PRACTICE Midterm Exam

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence Winter 2016

Outline CS 412/413. Function calls. Stack layout. Tiling a call. Two translations

Regular Expression Matching with Multi-Strings and Intervals. Philip Bille Mikkel Thorup

PPS: User Manual. Krishnendu Chatterjee, Martin Chmelik, Raghav Gupta, and Ayush Kanodia

Operator Precedence. Java CUP. E E + T T T * P P P id id id. Does a+b*c mean (a+b)*c or

Java CUP. Java CUP Specifications. User Code Additions. Package and Import Specifications

10/12/17. Motivating Example. Lexical and Syntax Analysis (2) Recursive-Descent Parsing. Recursive-Descent Parsing. Recursive-Descent Parsing

From Indexing Data Structures to de Bruijn Graphs

Homework. Context Free Languages III. Languages. Plan for today. Context Free Languages. CFLs and Regular Languages. Homework #5 (due 10/22)

ITEC2620 Introduction to Data Structures

Agenda & Reading. Class Exercise. COMPSCI 105 SS 2012 Principles of Computer Science. Arrays

LR Parsing, Part 2. Constructing Parse Tables. Need to Automatically Construct LR Parse Tables: Action and GOTO Table

Mid-term exam. Scores. Fall term 2012 KAIST EE209 Programming Structures for EE. Thursday Oct 25, Student's name: Student ID:

String Searching. String Search. Applications. Brute Force: Typical Case

CMPT 379 Compilers. Lexical Analysis

Solving Problems by Searching. CS 486/686: Introduction to Artificial Intelligence

What are suffix trees?

Lecture 18: Theory of Computation

6.3 Volumes. Just as area is always positive, so is volume and our attitudes towards finding it.

Outline. Tiling, formally. Expression tile as rule. Statement tiles as rules. Function calls. CS 412 Introduction to Compilers

LING/C SC/PSYC 438/538. Lecture 21 Sandiway Fong

Regular Expressions and Automata using Miranda

Context-Free Grammars

Tries. Yufei Tao KAIST. April 9, Y. Tao, April 9, 2013 Tries

Stack Manipulation. Other Issues. How about larger constants? Frame Pointer. PowerPC. Alternative Architectures

2014 Haskell January Test Regular Expressions and Finite Automata

Problem Set 2 Fall 16 Due: Wednesday, September 21th, in class, before class begins.

Today. CS 188: Artificial Intelligence Fall Recap: Search. Example: Pancake Problem. Example: Pancake Problem. General Tree Search.

States and Statecharts. Outline

Scanner Termination. Multi Character Lookahead

Today. Search Problems. Uninformed Search Methods. Depth-First Search Breadth-First Search Uniform-Cost Search

CSCI 446: Artificial Intelligence

Pattern Matching. exact pattern matching Knuth-Morris-Pratt RE pattern matching grep

1.1. Interval Notation and Set Notation Essential Question When is it convenient to use set-builder notation to represent a set of numbers?

Transcription:

Should e done L hours nd Office hours Sign up for the miling list t, strting to send importnt info to list http://groups.google.com/group/cs453-spring-2011 Red Ch 1 nd skim Ch 2 through 2.6, red 3.3 nd 3.4 Strt working with the MiniSVG strt up code You should t lest step through the existing code with deugger efore Thursdy s clss Do Soon Quiz 1 is due tonight, ws posted Tuesdy night Continue working with the MiniSVG strt up code You should t lest step through the existing code with deugger efore Thursdy s clss Send emil to mstrout@cs.colostte.edu if you would like to help put together Meggy Jr devices this Sundy 2-3pm in rm 425 Will only e le to ccommodte the first 8 students, still 3 slots left Will open it up for grd students nd other undergrds on Thursdy We will hve one other session sometime next week Tuesdy or Thursdy night HW1 due Wednesdy CS453 Lecture Regulr Expressions nd Trnsition Digrms 2 CS453 Lecture Regulr Expressions nd Trnsition Digrms 3 Pln for Tody Structure of Typicl Compiler Interpreter nd Compiler Structure, or Softwre Architecture Overview of Progrmming Assignments The MiniSVG interpreter nd MeggyJv compiler we will e uilding. Anlysis chrcter strem lexicl nlysis Synthesis IR code genertion tokens words IR syntctic nlysis optimiztion AST sentences IR nnotted AST semntic nlysis code genertion trget lnguge interpreter CS453 Lecture Regulr Expressions nd Trnsition Digrms 4 CS453 Lecture Regulr Expressions nd Trnsition Digrms 5

Exmple MeggyJv progrm import meggy.meggy; clss PA3Flower { pulic sttic void min(string[] whtever){ { // Upper left petl, clockwise Meggy.setPixel( (yte)2, (yte)4, Meggy.Color.VIOLET ); Meggy.setPixel( (yte)2, (yte)1, Meggy.Color.VIOLET); } } Atmel ssemly for Meggy.setPixel() cll min: cll _Z18MeggyJrSimpleSetupv # Push constnt 2 onto stck ldi r24, 2 push r24 # Push constnt 4 onto stck ldi r24, 4 push r24 # Push Meggy.Color.VIOLET onto the stck. ldi r22, 6 push r22 # Pop the rguments into registers in reverse order. pop r20 pop r22 pop r24 cll _Z6DrwPxhhh cll _Z12DisplySltev CS453 Lecture Regulr Expressions nd Trnsition Digrms 6 CS453 Lecture Regulr Expressions nd Trnsition Digrms 7 Structure of the MeggyJv Compiler Structure of the MiniSVG Interpreter (PA1) Anlysis chrcter strem Synthesis Anlysis chrcter strem lexicl nlysis tokens words syntctic nlysis AST AST nd symol tle sentences semntic nlysis code gen Atmel ssemly code PA2: MeggyJv nd Atmel wrmup PA3: setpixel compiler PA4: dd control flow PA5: dd functions PA6: dd vriles nd ojects PA7: dd rrys CS453 Lecture Regulr Expressions nd Trnsition Digrms 8 lexicl nlysis tokens syntctic nlysis clls to report nd drw routines Rectngle: (0,0) 500x500 color: GREEN Circle: (120,150) rdius:60 color: WHITE Circle: (350,150) rdius:60 color: WHITE Circle: (120,150) rdius:30 color: BLUE Circle: (350,150) rdius:30 color: BLUE Circle: (120,150) rdius:10 color: BLACK Circle: (350,150) rdius:10 color: BLACK Circle: (250,300) rdius:100 color: RED Line: (250,350) (350,350) color: BLACK Line: (0,100) (100,100) color: BLACK Line: (100,200) (200,200) color: BLACK Line: (300,400) (400,400) color: BLACK Line: (500,500) (500,500) color: BLACK Line: (50,100) (100,100) color: BLACK Line: (150,200) (200,200) color: BLACK Line: (200,400) (400,400) color: BLACK Line: (400,200) (400,200) color: BLACK Line: (450,200) (400,200) color: BLACK CS453 Lecture Regulr Expressions nd Trnsition Digrms 9

fce.svg <svg xmlns="http://www.w3.org/2000/svg"> <!-- THIS MAKES A FACE!!! --> <!-- From Stephnie nd Kiley --> <!-- ckground --> <rect x = "0" y = "0" width = "500" height = "500" fill="green" /> <!-- eyes --> <circle cx="120" cy="150" r="60" fill="white" />... <!-- mouth --> <circle cx="250" cy="300" r="100" fill="red" /> <line x1="250" y1="350" x2="350" y2="350" stroke="lck" /> <!-- hir -->... </svg> MiniSVG Renderer <svg xmlns="http://www.w3.org/2000/svg"> <!-- rectngles --> <rect x="20" y=" 20" width="300" height="250" fill="red" /> <rect x="30" y="20" width="300" height="250" fill="lue" /> <rect x = "40" y = "20" width = "300" height = "250" fill="green" /> <!-- white circle on top of rectngles --> <circle cx="120" cy="150" r="60" fill="white" /> <!-- lck digonl line --> <line x1="0" y1="0" x2="300" y2="300" stroke="lck" /> </svg> CS453 Lecture Regulr Expressions nd Trnsition Digrms 10 CS453 Lecture Regulr Expressions nd Trnsition Digrms 11 Aout The Slides on Lnguges nd Finite Automt Slides Originlly Developed y Prof. Costs Busch (2004) Mny thnks to Prof. Busch for developing the originl slide set. Adpted with permission y Prof. Dn Mssey (Spring 2007) Susequent modifictions, mny thnks to Prof. Mssey for CS 301 slides Adpted with permission y Prof. Michelle Strout (Spring 2011) Adpted for use in CS 453 Lnguges A lnguge is set of strings String: A finite sequence of letters Exmples: ct, dog, house, Defined over fixed lphet:! = {,, c,, z}

Empty String A string with no letters: " Regulr Expressions Regulr expressions descrie regulr lnguges Oservtions: " = 0 "w = w" = w " = " = Exmple: ( ()(c)) * descries the lnguge L(( ()(c))*) = {",c,,c,c,...} Recursive Definition for Specifying Regulr Expressions Exmple Regulr Expressions nd Regulr Definitions Primitive regulr expressions: ", #, $ Keywords Given regulr expressions r 1 nd r 2 Opertions r 1 r 2 (r 1 )(r 2 ) r 1 * ( r 1 ) Are regulr expressions Identifiers Numers CS453 Lecture Regulr Expressions nd Trnsition Digrms 17

Finite Automton Finite Accepter Input Input String String Finite Automton Output String Finite Automton Output Accept or Reject Trnsition Grph A -Finite Accepter Initil Configurtion Input String initil stte stte trnsition finl stte ccept

Reding the Input

Input finished String Rejection Output: ccept

Input finished Output: reject The Empty String " " Output: reject Would it e possile to ccept the empty string?

Another Exmple,,,,

Input finished Rejection Output: ccept,,,,

Input finished Which strings re ccepted?,, Output: reject Formlities Q Deterministic Finite Accepter (DFA)!! F ( Q ",!, q F) M =, : set of sttes : input lphet, 0 : trnsition function : initil stte : set of finl sttes Input Alphet!! = { }

Set of Sttes Q = { q, q, q, q, q q } 0 1 2 3 4, 5 Q Initil Stte Set of Finl Sttes F = { } q 4 F Trnsition Function! $ : Q # "! Q q 4

! (, ) = q 1! (, ) = q 1 Trnsition Function!! ( q ) = 3 2, q! q q 1 q 2 q 3 q 4 5 q5 q5 q5

Trnsition Digrms Definition - A finite utomt specilized for lexicl nlysis Initil Configurtion Input String $ Differences from finite stte utomt - Finding more thn one string in single input strem - Do not ccept until hit chrcter with no out trnsition - Asterisk nottion indictes the need to put lst chrcter ck in input - Do not show sink sttes CS453 Lecture Regulr Expressions nd Trnsition Digrms 54 $ $ token Recognize token when ttempt to process 3 rd

$ $ token token token ws * $ $ token ws * ws *

Demonstrtion of Longest Mtch nd Priority $ token ws * CS453 Lecture Lexicl Anlysis with JLex 63