Purpose: To go over: Recursive descent parsers Overview: Finish my C++ program t
ID: 3704253 • Letter: P
Question
Purpose:
To go over:
Recursive descent parsers
Overview:
Finish my C++ program that implements a recursive-descent parser of a simple language of cleaning one's house in English. The language can handle:
Mop the bathroom.
Wash the dishes.
Wash the dishes pots windows.
Wash the dishes pots windows. Mop the kitchen bathroom. Vacuum the bedroom foyer.
etc.
Assignment:
Please copy and paste the following:
Please finish parseWashVerb():
It should recognize (and then delete()) the tokens for WASH_KEYWORD_SYM and SCRUB_KEYWORD_SYM.
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
throw "Expected "wash" or "scrub"";
Please finish parseRoomVerb():
It should recognize (and then delete()) the tokens for VACUUM_KEYWORD_SYM, SWEEP_KEYWORD_SYM and MOP_KEYWORD_SYM.
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
throw "Expected "vacuum", "sweep", "mop" or end";
Please finish parseWashItem():
It should recognize (and then delete()) the tokens for DISHES_KEYWORD_SYM, POTS_KEYWORD_SYM, WINDOWS_KEYWORD_SYM, SINK_KEYWORD_SYM, TOILET_KEYWORD_SYM, and SHOWER_KEYWORD_SYM.
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
Please finish parseWashList():
It should recognize grammar rules 8 and 9 above.
Please finish parseRoomItem():
It should recognize (and then delete()) the tokens for HALL_KEYWORD_SYM, BEDROOM_KEYWORD_SYM, BATHROOM_KEYWORD_SYM, KITCHEN_KEYWORD_SYM, and FOYER_KEYWORD_SYM.
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
Please finish parseRoomList():
It should recognize grammar rules 10 and 11 above.
Please finish parseWashSentence():
It should recognize grammar rule 4 above. WS -> WV the WL period
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
throw "Expected "the"";
throw "Expected "."";
throw "Expected "wash" or "scrub"";
Please finish parseRoomSentence():
It should recognize grammar rule 5 above. RS -> RV the RL period
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
throw "Expected "the"";
throw "Expected "."";
throw "Expected "wash" or "scrub"";
Please finish parseS():
(Done for you.)
Hints:
If the same non-terminal is on the right-hand-side, then that means a recursive call to the same function.
The methods you have to help you are:
Sample output:
If the program successfully parses the output it prints
Otherwise it should print an error message that describes the problem.
Method: Function: tokenizer.peek() It returns the symbol_ty value for the next symbol on the input stream, without changing the input stream. When you reach the end of input it returns the value END_OF_INPUT_SYM. tokenizer.advance() It returns a pointer to the instance of Symbol that was next in the token stream, and internally goes to the next symbol. Once you are thru with them, all Symbol instances should be delete()d. getType() of Symbol It tells what type of symbol you have, which is one of the constants of symbol_ty. mypager This utility displays the contents of a file as ASCII characters, one "page" at at time. By default, a page is equivalent to at most 20 lines of text, each line not having more than 80 characters displayed. It is, essentially, a crude version of the less Unix file utility. Following are the specifications: 1. The usage of mypager is as follows: mypager ?file name> 2. When started, it displays the first page of text, meaning up to 20 lines of text from the file, each line having 80 characters or less. 3. It then waits for user input. If the user presses the 'f' key, then the next page is displayed. If the user presses the 'q' key, then the utility quits. This user input code has already been written and is included within the main function. 4. You will be supplied with an incomplete version of mypager.c that does not actually display any text. You are to modify several functions within mypager.c in order to make it work correctly. Specifically, you must revise three (3) functions, as follows: - fetch next line: this function retrieves the next line of text by repeatedly calling fetch_next_word; see mypager.c for more details - fetch_next_word: this function retrieves the next word of text by reading bytes from a buffer, see mypager.c for more details refill_buffer: this function refills the buffer with bytes read from the file; see mypager.c for more details 5. You may not revise or add any other functionsExplanation / Answer
Please finish parseWashVerb():
It should recognize (and then delete()) the tokens for WASH_KEYWORD_SYM and SCRUB_KEYWORD_SYM.
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
throw "Expected "wash" or "scrub"";
Please finish parseRoomVerb():
It should recognize (and then delete()) the tokens for VACUUM_KEYWORD_SYM, SWEEP_KEYWORD_SYM and MOP_KEYWORD_SYM.
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
throw "Expected "vacuum", "sweep", "mop" or end";
Please finish parseWashItem():
It should recognize (and then delete()) the tokens for DISHES_KEYWORD_SYM, POTS_KEYWORD_SYM, WINDOWS_KEYWORD_SYM, SINK_KEYWORD_SYM, TOILET_KEYWORD_SYM, and SHOWER_KEYWORD_SYM.
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
Please finish parseWashList():
It should recognize grammar rules 8 and 9 above.
Please finish parseRoomItem():
It should recognize (and then delete()) the tokens for HALL_KEYWORD_SYM, BEDROOM_KEYWORD_SYM, BATHROOM_KEYWORD_SYM, KITCHEN_KEYWORD_SYM, and FOYER_KEYWORD_SYM.
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
Please finish parseRoomList():
It should recognize grammar rules 10 and 11 above.
Please finish parseWashSentence():
It should recognize grammar rule 4 above. WS -> WV the WL period
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
throw "Expected "the"";
throw "Expected "."";
throw "Expected "wash" or "scrub"";
Please finish parseRoomSentence():
It should recognize grammar rule 5 above. RS -> RV the RL period
If you detect an error then simply throw a string that describes the problem. In my code I had the following:
throw "Expected "the"";
throw "Expected "."";
throw "Expected "wash" or "scrub"";
Please finish parseS():
(Done for you.)
Hints:
If the same non-terminal is on the right-hand-side, then that means a recursive call to the same function.
The methods you have to help you are:
Sample output:
If the program successfully parses the output it prints
Otherwise it should print an error message that describes the problem.
Method: Function: tokenizer.peek() It returns the symbol_ty value for the next symbol on the input stream, without changing the input stream. When you reach the end of input it returns the value END_OF_INPUT_SYM. tokenizer.advance() It returns a pointer to the instance of Symbol that was next in the token stream, and internally goes to the next symbol. Once you are thru with them, all Symbol instances should be delete()d. getType() of Symbol It tells what type of symbol you have, which is one of the constants of symbol_ty.Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.