/* Generated By:JavaCC: Do not edit this line. MFileParser.java */
package gov.redhawk.mfile.parser;
import java.io.*;
import java.util.*;
import gov.redhawk.mfile.parser.model.*;
public class MFileParser implements MFileParserConstants {
public static MFile parse(InputStream in, String encoding) throws ParseException
{
MFileParser parser = new MFileParser(in, encoding);
return parser.mFile();
}
final public MFile mFile() throws ParseException {
MFile retVal = new MFile();
Function function;
label_1:
while (true) {
switch (jj_nt.kind) {
case NL:
;
break;
default:
jj_la1[0] = jj_gen;
break label_1;
}
jj_consume_token(NL);
}
switch (jj_nt.kind) {
case FUNCTION:
function = function();
retVal.setFunction(function);
// TODO: Shortcut return MFile function definition
{if (true) return retVal;}
break;
default:
jj_la1[1] = jj_gen;
;
}
jj_consume_token(0);
{if (true) return retVal;}
throw new Error("Missing return statement in function");
}
final public List < String > outputs() throws ParseException {
List < String > strList = new ArrayList < String > ();
String id = null;
switch (jj_nt.kind) {
case 12:
jj_consume_token(12);
switch (jj_nt.kind) {
case ID:
strList = multiPart();
break;
default:
jj_la1[2] = jj_gen;
;
}
jj_consume_token(13);
break;
case ID:
strList = multiPart();
break;
default:
jj_la1[3] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
{if (true) return strList;}
throw new Error("Missing return statement in function");
}
final public Function function() throws ParseException {
Function function = new Function();
List < String > strList = null;
String id = null;
jj_consume_token(FUNCTION);
if (jj_2_1(2)) {
strList = outputs();
jj_consume_token(14);
jj_consume_token(ID);
function.getOutputs().addAll(strList);
} else {
switch (jj_nt.kind) {
case ID:
jj_consume_token(ID);
break;
default:
jj_la1[4] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
function.setName(token.image);
switch (jj_nt.kind) {
case 15:
functionArgs(function, strList);
break;
default:
jj_la1[5] = jj_gen;
;
}
jj_consume_token(NL);
{if (true) return function;}
throw new Error("Missing return statement in function");
}
final public void functionArgs(Function function, List < String > strList) throws ParseException {
String param;
jj_consume_token(15);
label_2:
while (true) {
switch (jj_nt.kind) {
case NL:
;
break;
default:
jj_la1[6] = jj_gen;
break label_2;
}
jj_consume_token(NL);
}
label_3:
while (true) {
switch (jj_nt.kind) {
case ID:
;
break;
default:
jj_la1[7] = jj_gen;
break label_3;
}
jj_consume_token(ID);
param = token.image;
function.getInputs().add(param);
switch (jj_nt.kind) {
case 14:
jj_consume_token(14);
number(function, param);
break;
default:
jj_la1[8] = jj_gen;
;
}
switch (jj_nt.kind) {
case 16:
jj_consume_token(16);
break;
default:
jj_la1[9] = jj_gen;
;
}
label_4:
while (true) {
switch (jj_nt.kind) {
case NL:
;
break;
default:
jj_la1[10] = jj_gen;
break label_4;
}
jj_consume_token(NL);
}
}
jj_consume_token(17);
switch (jj_nt.kind) {
case 18:
jj_consume_token(18);
break;
default:
jj_la1[11] = jj_gen;
;
}
}
final public void number(Function function, String input) throws ParseException {
switch (jj_nt.kind) {
case OCTALINT:
jj_consume_token(OCTALINT);
function.getInputDefaultValues().put(input, Integer.valueOf(token.image.substring(1), 8));
break;
case DECIMALINT:
jj_consume_token(DECIMALINT);
function.getInputDefaultValues().put(input, Integer.valueOf(token.image));
break;
case FIXED_PT:
jj_consume_token(FIXED_PT);
function.getInputDefaultValues().put(input, Integer.valueOf(token.image));
break;
case HEXADECIMALINT:
jj_consume_token(HEXADECIMALINT);
function.getInputDefaultValues().put(input, Integer.valueOf(token.image.substring(2), 16));
break;
case FLOATONE:
jj_consume_token(FLOATONE);
function.getInputDefaultValues().put(input, Double.valueOf(token.image));
break;
case FLOATTWO:
jj_consume_token(FLOATTWO);
function.getInputDefaultValues().put(input, Double.valueOf(token.image));
break;
default:
jj_la1[12] = jj_gen;
jj_consume_token(-1);
throw new ParseException();
}
}
final public List < String > multiPart() throws ParseException {
List < String > retVal = new ArrayList < String > ();
jj_consume_token(ID);
retVal.add(token.image);
label_5:
while (true) {
switch (jj_nt.kind) {
case 16:
case ID:
;
break;
default:
jj_la1[13] = jj_gen;
break label_5;
}
switch (jj_nt.kind) {
case 16:
jj_consume_token(16);
break;
default:
jj_la1[14] = jj_gen;
;
}
jj_consume_token(ID);
retVal.add(token.image);
}
{if (true) return retVal;}
throw new Error("Missing return statement in function");
}
final public String singlePart() throws ParseException {
jj_consume_token(ID);
{if (true) return token.image;}
throw new Error("Missing return statement in function");
}
private boolean jj_2_1(int xla) {
jj_la = xla; jj_lastpos = jj_scanpos = token;
try { return !jj_3_1(); }
catch(LookaheadSuccess ls) { return true; }
finally { jj_save(0, xla); }
}
private boolean jj_3R_8() {
if (jj_3R_10()) return true;
return false;
}
private boolean jj_3R_10() {
if (jj_scan_token(ID)) return true;
Token xsp;
while (true) {
xsp = jj_scanpos;
if (jj_3R_11()) { jj_scanpos = xsp; break; }
}
return false;
}
private boolean jj_3R_7() {
if (jj_scan_token(12)) return true;
Token xsp;
xsp = jj_scanpos;
if (jj_3R_9()) jj_scanpos = xsp;
if (jj_scan_token(13)) return true;
return false;
}
private boolean jj_3R_9() {
if (jj_3R_10()) return true;
return false;
}
private boolean jj_3R_6() {
Token xsp;
xsp = jj_scanpos;
if (jj_3R_7()) {
jj_scanpos = xsp;
if (jj_3R_8()) return true;
}
return false;
}
private boolean jj_3_1() {
if (jj_3R_6()) return true;
if (jj_scan_token(14)) return true;
return false;
}
private boolean jj_3R_11() {
Token xsp;
xsp = jj_scanpos;
if (jj_scan_token(16)) jj_scanpos = xsp;
if (jj_scan_token(ID)) return true;
return false;
}
/** Generated Token Manager. */
public MFileParserTokenManager token_source;
JavaCharStream jj_input_stream;
/** Current token. */
public Token token;
/** Next token. */
public Token jj_nt;
private Token jj_scanpos, jj_lastpos;
private int jj_la;
private int jj_gen;
final private int[] jj_la1 = new int[15];
static private int[] jj_la1_0;
static {
jj_la1_init_0();
}
private static void jj_la1_init_0() {
jj_la1_0 = new int[] {0x80000,0x800,0x100000,0x101000,0x100000,0x8000,0x80000,0x100000,0x4000,0x10000,0x80000,0x40000,0x7e00000,0x110000,0x10000,};
}
final private JJCalls[] jj_2_rtns = new JJCalls[1];
private boolean jj_rescan = false;
private int jj_gc = 0;
/** Constructor with InputStream. */
public MFileParser(java.io.InputStream stream) {
this(stream, null);
}
/** Constructor with InputStream and supplied encoding */
public MFileParser(java.io.InputStream stream, String encoding) {
try { jj_input_stream = new JavaCharStream(stream, encoding, 1, 1); } catch(java.io.UnsupportedEncodingException e) { throw new RuntimeException(e); }
token_source = new MFileParserTokenManager(jj_input_stream);
token = new Token();
token.next = jj_nt = token_source.getNextToken();
jj_gen = 0;
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
/** Reinitialise. */
public void ReInit(java.io.InputStream stream) {
ReInit(stream, null);
}
/** Reinitialise. */
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();
token.next = jj_nt = token_source.getNextToken();
jj_gen = 0;
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
/** Constructor. */
public MFileParser(java.io.Reader stream) {
jj_input_stream = new JavaCharStream(stream, 1, 1);
token_source = new MFileParserTokenManager(jj_input_stream);
token = new Token();
token.next = jj_nt = token_source.getNextToken();
jj_gen = 0;
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
/** Reinitialise. */
public void ReInit(java.io.Reader stream) {
jj_input_stream.ReInit(stream, 1, 1);
token_source.ReInit(jj_input_stream);
token = new Token();
token.next = jj_nt = token_source.getNextToken();
jj_gen = 0;
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
/** Constructor with generated Token Manager. */
public MFileParser(MFileParserTokenManager tm) {
token_source = tm;
token = new Token();
token.next = jj_nt = token_source.getNextToken();
jj_gen = 0;
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
/** Reinitialise. */
public void ReInit(MFileParserTokenManager tm) {
token_source = tm;
token = new Token();
token.next = jj_nt = token_source.getNextToken();
jj_gen = 0;
for (int i = 0; i < 15; i++) jj_la1[i] = -1;
for (int i = 0; i < jj_2_rtns.length; i++) jj_2_rtns[i] = new JJCalls();
}
private Token jj_consume_token(int kind) throws ParseException {
Token oldToken = token;
if ((token = jj_nt).next != null) jj_nt = jj_nt.next;
else jj_nt = jj_nt.next = token_source.getNextToken();
if (token.kind == kind) {
jj_gen++;
if (++jj_gc > 100) {
jj_gc = 0;
for (int i = 0; i < jj_2_rtns.length; i++) {
JJCalls c = jj_2_rtns[i];
while (c != null) {
if (c.gen < jj_gen) c.first = null;
c = c.next;
}
}
}
return token;
}
jj_nt = token;
token = oldToken;
jj_kind = kind;
throw generateParseException();
}
static private final class LookaheadSuccess extends java.lang.Error { }
final private LookaheadSuccess jj_ls = new LookaheadSuccess();
private boolean jj_scan_token(int kind) {
if (jj_scanpos == jj_lastpos) {
jj_la--;
if (jj_scanpos.next == null) {
jj_lastpos = jj_scanpos = jj_scanpos.next = token_source.getNextToken();
} else {
jj_lastpos = jj_scanpos = jj_scanpos.next;
}
} else {
jj_scanpos = jj_scanpos.next;
}
if (jj_rescan) {
int i = 0; Token tok = token;
while (tok != null && tok != jj_scanpos) { i++; tok = tok.next; }
if (tok != null) jj_add_error_token(kind, i);
}
if (jj_scanpos.kind != kind) return true;
if (jj_la == 0 && jj_scanpos == jj_lastpos) throw jj_ls;
return false;
}
/** Get the next Token. */
final public Token getNextToken() {
if ((token = jj_nt).next != null) jj_nt = jj_nt.next;
else jj_nt = jj_nt.next = token_source.getNextToken();
jj_gen++;
return token;
}
/** Get the specific 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;
}
private java.util.List<int[]> jj_expentries = new java.util.ArrayList<int[]>();
private int[] jj_expentry;
private int jj_kind = -1;
private int[] jj_lasttokens = new int[100];
private int jj_endpos;
private void jj_add_error_token(int kind, int pos) {
if (pos >= 100) return;
if (pos == jj_endpos + 1) {
jj_lasttokens[jj_endpos++] = kind;
} else if (jj_endpos != 0) {
jj_expentry = new int[jj_endpos];
for (int i = 0; i < jj_endpos; i++) {
jj_expentry[i] = jj_lasttokens[i];
}
jj_entries_loop: for (java.util.Iterator<?> it = jj_expentries.iterator(); it.hasNext();) {
int[] oldentry = (int[])(it.next());
if (oldentry.length == jj_expentry.length) {
for (int i = 0; i < jj_expentry.length; i++) {
if (oldentry[i] != jj_expentry[i]) {
continue jj_entries_loop;
}
}
jj_expentries.add(jj_expentry);
break jj_entries_loop;
}
}
if (pos != 0) jj_lasttokens[(jj_endpos = pos) - 1] = kind;
}
}
/** Generate ParseException. */
public ParseException generateParseException() {
jj_expentries.clear();
boolean[] la1tokens = new boolean[29];
if (jj_kind >= 0) {
la1tokens[jj_kind] = true;
jj_kind = -1;
}
for (int i = 0; i < 15; 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 < 29; i++) {
if (la1tokens[i]) {
jj_expentry = new int[1];
jj_expentry[0] = i;
jj_expentries.add(jj_expentry);
}
}
jj_endpos = 0;
jj_rescan_token();
jj_add_error_token(0, 0);
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. */
final public void enable_tracing() {
}
/** Disable tracing. */
final public void disable_tracing() {
}
private void jj_rescan_token() {
jj_rescan = true;
for (int i = 0; i < 1; i++) {
try {
JJCalls p = jj_2_rtns[i];
do {
if (p.gen > jj_gen) {
jj_la = p.arg; jj_lastpos = jj_scanpos = p.first;
switch (i) {
case 0: jj_3_1(); break;
}
}
p = p.next;
} while (p != null);
} catch(LookaheadSuccess ls) { }
}
jj_rescan = false;
}
private void jj_save(int index, int xla) {
JJCalls p = jj_2_rtns[index];
while (p.gen > jj_gen) {
if (p.next == null) { p = p.next = new JJCalls(); break; }
p = p.next;
}
p.gen = jj_gen + xla - jj_la; p.first = token; p.arg = xla;
}
static final class JJCalls {
int gen;
Token first;
int arg;
JJCalls next;
}
}