Question: Create a Finite State Machine from the following regular Grammar in C++ using a 2D array or enum or vector or map without using if/else

Create a Finite State Machine from the following regular Grammar in C++ using a 2D array or enum or vector or map without using if/else or switch statements.

We need to implement a lexical analyzer which is able to recognize octal and decimal numbers with the following requirements. An input number starts with a + or - sign. An octal number starts with a 0 and can continue with an arbitrarily number of digits. An octal number started with more than one 0 is not an acceptable number. Note: digits used in an octal number are between 0 and 7. A decimal number starts with any digit except 0 and can continue with an arbitrarily number of digits. Note: digits used in a decimal number are between 0 and 9. 0 is an acceptable number, no matter whether we accept it as a decimal or as an octal number.

Here is the sample input: +0 -03489 -00 +9803467 -184 -04650 + -034-21 Here is the sample output: Accepted: +0 Rejected: -03489 Rejected: -00 Accepted: +9803467 Accepted: -184 Accepted: -04650 Rejected: + Rejected: -034-21

S-> +A | -A A-> 0B|CD C->1|2|3|4|5|6|7|8|9 D-> 0D|CD| C |F |0 B-> F | FE F-> 1|2|3|4|5|6|7 E->FE|0E|0|F|E

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!