Consider the following non-deterministic finite state machine M:
Note: in the diagram ε is denoted using $.
What is L(M), i.e., the language defined by M?
For each state S in M, determine eclose(S).
Convert the NFA M to an equivalent NFA M* containing no ε-transitions.
Convert your NFA M* containing no ε-transitions from Part c to an equivalent DFA M**. Make sure to optimize M** to remove any unreachable or dead states.
Java (as well as C and C++) allows comments delimited by "/*
" and "*/
".
This kind of comment can be defined in English as follows:
A comment consists of three parts:
a slash followed by a star, followed by
The body of the comment can be empty, or can contain any characters except
the two-character sequence "*/
".
Note that the body of a comment can include stars and slashes, just not "*/
".
Assume that the following JLex macros have been defined:
SLASH = [/] STAR = [*]
Below are 5 incorrect JLex patterns for the kind of comment defined above. For each pattern, explain what is wrong. For example, you might say The pattern does not allow the comment body to include stars, or The pattern does allow the comment body to include */. If the pattern both disallows some "good" comments and allows some "bad" comments, give two explanations, one for each problem with the pattern. Then, for each problem with the pattern, give a string that illustrates the problem; i.e., give a string that is not matched by the pattern but is a "good" comment and/or give a string that is matched by the pattern but is a "bad" comment. Be sure that it is clear whether your example strings are intended to be "good" or "bad" comments.
{SLASH}{STAR}[^(*/)]*{STAR}{SLASH} {SLASH}{STAR}(.)*{STAR}{SLASH} {SLASH}{STAR}([^*]*{STAR}+[^*/])*{STAR}+{SLASH} {SLASH}{STAR}([^*]|[^/])+{STAR}{SLASH} {SLASH}{STAR}[^*]*{STAR}+{SLASH}+
Give a correct JLex pattern for comments as defined above. You may define and use additional macros. Make your pattern as readable as possible.
Last Updated: 2/5/2024 © 2024 CS 536