Basic technologies. Lexical analysis. Lexical analysis. Basic technologies. Syntactical analysis Parser generators Rewrite engines

Similar documents
Homework 3 Solutions

One Minute To Learn Programming: Finite Automata

flex Regular Expressions and Lexical Scanning Regular Expressions and flex Examples on Alphabet A = {a,b} (Standard) Regular Expressions on Alphabet A

Regular Sets and Expressions

Java CUP. Java CUP Specifications. User Code Additions You may define Java code to be included within the generated parser:

A Visual and Interactive Input abb Automata. Theory Course with JFLAP 4.0

Solutions for Selected Exercises from Introduction to Compiler Design

Newton-Raphson Method of Solving a Nonlinear Equation Autar Kaw

Solution to Problem Set 1

FORMAL LANGUAGES, AUTOMATA AND THEORY OF COMPUTATION EXERCISES ON REGULAR LANGUAGES

Unambiguous Recognizable Two-dimensional Languages

Boolean Algebra. ECE 152A Winter 2012

AntiSpyware Enterprise Module 8.5

Regular Languages and Finite Automata

Binary Representation of Numbers Autar Kaw

5 a LAN 6 a gateway 7 a modem

Reasoning to Solve Equations and Inequalities

Bypassing Space Explosion in Regular Expression Matching for Network Intrusion Detection and Prevention Systems

Pointed Regular Expressions

Regular Repair of Specifications

MATH 150 HOMEWORK 4 SOLUTIONS

Modular Generic Verification of LTL Properties for Aspects

1.00/1.001 Introduction to Computers and Engineering Problem Solving Fall Final Exam

and thus, they are similar. If k = 3 then the Jordan form of both matrices is

Example 27.1 Draw a Venn diagram to show the relationship between counting numbers, whole numbers, integers, and rational numbers.

WHAT HAPPENS WHEN YOU MIX COMPLEX NUMBERS WITH PRIME NUMBERS?

Mathematics. Vectors. hsn.uk.net. Higher. Contents. Vectors 128 HSN23100

Appendix D: Completing the Square and the Quadratic Formula. In Appendix A, two special cases of expanding brackets were considered:

Two hours UNIVERSITY OF MANCHESTER SCHOOL OF COMPUTER SCIENCE. Date: Friday 16 th May Time: 14:00 16:00

Lecture 3 Gaussian Probability Distribution

Engineer-to-Engineer Note

License Manager Installation and Setup

Lecture 5. Inner Product

Scanner. tokens scanner parser IR. source code. errors

DATABASDESIGN FÖR INGENJÖRER F

FAULT TREES AND RELIABILITY BLOCK DIAGRAMS. Harry G. Kwatny. Department of Mechanical Engineering & Mechanics Drexel University

Section 5-4 Trigonometric Functions

2 DIODE CLIPPING and CLAMPING CIRCUITS

Generating In-Line Monitors For Rabin Automata

Concept Formation Using Graph Grammars

Automated Grading of DFA Constructions

Graphs on Logarithmic and Semilogarithmic Paper

Automata theory. An algorithmic approach. Lecture Notes. Javier Esparza

CS99S Laboratory 2 Preparation Copyright W. J. Dally 2001 October 1, 2001

Warm-up for Differential Calculus

Quick Reference Guide: One-time Account Update

Bayesian Updating with Continuous Priors Class 13, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

Math 135 Circles and Completing the Square Examples

Use Geometry Expressions to create a more complex locus of points. Find evidence for equivalence using Geometry Expressions.

Protocol Analysis / Analysis of Software Artifacts Kevin Bierhoff

Integration by Substitution

Angles 2.1. Exercise Find the size of the lettered angles. Give reasons for your answers. a) b) c) Example

9.3. The Scalar Product. Introduction. Prerequisites. Learning Outcomes

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

KEY SKILLS INFORMATION TECHNOLOGY Level 3. Question Paper. 29 January 9 February 2001

Words Symbols Diagram. abcde. a + b + c + d + e

LINEAR TRANSFORMATIONS AND THEIR REPRESENTING MATRICES

! What can a computer do? ! What can a computer do with limited resources? ! Don't talk about specific machines or problems.

6.2 Volumes of Revolution: The Disk Method

Chapter. Contents: A Constructing decimal numbers

Incorporating Negative Values in AHP Using Rule- Based Scoring Methodology for Ranking of Sustainable Chemical Process Design Options

String Searching. String Search. Spam Filtering. String Search

Engineer-to-Engineer Note

On the expressive power of temporal logic

0.1 Basic Set Theory and Interval Notation

OUTLINE SYSTEM-ON-CHIP DESIGN. GETTING STARTED WITH VHDL August 31, 2015 GAJSKI S Y-CHART (1983) TOP-DOWN DESIGN (1)

Application for the Utah State Office of Education Secondary Science Endorsement

Outline of the Lecture. Software Testing. Unit & Integration Testing. Components. Lecture Notes 3 (of 4)

Data Compression. Lossless And Lossy Compression

the machine and check the components

Irregular Repeat Accumulate Codes 1

Fuzzy Clustering for TV Program Classification

1. Introduction Texts and their processing

Learning Workflow Petri Nets

Three-Phase Induction Generator Feeding a Single-Phase Electrical Distribution System - Time Domain Mathematical Model

Implementation of Boolean Functions through Multiplexers with the Help of Shannon Expansion Theorem

Vendor Rating for Service Desk Selection

PROF. BOYAN KOSTADINOV NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY

Experiment 6: Friction

Complexity Results in Epistemic Planning

Resistive Network Analysis. The Node Voltage Method - 1

NQF Level: 2 US No: 7480

Virtual Machine. Part II: Program Control. Building a Modern Computer From First Principles.

Helicopter Theme and Variations

RIGHT TRIANGLES AND THE PYTHAGOREAN TRIPLETS

Positive Integral Operators With Analytic Kernels

Example A rectangular box without lid is to be made from a square cardboard of sides 18 cm by cutting equal squares from each corner and then folding

Algebra Review. How well do you remember your algebra?

How fast can we sort? Sorting. Decision-tree model. Decision-tree for insertion sort Sort a 1, a 2, a 3. CS Spring 2009

Ratio and Proportion

Vectors. The magnitude of a vector is its length, which can be determined by Pythagoras Theorem. The magnitude of a is written as a.

Unit 6: Exponents and Radicals

Lec 2: Gates and Logic

Orbits and Kepler s Laws

Vectors Recap of vectors

Lesson 4.1 Triangle Sum Conjecture

Treatment Spring Late Summer Fall Mean = 1.33 Mean = 4.88 Mean = 3.

CS 316: Gates and Logic

Quick Guide to Lisp Implementation

Transcription:

Bsc technologes Generc Lnguge Technology: Bsc technologes Pro.dr. Mrk vn den Brnd Syntctcl nlyss Prser genertors Rewrte engnes / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 1 Tsks nd orgnzton o lexcl nlyzer Speccton o lexcl tokens v regulr expressons Implementton o regulr expressons (non-)determnstc nte utomt trnslton o regulr expresson to utomton progrm text (chrcters) Lexcl nlyzer Syntctcl nlyss get next token token prse tree Prser Symol tle / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 2 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 3

Flotng pont numers Tsks o the lexcl nlyzer: redng the nput nd producton o tokens elmnton o lyout nd comments keepng trck o poston normton lexcl l syntx [0] ([1-9][0-9]*) -> UnsgnedInt [\+\-]?\ UnsgnedInt -> SgnedInt UnsgnedInt "." [0-9]+ ([ee] SgnedInt)? -> UnsgnedRel UnsgnedInt [ee] SgnedInt -> UnsgnedRel UnsgnedInt UnsgnedRel -> Numer 0 1 14 0.1 3e4 3.014e-7 00 01 04.1 3e04 3.14e-07 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 4 Pge 5 A regulr expresson (r.e.) r over n lphet Σ corresponds to the lnguge L(r) 1. s r.e. nd corresponds to {} 2. Σ s r.e. nd corresponds to {} 3. Suppose r nd s re r.e. s correspondng to the lnguges L(r) nd L(s). lterntve (r) (s) s r.e. L(r) L(s). conctenton (r) (s) s r.e. L(r) L(s) c. Kleene closure (r)* s r.e. (L(r))* d. rckets (r) s r.e. L(r) Opertors re let-ssoctve nd prortes re * > conctenton > A regulr denton over lphet Σ hs the orm: re 1 -> d 1 re 2 -> d 2 re n -> d n where d re derent nmes nd ech re s r.e. over lphet Σ {d 1, d 2,, d -1 } Thus, n re occur only nmes whch re lredy dened / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 6 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 7

A regulr expresson cn e compled nto nte utomton (FA = nte utomton) whch s recognzer or the correspondng regulr lnguge A nte utomton s non-determnstc severl derent trnstons re possle or one nput symol n stte (NFA) There re two possle wys o trnsormng r.e. nto determnstc nte utomton: 1. r.e. NFA DFA 2. re r.e. DFA The generted DFA hs to e optmzed Otherwse the nte utomton s determnstc (DFA) / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 8 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 9 Non-determnstc nte utomton conssts o: 1. Set o sttes S 2. Input lphet Σ 3. Trnston uncton whch tkes stte/symol pr nd yelds set o new sttes 4. The strt stte s 0 S 5. A set F o cceptng sttes Exmple: S = {0,1,2,3} Σ = {, } S 0 = 0 F = {3} Ths utomton ccepts: ( )* Trnston uncton: Stte 0 {0,1} {0} 1 {2} 2 {3} / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 10 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 11

Trnstons my lso e lelled wth 1 2 0 3 4 NFA ccepts strng x There exsts pth n the trnston dgrm rom strt to nl stte such tht the conctenton o the lels on the pth equl x For exmple s ccepted y the prevous NFA Pth: 0 1 2 2 2 Lels: = The regulr expresson s: * * / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 12 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 13 Regulr expresson NFA Input: regulr expresson r over lphet Σ Output: NFA N whch ccepts L(r) 1. r = 2. r = where Σ 1. Suppose N(s) nd N(t) re NFAs or the r.e. s nd t. r = s t. r=st N(s) N(s) N(t) N(t) Ths operton s only possle the nl stte o N(s) hs no outgong trnstons nd the strt stte o N(t) hs no ncomng trnstons / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 14 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 15

c. r = s* N(s) d. r =(s) thenn(r) =N(s) Converson NFA DFA Regulr expresson cn e trnsormed nto NFAs DFAs cn e smulted/mplemented ecently Trnsormton o NFA nto DFA: construct DFA where ech stte represents suset o the sttes o the sttes o the NFA ter redng the nput 1 2 n the NFA s n set o sttes T, whch corresponds to one stte o the DFA / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 16 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 17 Auxlry unctons: -closure(s) yelds set o NFA sttes rechle rom stte s n NFA v -trnstons only -closure(t) yelds set o NFA sttes rechle rom stte s n T v -trnstons only move(t, ) yelds set o NFA sttes rechle rom stte s n T v nput Intlly, -closure(s 0 ) s the only stte n Dsttes nd unmrked whle there s n unmrked stte T n Dsttes do mrk T; or ech nput symol do U := -closure(move(t, )) U s not n Dsttes then dd U s n unmrked stte to Dsttes; end Dtrns[T,] := U; end end / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 18 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 19

Suset constructon (Rn & Scott) NFA = (Q, V, γ, q 0, F) NFA N or ( )* Equvlent DFA = (P(Q), V, δ, {q 0 }, F ) ) δ P(Q) V P(Q) δ(qq, ) ) = ( q:q qq : γ(q, ( )) F = {qq P(Q) qq F } δ({q 0 }, w) = set o ll sttes n whch the orgnl NFA cn e ter processng strng w 2 3 0 1 6 7 8 9 10 4 5 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 20 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 21 A = {0, 1, 4, 5, 7} (= -closure(0)) B = {1, 2, 3, 4, 6, 7, 8} (= move({0, 1, 4, 5, 7}, )) C = {1, 2, 4, 5, 6, 7} (= move({0, 1, 4, 5, 7}, )) D = {1,2,4,5,6,7,9}(= move({1, 2, 3, 4, 6, 7, 8}, )) E = {1, 2, 4, 5, 6, 7, 10} (= move({1, 2, 3, 4, 6, 7, 9}, )) Resultng DFA A B D E Trnston tle stte A B C B B D C B C D B E E B C C / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 22 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 23

DFA mnml DFA (MDFA) DFA = (Q, V, δ, q 0, F) equvlence relton on sttes; or ll s, t Q s t ( w : w V* : δ(s,w) F δ(t,w) F) Denton (equvlence clss o stte q) Q P(Q) ( q : q Q : (q) ={q q q } Prttonng stte set Q ccordng to relton yelds stte set Q whch s used n the mnml DFA (MDFA) (Q, V, δ, (q 0 ), F ) where ( s, : s V:δ ( (s),)) = (δ(s,)) F = { () F} LEX s scnner genertor whch trnsorms regulr expressons nto nte utomton: r.e. NFA re 0 {cton 0 } re 1 {cton 1 } 0 0 re k {cton k } strt F = { 0,, k } NFA DFA cceptng sttes hve the orm {,,,,, c, } wth correspondng cton: cton mn(,,c) k k / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 24 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 25 Implementton exmples cn e ound n Secton 3.3.2 o http://www.wn.tue.nl/~mvdrnd/courses/glt/0910/ ppers/notes.pdpd Resoluton o mgutes Longest mtch s preerred I two lterntves recognze the sme sequence o chrcters, the lterntve occurrng rst n the speccton s chosen BEGIN [sym := egnsym] IF [sym := sym] letter.(letter dgt)* [sym := dsym] dgt.(dgt)* t t [sym := ntrepsym] := [sym := ecomessym] / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 26 / Fcultet Wskunde en Inormtc 2-9-2010 PAGE 27