Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ONLY ANSWER #3 Please only update the two files nihonglish.lex and nihonglish.y. All needed files are attached. This is ONE question so please answer it
ONLY ANSWER #3 Please only update the two files nihonglish.lex and nihonglish.y. All needed files are attached. This is ONE question so please answer it completely and I will upvote.
Given Grammer Rules:
makefile:
nihonglish.lex:
nihonglish.y:
Phrase.h:
Sentence.h:
Finish both the lexicographic rules in nihonglish. lex to make it recognize the relevant English words, and the grammar rules in nihonglish.y to parse Nihonglish. I have already already defined the sunion for you. But you have to: a. Define the terminals and non-terminals, and give them types in nihonglish.y. b. Define lexeme rules in nihonglish. lex. c. Define grammar rules in nihonglish.y. What this program does is restate the Nihonglish sentences into ordinary English: $.ihonglish please enter a sentence: I as for store to going. I am going to the store. $.ihonglish please enter a sentence: store to going? Are you going the store? $.ihonglish please enter a sentence: You as for home to going. You are going to home. $.ihonglish Please enter a sentence: Home to going. I am going to home. So let us go! a. nihonglish.y: 1. Stop! Think! What are the non-terminals that you want to represent? What are the terminals that you want to represent? You should not handle productions 6,7,9 and 10 in the grammar. Instead, when nihonglish. lex recognizes "I" or "you" have it return() a terminal representing T. Likewise, when nihonglish. lex recognizes "home" or "store" have it return() a terminal representing L. 2. On the line \&start // YOUR STARTING SYMBOL HERE erase the comment and replace it with your starting non-terminal. 3. Just below that we need to define the terminals and non-terminals, and then give them their types. - There are several terminals in the grammar. Terminal for T should have type strptr_, and the terminal for L should also have type strptr_. - The non-terminals for PP, PPL and s should have type nodeptr.. b. nihonglish. lex: 1. Delete // YOUR CODE HERE and add your rules after that. 2. Ignore spaces, tabs and newlines. 3. Recognize the terminals, in both lowercase and capitalized forms. 4. When recognizing the English 1 st person pronoun " I ", do this: tstart // YOUR STARTING SYMBOL HERE erase the comment and replace it with your starting non-terminal. 3. Just below that we need to define the terminals and non-terminals, and then give them their types. - There are several terminals in the grammar. Terminal for T should have type strptr_, and the terminal for L should also have type strPtr_. - The non-terminals for PP, PPL and s should have type nodePtr.. b. nihonglish. lex: 1. Delete // YOUR CODE HERE and add your rules after that. 2. Ignore spaces, tabs and newlines. 3. Recognize the terminals, in both lowercase and capitalized forms. 4. When recognizing the English 1st person pronoun " I ", do this: yYlval.strPtr_ = new std:string("I"); (Of course, you should also return() your terminal representing T.) 5. When recognizing "you", do this: yylval.strptr_ = new std: string("you"); (Of course, you should also return() your terminal representing T.) 6. When recognizing "home", do this: yYlval.strptr_ = new std:string("home"); (Of course, you should also return() your terminal representing L.) 7. When recognizing "store", do this: yYlval.strptr_ = new std:string("store"); (Of course, you should also return() your terminal representing L.) c. Back to nihonglish. Y: Time to define the grammar! Do this just under this line: //Rulesstarthere: 1. Production 8 should make the value associated with left hand side non-terminal equal to new Tophrase (something), where something represents the value associated with the L. 2. Production 5 should make the value associated with left hand side non-terminal equal to new Topicphrase(something), where something represents the value associated with the T. 3. Production 4 should - Use the attach() method of class phrase attach the 2nd pp to the first pp - make the value associated with left hand side non-terminal equal to the value associated with the 1st pP 4. Production 3 should make the value associated with left hand side non-terminal equal to the value associated with the 1 st (and only) pp 5. Production 2 should set global variable sentenceptr equal to new Sentence (something, true), where something is the value associated with ppL. (The true means that the sentence is a question.) 6. Production 1 should set global variable sentenceptr equal to new Sentence(something, false), where something is the value associated with pPL. (The false means that the sentence is a declarative sentence.) Consider a natural language called Nihonglish with the vocabulary of English but a different grammar. - The grammar of Nihonglish does not have have prepositions or prepositional phrases. Instead, it has postpositions and postpositional phrases. - The topic of the sentence (often times the subject), has its own post-position: "as for" - the verb comes at the end. The English sentence: I am going home. is rendered in Nihonglish as: I as for home to going. And the question Are you going to the store? is rendered in Nihonglish as: You as for store to going? or more succinctly: Store to going? Our subset of Nihonglish has these non-terminals: and these grammatical rules: 1. S> PPL going period 2. S PPL going question_mark 3. PPLPP 4. PPL PP PP 5. PPT as for 6. Ti (The English 1st person pronoun " I ") 7. T> you 8. PPL to 9. L> home 10.L store M Makefile C Phrase.h > I/ VI. Mutators: II PURPOSE: To nake "nextPtr" the phrase after "*this' one. // No return value. virtual void attach (Phrases nextPtr 1=Bi 31 I/ PURPOSE: To represent phrase telling where to. class ToPhrase : public Phrase \{ Il I. Menber vars: I/ PURPOSE: To hold the location. stdiastring strizi I/ PURP05E: To hold the next phrase in the list, if there is one. Phrase* nextPtr_; I/ II. Disallowed auto-generated nethods: // No default constructor: ToPhrase (l; I/ No copy constructor: ToPhrase (const ToPhraset source 1 is I/ No copy assignnent op: ToPhrases operator= (const ToPhrasek source Ii protected : I/ III. Protected nethods: public : I/ IV. Constructor(s), assignnent op(s), factory(s) and destructor: I/ PURPOSE: To nake a phrase the represents "to *newstrptr". l/ No return value. ToPhrase (stdistring* newstrptr I: Phrase(l). str_(*newStrptr), nextPtr_(NULL) \{ delete(new5trptr); 3 I/ PURPOSE: To release the resources of '*this'. No parameters. No I/ return value. ToPhrase ()
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