/* Generated By:JavaCC: Do not edit this line. MaturityParser.java */
/*
This file is part of the software framework JStatCom,
a library for building applications for data based analysis.
Copyright (C) 2000-2005 Markus Kraetzig
This library is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation; either version 2.1 of the
License, or (at your option) any later version.
This library is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*/
package com.jstatcom.parser;
import java.io.StringReader;
import java.util.Stack;
import com.jstatcom.util.Maturity;
import com.jstatcom.util.MaturityUnits;
public class MaturityParser implements MaturityParserConstants {
private final Stack argStack = new Stack();
public static void main(String args[]) {
MaturityParser parser = new MaturityParser(System.in);
/* Defines the variable space. */
while (true) {
System.out.print("Enter Maturity Expression: ");
System.out.flush();
try {
/* for System.in call toeval1, otherwise toeval() */
switch (parser.toeval()) {
case 0:
System.out.println("nothing.");
return;
case 1:
System.out.println(parser.argStack.pop());
break;
}
} catch (ParseException x) {
x.printStackTrace();
}
}
}
/**
* Default constructor.
*/
public MaturityParser() {
this(new StringReader(""));
}
/**
* Reinitializes this engine and parses an input String.
*
* @param inputString
* the String to parse
* @return Maturity object if parser and assembly where successful
* @throws IllegalArgumentException
* if Maturity assembly failed due to wrong arguments
* @throws ParseException
* if parsing failed, contains error description
* @throws TokenMgrError
* if tokenizing failed, contains error description
*/
public Maturity parseString(String inputString) throws ParseException,
TokenMgrError, IllegalArgumentException {
ReInit(new StringReader(inputString));
toeval();
return (Maturity) argStack.pop();
}
final public int toeval() throws ParseException {
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case INTEGER:
maturity();
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case EOL:
jj_consume_token(EOL);
break;
case 0:
jj_consume_token(0);
break;
default:
jj_la1[0] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
{
if (true)
return 1;
}
break;
case 0:
case EOL:
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case EOL:
jj_consume_token(EOL);
break;
case 0:
jj_consume_token(0);
break;
default:
jj_la1[1] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
{
if (true)
return 0;
}
break;
default:
jj_la1[2] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
throw new Error("Missing return statement in function");
}
/**
* Possible Maturity formats.
*/
@SuppressWarnings("unchecked")
final public void maturity() throws ParseException {
int count;
jj_consume_token(INTEGER);
count = Double.valueOf(token.image).intValue();
switch ((jj_ntk == -1) ? jj_ntk() : jj_ntk) {
case DAY:
jj_consume_token(DAY);
argStack.push(new Maturity(count, MaturityUnits.DAYS));
break;
case MONTH:
jj_consume_token(MONTH);
argStack.push(new Maturity(count, MaturityUnits.MONTHS));
break;
case YEAR:
jj_consume_token(YEAR);
argStack.push(new Maturity(count, MaturityUnits.YEARS));
break;
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
public MaturityParserTokenManager token_source;
SimpleCharStream jj_input_stream;
public Token token, jj_nt;
private int jj_ntk;
private int jj_gen;
final private int[] jj_la1 = new int[4];
static private int[] jj_la1_0;
static {
jj_la1_0();
}
private static void jj_la1_0() {
jj_la1_0 = new int[] { 0x11, 0x11, 0x111, 0xe0, };
}
public MaturityParser(java.io.InputStream stream) {
this(stream, null);
}
public MaturityParser(java.io.InputStream stream, String encoding) {
try {
jj_input_stream = new SimpleCharStream(stream, encoding, 1, 1);
} catch (java.io.UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
token_source = new MaturityParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 4; i++)
jj_la1[i] = -1;
}
public void ReInit(java.io.InputStream stream) {
ReInit(stream);
}
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 < 4; i++)
jj_la1[i] = -1;
}
public MaturityParser(java.io.Reader stream) {
jj_input_stream = new SimpleCharStream(stream, 1, 1);
token_source = new MaturityParserTokenManager(jj_input_stream);
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 4; i++)
jj_la1[i] = -1;
}
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 < 4; i++)
jj_la1[i] = -1;
}
public MaturityParser(MaturityParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 4; i++)
jj_la1[i] = -1;
}
public void ReInit(MaturityParserTokenManager tm) {
token_source = tm;
token = new Token();
jj_ntk = -1;
jj_gen = 0;
for (int i = 0; i < 4; i++)
jj_la1[i] = -1;
}
final 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;
throw generateParseException();
}
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;
}
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;
}
final private int jj_ntk() {
if ((jj_nt = token.next) == null)
return (jj_ntk = (token.next = token_source.getNextToken()).kind);
return (jj_ntk = jj_nt.kind);
}
private java.util.Vector jj_expentries = new java.util.Vector();
private int[] jj_expentry;
private int jj_kind = -1;
@SuppressWarnings("unchecked")
public ParseException generateParseException() {
jj_expentries.removeAllElements();
boolean[] la1tokens = new boolean[10];
for (int i = 0; i < 10; i++) {
la1tokens[i] = false;
}
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 4; 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;
}
}
}
}
for (int i = 0; i < 10; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
jj_expentries.addElement(jj_expentry);
}
}
int[][] exptokseq = new int[jj_expentries.size()][];
for (int i = 0; i < jj_expentries.size(); i++) {
exptokseq[i] = (int[]) jj_expentries.elementAt(i);
}
return new ParseException(token, exptokseq, tokenImage);
}
final public void enable_tracing() {
}
final public void disable_tracing() {
}
}
Ads help maintain this website.