Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Scanner Develop a scanner that will recognize the list of keywords shown in the following section. Use the finite state machine / table approach described
Scanner Develop a scanner that will recognize the list of keywords shown in the following section. Use the finite state machine / table approach described in class. Your scanner should be implemented as an object; the nexttoken() function should be a member function; the table should be a private data structure within the object. Each time the nexttoken () function is called, it should return the next token in the input stream; when no more text remains in the input stream, it should return an EOF indicator. Your scanner should skip space characters (tab, space, and newline). Write a test program to call the nexttoken (). It should accept input from STDIN, and output to STDOUT, and continue until the scanner function returns an EOF. The test program should output a text label for each token recognized in the input stream, one token per line. Tokens to Recognize Here is the list of tokens to recognize, and the labels to print when each token is recogniz Your scanner should not be case sensitive. In other words, it should recognize "array", "ARRAY", or even "ArRAy." Coding trick: Suppose your scanner recognizes word - anything that starts with a letter and contains a sequence of letters and digits. If you find a word, you can then look it up in a table to see if it is one of the special tokens. This will make your state transition table a lot simpler, but it will not perform as well as the purely table-driven scanner, because you'll need an extra lookup. The choice is yours, but please document it. C++ Coding suggestion Create an enumerated type to represent the token types. Write an output function (or override an output operator) to print the labels. A test input file called test-in.txt, containing at least 20 and no more than 50 tokens. An output file called test-out.text produced by your program in response to the test input
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started