I have a couple of exam questions for my compilers class and wanted to check if my solutions are correct.
The first question is:
Consider a language in which numbers start with an optional minus sign, followed by one or more decimal digits, followed by an optional decimal point. If the number contains a decimal point it is followed by one or more further decimal digits. Express the syntax of numbers in this language as a regular expression.
And for my answer:
("-")? ["0"-"9"]+ ("."["0"-"9"]+)?
The second question is:
Construct a deterministic ﬁnite state automaton for recognising the numbers as described in Question 1
And my answer is:
Where state 2,4,5 and 6 are terminals.
Are these solutions correct? I am unsure of what the DFA should look like and it's differences to an NFA.