1. /* Assignment.java */
/* Generated By:JavaCC: Do not edit this line. Assignment.java */
// This is to begin our parser
public class Assignment implements AssignmentConstants {
public static void main(String[] args) {
try {
// We will try to complete the following, moving on to "catch" if any
error is found
Assignment parser = new
Assignment(System.in);
// We create a new instance of our assignment parser
String s = parser.Input();
// We test the parser for the input, and obtain the tag-free string if
the file parses correctly
System.out.println("YES");
// We then print YES if file parses
System.out.println(s);
// And print the subsequent tag-free String
}
catch (ParseException e) { // We now catch all
parse errors
System.out.println("NO");
if((e.currentToken.next.kind ==
SBLOCK) && (e.currentToken.beginColumn == 0)) { // If we begin with
spaces, we define this error
System.err.println("Space(s)
at start of input");
}
else if((e.currentToken.kind ==
SBLOCK) && (e.currentToken.next.kind == EOF)) { // If we end with
spaces
System.err.println("Space(s)
at end of input");
}
else if(((e.currentToken.kind ==
UBLOCK) || (e.currentToken.kind == UCHARACTER)) &&
(e.currentToken.next.kind == EOF)) { // If we end with block of
capital letters and cause an error, we must be in 2L mode
System.err.println("Must close
2L tag");
}
else if(((e.currentToken.kind ==
LBLOCK) || (e.currentToken.kind == LCHARACTER)) &&
(e.currentToken.next.kind == EOF)) { // If we end with block of
lowercase letters and cause an error, we must be in 2U mode
System.err.println("Must close
2U tag");
}
else if(((e.currentToken.kind ==
SBLOCK) || (e.currentToken.kind == SPACE)) &&
2. (e.currentToken.next.kind == UTAGCLOSE)) { // If
we end tag block with spaces, we define this error
System.err.println("Cannot
have spaces at end of 2U tag input");
}
else if(((e.currentToken.kind ==
SBLOCK) || (e.currentToken.kind == SPACE)) &&
(e.currentToken.next.kind == LTAGCLOSE)) { // If we end
tag block with spaces, we define this error
System.err.println("Cannot
have spaces at end of 2L tag input");
}
else if(((e.currentToken.next.kind ==
SBLOCK) || (e.currentToken.next.kind == SPACE)) &&
(e.currentToken.kind == UTAGOPEN)) { // If we start tag
block with spaces, we define this error
System.err.println("Cannot
have spaces at start of 2U tag input");
}
else if(((e.currentToken.next.kind ==
SBLOCK) || (e.currentToken.next.kind == SPACE)) &&
(e.currentToken.kind == LTAGOPEN)) { // If we start tag
block with spaces, we define this error
System.err.println("Cannot
have spaces at start of 2L tag input");
}
else if((e.currentToken.next.kind ==
SBLOCK) || (e.currentToken.next.kind == SPACE)) {
// If we have an odd space to our space block, then we have a space
parity error
System.err.println("Incorrect
space parity");
}
else if(((e.currentToken.next.kind ==
UCHARACTER) || (e.currentToken.next.kind == UBLOCK)) &&
((e.currentToken.kind == LCHARACTER) || (e.currentToken.kind ==
LBLOCK) || (e.currentToken.kind == UTAGOPEN))) { // If we find a
capital letter amongst a correct lowercase input, we define this error
System.err.println("Capital
letter in lowercase input");
}
else if((e.currentToken.next.kind ==
LCHARACTER) || (e.currentToken.next.kind == LBLOCK) &&
((e.currentToken.kind == UCHARACTER) || (e.currentToken.kind ==
UBLOCK) || (e.currentToken.kind == LTAGOPEN))) { // If we find a
lowercase letter amongst a correct uppercase input, we define this
error
System.err.println("Lowercase
letter in upper case input");
}
else if((e.currentToken.next.kind ==
UCHARACTER) || (e.currentToken.next.kind == UBLOCK)) {
3. // If we have an odd capital letter to our valid uppercase block, we
have an uppercase block parity error
System.err.println("Invalid
parity of upper case block");
}
else if((e.currentToken.next.kind ==
LCHARACTER) || (e.currentToken.next.kind == LBLOCK)) {
// If we have an odd lowercase letter to our valid lowercase block, we
have an lowercase block parity error
System.err.println("Invalid
parity of lowercase block");
}
else if((e.currentToken.next.kind ==
UTAGCLOSE) && (e.currentToken.kind == UTAGOPEN)) {
// We need at least one block in any input between tags, so if we have
two tags together, we define this error
System.err.println("Must enter
input between 2U tags");
}
else if(e.currentToken.next.kind ==
UTAGCLOSE) {
// If the error is caused by a close tag, then we must not have
defined an open tag
System.err.println("2U close
tag with no 2U open tag");
}
else if((e.currentToken.next.kind ==
LTAGCLOSE) && (e.currentToken.kind == LTAGOPEN)) {
// We need at least one block in any input between tags, so if we have
two tags together, we define this error
System.err.println("Must enter
input between 2L tags");
}
else if(e.currentToken.next.kind ==
LTAGCLOSE) {
// If the error is caused by a close tag, then we must not have
defined an open tag
System.err.println("2L close
tag with no 2L open tag");
}
else if((e.currentToken.next.kind ==
UTAGOPEN) && (e.currentToken.kind == UTAGOPEN)) {
// We cannot have two open tags of the same type right next to each
other, so define this error
System.err.println("Cannot
nest 2U open tags");
}
else if((e.currentToken.next.kind ==
LTAGOPEN) && (e.currentToken.kind == LTAGOPEN)) {
// We cannot have two open tags of the same type right next to each
other, so define this error
4. System.err.println("Cannot
nest 2L open tags");
}
else if(e.currentToken.next.kind ==
UTAGOPEN) {
// If we have an error caused by the open tag, we know it must be
amongst the incorrect type of block
System.err.println("2U open
tags cannot be placed amongst lowercase input");
}
else if(e.currentToken.next.kind ==
LTAGOPEN) {
// If we have an error caused by the open tag, we know it must be
amongst the incorrect type of block
System.err.println("2L open
tags cannot be placed amongst upper case input");
}
else if(e.currentToken.next.kind ==
EOF) {
// If we have hit the end of file and that is causing the error, then
it must be the only token found and hence define this error
System.err.println("Must have
at least one block in file");
}
}
catch(TokenMgrError e) {
// This is to catch the error that arises when a non-tokenisable
character is found in our input
System.out.println("NO");
System.err.println("Invalid character
in input");
}
}
static final public String Input() throws ParseException {String s;
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case UBLOCK:
case UTAGOPEN:{
s = LODD(0);
break;
}
case LBLOCK:
case LTAGOPEN:{
s = LEVEN(0);
break;
}
default:
jj_la1[0] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
jj_consume_token(0);
5. {if ("" != null) return s;}
throw new Error("Missing return statement in function");
}
static final public String LEVEN(int k) throws ParseException {Token
t; Token t2; String s = ""; String s2 = ""; String s3 = ""; String tmp
= ""; String tmp2 = ""; int i = 0;
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case LBLOCK:{
t = jj_consume_token(LBLOCK);
if(k == 0) { s = t.toString(); }
// if we are in the mode, such that the call has come from input or
LEVEN, we define the string as it is
else { tmp2 = t.toString();
// if we are in the mode, such that the call has come from LODD, we
convert the string by the language rules
while(i < tmp2.length()) {
// for each character in our string
if(i == 0) {
// for the first character, we know we have a lowercase letter and so
convert the character to uppercase and add it on twice
s = s +
Character.toUpperCase(tmp2.charAt(i)) +
Character.toUpperCase(tmp2.charAt(i));
i++;
}
else if((tmp2.charAt(i
- 1) == ' ') && (tmp2.charAt(i) != ' ')) {
// if we are moving from a space to a letter, we are on the first
letter of the block and so convert to uppercase and add it twice
s = s +
Character.toUpperCase(tmp2.charAt(i)) +
Character.toUpperCase(tmp2.charAt(i));
i++;
}
else if(tmp2.charAt(i)
== ' ') { // if we have a space, we add
the space to the String unchanged
s = s + " ";
i++;
}
else {
// if we have character amongst a block, we simply make it uppercase
and add it to our String
s = s +
Character.toUpperCase(tmp2.charAt(i));
i++;
}
}
i = 0;
// We reset i once we have traversed the String
}
6. break;
}
case LTAGOPEN:{
jj_consume_token(LTAGOPEN);
tmp = LODD(1);
jj_consume_token(LTAGCLOSE);
if(k == 0) { s = tmp; }
// If we are in the mode, such that the call has come from the input
or LEVEN, we define the string as it is
else {
// If we are in the mode, such that the call came from LODD, we
convert the string by the language rules
while(i < tmp.length()) {
// for each character in our string
if(i == 0) {
// for the first character, we know we have a lowercase letter and so
convert the character to uppercase and add it on twice
s = s +
Character.toUpperCase(tmp.charAt(i)) +
Character.toUpperCase(tmp.charAt(i));
i++;
}
else if((tmp.charAt(i
- 1) == ' ') && (tmp.charAt(i) != ' ')) {
// if we are moving from a space to a letter, we are on the first
letter of the block and so convert to uppercase and add it twice
s = s +
Character.toUpperCase(tmp.charAt(i)) +
Character.toUpperCase(tmp.charAt(i));
i++;
}
else if(tmp.charAt(i)
== ' ') { // if we have a space, we
add the space to the String unchanged
s = s + " ";
i++;
}
else {
// if we have character amongst a block, we simply make it uppercase
and add it to our String
s = s +
Character.toUpperCase(tmp.charAt(i));
i++;
}
}
i = 0;
// We reset i once we have traversed the String
}
break;
}
default:
jj_la1[1] = jj_gen;
7. jj_consume_token(-1);
throw new ParseException();
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SBLOCK:{
t2 = jj_consume_token(SBLOCK);
s2 = t2.toString();
// We then define LEVEN to be made up of any spaceblock, which
we take the String of
s3 = LEVEN(k);
break;
}
default:
jj_la1[2] = jj_gen;
;
}
{if ("" != null) return (s + s2 + s3);}
throw new Error("Missing return statement in function");
}
// We return the concatenation of the three found strings
static final public
String LODD(int k) throws ParseException {Token t; Token t2; String s
= ""; String s2 = ""; String s3 = ""; String tmp = ""; String tmp2 =
""; int i = 0;
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case UBLOCK:{
t = jj_consume_token(UBLOCK);
if(k == 0) { s = t.toString(); }
// If we are in the mode, such that the call has come from the input
or LODD, we define the string as it is
else { tmp2 = t.toString();
// If we are in the mode, such that the call came from LEVEN, we
convert the string by the language rules
while(i < tmp2.length()) {
// for each character in our string
if(i == 0) {
// for the first character, we know we have a capital letter and so
ignore the character
i++;
}
else if((tmp2.charAt(i
- 1) == ' ') && (tmp2.charAt(i) != ' ')) {
// if we are moving from a space to a letter, we are on the first
letter of the block and so ignore the character
i++;
}
else if(tmp2.charAt(i)
== ' ') { // if we have a space, we add
the space to the String unchanged
s = s + " ";
i++;
8. }
else {
// if we have character amongst a block, we simply make it lowercase
and add it to our String
s = s +
Character.toLowerCase(tmp2.charAt(i));
i++;
}
}
i = 0;
// We reset i once we have traversed the String
}
break;
}
case UTAGOPEN:{
jj_consume_token(UTAGOPEN);
tmp = LEVEN(1);
jj_consume_token(UTAGCLOSE);
if(k == 0) {s = tmp;}
// If we are in the mode, such that the call has come from the input
or LODD, we define the string as it is
else {
// If we are in the mode, such that the call came from LEVEN, we
convert the string by the language rules
while(i < tmp.length()) {
// for each character in our string
if(i == 0) {
// for the first character, we know we have a capital letter and so
ignore the character
i++;
}
else if((tmp.charAt(i
- 1) == ' ') && (tmp.charAt(i) != ' ')) {
// if we are moving from a space to a letter, we are on the first
letter of the block and so ignore the character
i++;
}
else if(tmp.charAt(i)
== ' ') { // if we have a space, we
add the space to the String unchanged
s = s + " ";
i++;
}
else {
// if we have character amongst a block, we simply make it lowercase
and add it to our String
s = s +
Character.toLowerCase(tmp.charAt(i));
i++;
}
}
9. i = 0;
// We reset i once we have traversed the String
}
break;
}
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
switch ((jj_ntk==-1)?jj_ntk_f():jj_ntk) {
case SBLOCK:{
t2 = jj_consume_token(SBLOCK);
s2 = t2.toString();
// We then define LODD to be made up of any spaceblock, which we
take the String of
s3 = LODD(k);
break;
}
default:
jj_la1[4] = jj_gen;
;
}
{if ("" != null) return (s + s2 + s3);}
throw new Error("Missing return statement in function");
}
static private boolean jj_initialized_once = false;
/** Generated Token Manager. */
static public AssignmentTokenManager token_source;
static SimpleCharStream jj_input_stream;
/** Current token. */
static public Token token;
/** Next token. */
static public Token jj_nt;
static private int jj_ntk;
static private int jj_gen;
static final private int[] jj_la1 = new int[5];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0x286,0x204,0x8,0x82,0x8,};
}
/** Constructor with InputStream. */
public Assignment(java.io.InputStream stream) {
this(stream, null);
}
/** Constructor with InputStream and supplied encoding */
public Assignment(java.io.InputStream stream, String encoding) {
10. if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static
parser. ");
System.out.println(" You must either use ReInit() or set
the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
try { jj_input_stream = new SimpleCharStream(stream, encoding, 1,
1); } catch(java.io.UnsupportedEncodingException e) { throw new
RuntimeException(e); }
token_source = new AssignmentTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 5; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
static public void ReInit(java.io.InputStream stream) {
ReInit(stream, null);
}
/** Reinitialise. */
static public void ReInit(java.io.InputStream stream, String
encoding) {
try { jj_input_stream.ReInit(stream, encoding, 1, 1); }
catch(java.io.UnsupportedEncodingException e) { throw new
RuntimeException(e); }
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 5; i++) jj_la1[i] = -1;
}
/** Constructor. */
public Assignment(java.io.Reader stream) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static
parser. ");
System.out.println(" You must either use ReInit() or set
the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new AssignmentTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
11. for (int i = 0; i < 5; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
static public void ReInit(java.io.Reader stream) {
jj_input_stream.ReInit(stream, 1, 1);
token_source.ReInit(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 5; i++) jj_la1[i] = -1;
}
/** Constructor with generated Token Manager. */
public Assignment(AssignmentTokenManager tm) {
if (jj_initialized_once) {
System.out.println("ERROR: Second call to constructor of static
parser. ");
System.out.println(" You must either use ReInit() or set
the JavaCC option STATIC to false");
System.out.println(" during parser generation.");
throw new Error();
}
jj_initialized_once = true;
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 5; i++) jj_la1[i] = -1;
}
/** Reinitialise. */
public void ReInit(AssignmentTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 5; i++) jj_la1[i] = -1;
}
static private Token jj_consume_token(int kind) throws
ParseException {
Token oldToken;
if ((oldToken = token).next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
if (token.kind == kind) {
jj_gen++;
return token;
}
token = oldToken;
jj_kind = kind;
12. throw generateParseException();
}
/** Get the next Token. */
static final public Token getNextToken() {
if (token.next != null) token = token.next;
else token = token.next = token_source.getNextToken();
jj_ntk = -1;
jj_gen++;
return token;
}
/** Get the specific Token. */
static final public Token getToken(int index) {
Token t = token;
for (int i = 0; i < index; i++) {
if (t.next != null) t = t.next;
else t = t.next = token_source.getNextToken();
}
return t;
}
static private int jj_ntk_f() {
if ((jj_nt=token.next) == null)
return (jj_ntk = (token.next=token_source.getNextToken()).kind);
else
return (jj_ntk = jj_nt.kind);
}
static private java.util.List<int[]> jj_expentries = new
java.util.ArrayList<int[]>();
static private int[] jj_expentry;
static private int jj_kind = -1;
/** Generate ParseException. */
static public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[11];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 5; i++) {
if (jj_la1[i] == jj_gen) {
for (int j = 0; j < 32; j++) {
if ((jj_la1_0[i] & (1<<j)) != 0) {
la1tokens[j] = true;
}
}
}
}
13. for (int i = 0; i < 11; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
jj_expentries.add(jj_expentry);
}
}
int[][] exptokseq = new int[jj_expentries.size()][];
for (int i = 0; i < jj_expentries.size(); i++) {
exptokseq[i] = jj_expentries.get(i);
}
return new ParseException(token, exptokseq, tokenImage);
}
/** Enable tracing. */
static final public void enable_tracing() {
}
/** Disable tracing. */
static final public void disable_tracing() {
}
}