
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Examples of finite-state machines and regular expressions to recognize decimal and hexadecimal constants, as well as semicolon-separated lists of a's and b's in square brackets. It also includes an ocamllex specification for tokens of a specific type.
Typology: Exams
1 / 1
This page cannot be seen from the preview
Don't miss anything!

(a) Write a finite-state machine to recognize either decimal or hexadecimal constants. Label each state with either S (start state), D (decimal constant), H (hexadecimal constant), or N (neither).
(b) Write a regular expression to recognize either a decimal or hexadecimal constant.
(a) a(a|b)*
(b) aab(b|a)
(c) (b|a)aab(b|a)*
(b) Then write a finite-state machine for the language. Each state should be labeled either as S (for the start state), A (for an accepting state), or E (for an error state).
type token = LESSTHAN | LEFTSHIFT | LEFTSHIFTEQ | IDENT of string
where these represent, respectively, the sequence โ<โ, โ<<โ, โ<<=โ, and any string starting with a letter and consisting solely of letters and digits. Your specification should return the next token in the input, ignoring any character other than the ones that constitute tokens.