Answered step by step
Verified Expert Solution
Link Copied!

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 5.0(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!
Nihonglish.jj:
PARSER_BEGIN(Nihonglish)
import java.util.*;
import java.io.*;
public
class Nihonglish
{
public
static
String QUIT_CMD ="";
static
Nihonglish parser = null;
public
static
Sentence parse (String parseMe
)
throws Exception
{
StringReader input = new java.io.StringReader(parseMe);
if (parser == null)
parser = new Nihonglish(input);
else
parser.ReInit(input);
return(parser.sentence());
}
public
static
void main(String[] args) throws Exception
{
String parseMe;
Scanner input = new Scanner(System.in);
while (true)
{
System.out.print
("Sentence to parse or \""+
QUIT_CMD +
"\" to quit: "
);
parseMe = input.nextLine();
if ( parseMe.equals(QUIT_CMD))
{
break;
}
try
{
System.out.println(parse(parseMe));
}
catch (Exception error)
{
System.err.println(error);
}
}
}
}
PARSER_END(Nihonglish)
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
{ return(null /* DELETE null AND ADD CODE HERE */); }
}
Phrase postposit_phrase_list () throws Exception :
{
Phrase phrase1st = null;
Phrase phraseNth = null;
}
{
// DELETE THIS AND ADD CODE HERE
{ return(null /* DELETE null AND ADD CODE HERE */); }
}
Phrase postposit_phrase () throws Exception :
{
Phrase phrase = null;
String who ="";
String where ="";
}
{
// DELETE THIS AND ADD CODE HERE
{ return(null /* DELETE null AND ADD CODE HERE */); }
}
String who () throws Exception :
{
String s;
}
{
// DELETE THIS AND ADD CODE HERE
{ return(null /* DELETE null AND ADD CODE HERE */); }
}
String where () throws Exception :
{
String s;
}
{
// DELETE THIS AND ADD CODE HERE
{ return(null /* DELETE null AND ADD CODE HERE */); }
}

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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions