Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Consider a natural language called Nihonglish with the vocabulary of English but a different grammar. - The grammar of Nihonglish does not have have prepositions
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 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.)
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