Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Give nihonglish.jj both the tokens ( uppercase and lowercase ) of the English words, and the grammar rules to parse Nihonglish. I have already already
Give nihonglish.jj both the tokens uppercase and lowercase of the English words, and the grammar rules to parse Nihonglish.
I have already already given you the following classes and interfaces:
Sentence.java,
Phrase.java,
SubjectPhrase.java,
ToPhrase.java,
You have to:
Define the terminals they are called TOKENs in Javacc
Define the grammar rules in Nihonglish.jj
What this program does is restate the Nihonglish sentences into ordinary English:
$ javacc.sh Nihonglish.jj
Java Compiler Compiler Version Parser Generator
type "javacc" with no arguments for help
Reading from file Nihonglish.jj
File "TokenMgrError.java" is being rebuilt.
File "ParseException.java" is being rebuilt.
File "Token.java" is being rebuilt.
File "SimpleCharStream.java" is being rebuilt.
Parser generated successfully.
$ javac Nihonglish.java
$ java Nihonglish
Sentence to parse or to quit: I as for home to going.
I am going to home.
Sentence to parse or to quit: I as for home to going?
Am I going home?
Sentence to parse or to quit: Home to I as for going.
I am going to home.
Sentence to parse or to quit: Home to going.
I am going to home.
Sentence to parse or to quit: Store to going.
I am going to the store.
Sentence to parse or to quit: Store to you as for going.
You are going to the store.
Sentence to parse or to quit: You as for going?
Are you going?
Sentence to parse or to quit: You as for home to going.
You are going to home.
Sentence to parse or to quit: I just pressed "Enter"
So let us go
PARSERBEGINNihonglish
import java.util.;
import java.io;
public
class Nihonglish
public
static
String QUITCMD ;
static
Nihonglish parser null;
public
static
Sentence parse String parseMe
throws Exception
StringReader input new java.ioStringReaderparseMe;
if parser null
parser new Nihonglishinput;
else
parser.ReInitinput;
returnparsersentence;
public
static
void mainString args throws Exception
String parseMe;
Scanner input new ScannerSystemin;
while true
System.out.print
Sentence to parse or
QUITCMD
to quit:
;
parseMe input.nextLine;
if parseMe.equalsQUITCMD
break;
try
System.out.printlnparseparseMe;
catch Exception error
System.err.printlnerror;
PARSERENDNihonglish
SKIP: t
r
TOKEN: DELETE THIS AND DEFINE TOKENS HERE
Sentence sentence throws Exception :
Sentence sent;
Phrase phrase;
boolean isQuestion;
DELETE THIS AND ADD CODE HERE
returnnull DELETE null AND ADD CODE HERE ;
Phrase postpositphraselist throws Exception :
Phrase phrasest null;
Phrase phraseNth null;
DELETE THIS AND ADD CODE HERE
returnnull DELETE null AND ADD CODE HERE ;
Phrase postpositphrase throws Exception :
Phrase phrase null;
String who ;
String where ;
DELETE THIS AND ADD CODE HERE
returnnull DELETE null AND ADD CODE HERE ;
String who throws Exception :
String s;
DELETE THIS AND ADD CODE HERE
returnnull DELETE null AND ADD CODE HERE ;
String where throws Exception :
String s;
DELETE THIS AND ADD CODE HERE
returnnull DELETE null AND ADD CODE HERE ;
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