Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Report. The report consists of four components. 1) Specify the important data structure(s) you will use in your scanner algorithm. The speci- fication should be

image text in transcribed

image text in transcribed

Report. The report consists of four components. 1) Specify the important data structure(s) you will use in your scanner algorithm. The speci- fication should be independent of any specific programming language such as JAVA. Here is an example of specifying a data structure. To specify a data structure for the table in Fig 2.12 in the textbook, we need the following data structure with a name transitionTable. transitionTable is a two dimensional ar- ray. The first dimension is indexed from 1 to 18 (the number of states) and the second dimension is indexed from 1 to 14 with 1 representing white spaces (space, tab, newline), 2 representing the character /,.,14 representing any letter. For any integer i and j, transitionTable[0][] is a record with field names action and newState. action can take values of move, recognize, stuck. transitionTable[1][].action=move means that the automata should move to next state and transitionTable[1][].newState is the state to move to. transitionTable[0[].move = recognize means that i is a final state and the automata can not move to any other state with the input character corresponding to the number j, i.e., we recognize a token! transitionTabletu].move = stuck means that the the automata can nol gel lo any slale from slate iwith a character corresponding to the number j. 2) The pseudo-code. For each function in your pseudo-code, you MUST have input, output and how output is related to input. As for pseudocode statements you should use to describe your algorithm, please refer to those in Fig 2.11 and the sample pseudo-code given on our website. The principle is not to use statements in a specific language such as JAVA, but your statements are still precise and understandable by a student who has taken CS1411, i.e., has basic knowledge about programming. Note that in your pseudo-code, you can use statement such If transitionTable[0]).action is move. Your pseudo-code should cover the major idea how you recognize a token, reflect the longest possible" principle to find a token, how the tokens read and write are recognized etc. 3) The test cases to test the correctness of your program with explanation why you select them. 4) Acknowledgment of people and their contribution to your project. Implementation. As for implementation (program), the minimal expectation is a finished im- plementation which means the source code is compilable to an executable and the executable behaves correctly at least most of the time. Here is the task: write a scanner using an imperative language: C/C++ (in this option, your program must be compilable using goc or g++.), Java and Python. Your program must have the scan function. Its precondition is that the current pointer of the input file is NOT at the end of file (EOF). It scans from the current pointer of the input file and stops when either a valid token or invalid token can be decided. In the case of a valid token, scan returns the token type (i.e., the left hand side symbol of the corresponding production rule. E.g., for production rule id -> letter letter, the token type of an input "abc" would be id); otherwise, it returns an error flag. Note here when deciding a token you must use the "longest possible token" rule. Your scanner should also deal with the read and write token correctly. The scanner takes the name of a text file from the command line. It outputs to the console errorif there is any non-valid token in the input file; the list of tokens otherwise. Your implementation should be based on the automata in on Page 54 of the textbook. Commandline Invocation: scanner If there is any non-token string in the input file, your program should exit and output to the console only: error. Otherwise, your program outputs only the list of tokens in the form of (tokeni, token2, Example Input File: foo.txt with the following content: read /* foo bar */ five 5 Example Commandline: scanner foo.txt Example Output: (read, times, id, number). Note that your scanner does NOT output the token of comment. In fact, your function scan should completely ignore all comments in the input. In the example, the next token of times is id, instead of comment. Report. The report consists of four components. 1) Specify the important data structure(s) you will use in your scanner algorithm. The speci- fication should be independent of any specific programming language such as JAVA. Here is an example of specifying a data structure. To specify a data structure for the table in Fig 2.12 in the textbook, we need the following data structure with a name transitionTable. transitionTable is a two dimensional ar- ray. The first dimension is indexed from 1 to 18 (the number of states) and the second dimension is indexed from 1 to 14 with 1 representing white spaces (space, tab, newline), 2 representing the character /,.,14 representing any letter. For any integer i and j, transitionTable[0][] is a record with field names action and newState. action can take values of move, recognize, stuck. transitionTable[1][].action=move means that the automata should move to next state and transitionTable[1][].newState is the state to move to. transitionTable[0[].move = recognize means that i is a final state and the automata can not move to any other state with the input character corresponding to the number j, i.e., we recognize a token! transitionTabletu].move = stuck means that the the automata can nol gel lo any slale from slate iwith a character corresponding to the number j. 2) The pseudo-code. For each function in your pseudo-code, you MUST have input, output and how output is related to input. As for pseudocode statements you should use to describe your algorithm, please refer to those in Fig 2.11 and the sample pseudo-code given on our website. The principle is not to use statements in a specific language such as JAVA, but your statements are still precise and understandable by a student who has taken CS1411, i.e., has basic knowledge about programming. Note that in your pseudo-code, you can use statement such If transitionTable[0]).action is move. Your pseudo-code should cover the major idea how you recognize a token, reflect the longest possible" principle to find a token, how the tokens read and write are recognized etc. 3) The test cases to test the correctness of your program with explanation why you select them. 4) Acknowledgment of people and their contribution to your project. Implementation. As for implementation (program), the minimal expectation is a finished im- plementation which means the source code is compilable to an executable and the executable behaves correctly at least most of the time. Here is the task: write a scanner using an imperative language: C/C++ (in this option, your program must be compilable using goc or g++.), Java and Python. Your program must have the scan function. Its precondition is that the current pointer of the input file is NOT at the end of file (EOF). It scans from the current pointer of the input file and stops when either a valid token or invalid token can be decided. In the case of a valid token, scan returns the token type (i.e., the left hand side symbol of the corresponding production rule. E.g., for production rule id -> letter letter, the token type of an input "abc" would be id); otherwise, it returns an error flag. Note here when deciding a token you must use the "longest possible token" rule. Your scanner should also deal with the read and write token correctly. The scanner takes the name of a text file from the command line. It outputs to the console errorif there is any non-valid token in the input file; the list of tokens otherwise. Your implementation should be based on the automata in on Page 54 of the textbook. Commandline Invocation: scanner If there is any non-token string in the input file, your program should exit and output to the console only: error. Otherwise, your program outputs only the list of tokens in the form of (tokeni, token2, Example Input File: foo.txt with the following content: read /* foo bar */ five 5 Example Commandline: scanner foo.txt Example Output: (read, times, id, number). Note that your scanner does NOT output the token of comment. In fact, your function scan should completely ignore all comments in the input. In the example, the next token of times is id, instead of comment

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Samsung Galaxy S23 Ultra Comprehensive User Manual

Authors: Leo Scott

1st Edition

B0BVPBJK5Q, 979-8377286455

More Books

Students also viewed these Databases questions

Question

Do we have the resources to implement the solution?

Answered: 1 week ago

Question

Discuss the characteristics of emerging adulthood.

Answered: 1 week ago