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