Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Match regular expressions using backtracing search Simple Regular Expressions with expl exp2, exp1 exp2, null string (epsilon), (end of string), dot (any single character), optional

image text in transcribed

image text in transcribed

Match regular expressions using backtracing search Simple Regular Expressions with expl exp2, exp1 exp2, null string (epsilon), (end of string), dot (any single character), optional expr (? exp), and Kleene star data RegExp Rnull e empty string epsilon s at end of string? | Rend | Rany I Rch Char I Ror RegExp RegExp any one character a specific character alternation Rand RegExp RegExp |Ropt RegExp | Rstar RegExp deriving (Eq, Show) concatenation ? optional expression Kleene star A match result ok str1 str2 means that strl matched the expression and str2 was leftover. Note strl ++ str2 should be the string passed to match. data Mresult-FAIL I OK String String deriving (Eq, Show) Match (Ror rl r2) string matches r1 against string and also r2 against string and fails if both fail, returns the successful result if exactly one succeeds and returns the result with the longer match if both succeed match (Ror rexp1 rexp2) str Match (Rand r1 r2) string matches r1 and (if it succeeds) matches r2 against the string leftover from rl.If r2 succeeds then the Rand returns the concatenation of the matches from rl and r2 match (Rand rexpl rexp2) str - Matching an optional expression is like matching (rexp Inull) match (Ropt rexp) str matching rexpx is like matching ((rexp rexpx) null), but to avoid infinite recursion, if rexp matches null, we stop with the base case (matching null) -we also stop with the base case if rexp fails to match. match (Rstar rexp) str Match regular expressions using backtracing search Simple Regular Expressions with expl exp2, exp1 exp2, null string (epsilon), (end of string), dot (any single character), optional expr (? exp), and Kleene star data RegExp Rnull e empty string epsilon s at end of string? | Rend | Rany I Rch Char I Ror RegExp RegExp any one character a specific character alternation Rand RegExp RegExp |Ropt RegExp | Rstar RegExp deriving (Eq, Show) concatenation ? optional expression Kleene star A match result ok str1 str2 means that strl matched the expression and str2 was leftover. Note strl ++ str2 should be the string passed to match. data Mresult-FAIL I OK String String deriving (Eq, Show) Match (Ror rl r2) string matches r1 against string and also r2 against string and fails if both fail, returns the successful result if exactly one succeeds and returns the result with the longer match if both succeed match (Ror rexp1 rexp2) str Match (Rand r1 r2) string matches r1 and (if it succeeds) matches r2 against the string leftover from rl.If r2 succeeds then the Rand returns the concatenation of the matches from rl and r2 match (Rand rexpl rexp2) str - Matching an optional expression is like matching (rexp Inull) match (Ropt rexp) str matching rexpx is like matching ((rexp rexpx) null), but to avoid infinite recursion, if rexp matches null, we stop with the base case (matching null) -we also stop with the base case if rexp fails to match. match (Rstar rexp) str

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions