diff --git a/prism/src/parser/ParseException.java b/prism/src/parser/ParseException.java index 168db645..5144d63b 100644 --- a/prism/src/parser/ParseException.java +++ b/prism/src/parser/ParseException.java @@ -1,5 +1,5 @@ -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ -/* And modified by me - added shorter form of error message */ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ package parser; /** @@ -13,25 +13,25 @@ package parser; */ public class ParseException extends Exception { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + /** * This constructor is used by the method "generateParseException" * in the generated parser. Calling this constructor generates * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. The boolean - * flag "specialConstructor" is also set to true to indicate that - * this constructor was used to create this object. - * This constructor calls its super class with the empty string - * to force the "toString" method of parent class "Throwable" to - * print the error message in the form: - * ParseException: + * "expectedTokenSequences", and "tokenImage" set. */ public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal ) { - super(""); - specialConstructor = true; + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); currentToken = currentTokenVal; expectedTokenSequences = expectedTokenSequencesVal; tokenImage = tokenImageVal; @@ -49,20 +49,13 @@ public class ParseException extends Exception { public ParseException() { super(); - specialConstructor = false; } + /** Constructor with message. */ public ParseException(String message) { super(message); - specialConstructor = false; } - /** - * This variable determines which constructor was used to create - * this object and thereby affects the semantics of the - * "getMessage" method (see below). - */ - protected boolean specialConstructor; /** * This is the last token that has been consumed successfully. If @@ -86,19 +79,16 @@ public class ParseException extends Exception { public String[] tokenImage; /** - * This method has the standard behavior when this object has been - * created using the standard constructors. Otherwise, it uses - * "currentToken" and "expectedTokenSequences" to generate a parse + * It uses "currentToken" and "expectedTokenSequences" to generate a parse * error message and returns it. If this object has been created * due to a parse error, and you do not catch it (it gets thrown - * from the parser), then this method is called during the printing - * of the final stack trace, and hence the correct error message + * from the parser) the correct error message * gets displayed. */ - public String getMessage() { - if (!specialConstructor) { - return super.getMessage(); - } + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); StringBuffer expected = new StringBuffer(); int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { @@ -106,7 +96,7 @@ public class ParseException extends Exception { maxSize = expectedTokenSequences[i].length; } for (int j = 0; j < expectedTokenSequences[i].length; j++) { - expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" "); + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); } if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected.append("..."); @@ -121,8 +111,11 @@ public class ParseException extends Exception { retval += tokenImage[0]; break; } + retval += " " + tokenImage[tok.kind]; + retval += " \""; retval += add_escapes(tok.image); - tok = tok.next; + retval += " \""; + tok = tok.next; } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; @@ -135,43 +128,17 @@ public class ParseException extends Exception { return retval; } - public String getShortMessage() { - if (!specialConstructor) { - return super.getMessage(); - } - String retval = "Syntax error at line "; - retval += currentToken.next.beginLine + ", column " + currentToken.next.beginColumn + ": \""; - int maxSize = 0; - for (int i = 0; i < expectedTokenSequences.length; i++) { - if (maxSize < expectedTokenSequences[i].length) { - maxSize = expectedTokenSequences[i].length; - } - } - Token tok = currentToken.next; - for (int i = 0; i < maxSize; i++) { - if (i != 0) retval += " "; - if (tok.kind == 0) { - retval += tokenImage[0]; - break; - } - retval += tok.image; - tok = tok.next; - } - retval += "\""; - return retval; - } - /** * The end of line string for this machine. */ protected String eol = System.getProperty("line.separator", "\n"); - + /** * Used to convert raw characters to their escaped version * when these raw version cannot be used as part of an ASCII * string literal. */ - protected String add_escapes(String str) { + static String add_escapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { @@ -217,3 +184,4 @@ public class ParseException extends Exception { } } +/* JavaCC - OriginalChecksum=16ba3edbb338127335444b2b77a37aa1 (do not edit this line) */ diff --git a/prism/src/parser/Prism3To4.java b/prism/src/parser/Prism3To4.java index 409cb468..1e3b13b5 100644 --- a/prism/src/parser/Prism3To4.java +++ b/prism/src/parser/Prism3To4.java @@ -16,7 +16,7 @@ public class Prism3To4 implements Prism3To4Constants { System.err.println("Syntax error"+(args.length > 0?" in "+args[0]:"")+": " + e.getMessage()); System.exit(1); } catch (ParseException e) { - System.err.println("Error"+(args.length > 0?" in "+args[0]:"")+": " + e.getShortMessage()); System.exit(1); + System.err.println("Error"+(args.length > 0?" in "+args[0]:"")+": " + e.getMessage()); System.exit(1); } catch (FileNotFoundException e) { System.err.println(e); System.exit(1); diff --git a/prism/src/parser/Prism3To4.jj b/prism/src/parser/Prism3To4.jj index 9a3bbf9c..f2b24cf6 100644 --- a/prism/src/parser/Prism3To4.jj +++ b/prism/src/parser/Prism3To4.jj @@ -56,7 +56,7 @@ public class Prism3To4 System.err.println("Syntax error"+(args.length > 0?" in "+args[0]:"")+": " + e.getMessage()); System.exit(1); } catch (ParseException e) { - System.err.println("Error"+(args.length > 0?" in "+args[0]:"")+": " + e.getShortMessage()); System.exit(1); + System.err.println("Error"+(args.length > 0?" in "+args[0]:"")+": " + e.getMessage()); System.exit(1); } catch (FileNotFoundException e) { System.err.println(e); System.exit(1); diff --git a/prism/src/pta/parser/PTAParser.java b/prism/src/pta/parser/PTAParser.java index 22eae3f2..59513e31 100644 --- a/prism/src/pta/parser/PTAParser.java +++ b/prism/src/pta/parser/PTAParser.java @@ -22,7 +22,7 @@ public class PTAParser implements PTAParserConstants { p = new PTAParser(); str = (args.length > 0) ? new FileInputStream(args[0]) : System.in; src = (args.length > 0) ? "file "+args[0] : "stdin"; - System.out.println("Reading from "+src+"...\n"); + System.out.println("Reading from "+src+"...\u005cn"); PTA pta = p.parsePTA(str); System.out.print(pta); @@ -183,7 +183,7 @@ public class PTAParser implements PTAParserConstants { public void createDataStructures(astPTA pta, Transition trans) { int d = pta.getLocationIndex(dest); - if (d == -1) { System.err.println("Error: Location \""+dest+"\" does not exist"); System.exit(1); } + if (d == -1) { System.err.println("Error: Location \u005c""+dest+"\u005c" does not exist"); System.exit(1); } Edge edge = trans.addEdge(prob, d); for (Map.Entry e : resets.entrySet()) edge.addReset(e.getKey(), e.getValue()); } @@ -480,32 +480,38 @@ public class PTAParser implements PTAParserConstants { } static private boolean jj_initialized_once = false; + /** Generated Token Manager. */ static public PTAParserTokenManager token_source; static SimpleCharStream jj_input_stream; - static public Token token, jj_nt; + /** 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[13]; static private int[] jj_la1_0; static private int[] jj_la1_1; static { - jj_la1_0(); - jj_la1_1(); + jj_la1_init_0(); + jj_la1_init_1(); } - private static void jj_la1_0() { + private static void jj_la1_init_0() { jj_la1_0 = new int[] {0x200000,0x8,0x80000,0x80400000,0x40,0x0,0x8000,0x80,0x1e800000,0x0,0x8000,0x20,0x0,}; } - private static void jj_la1_1() { + private static void jj_la1_init_1() { jj_la1_1 = new int[] {0x0,0x0,0x0,0x0,0x100,0x100,0x0,0x100,0x0,0x120,0x0,0x100,0x60,}; } + /** Constructor with InputStream. */ public PTAParser(java.io.InputStream stream) { this(stream, null); } + /** Constructor with InputStream and supplied encoding */ public PTAParser(java.io.InputStream stream, String encoding) { if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. You must"); - System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); + 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(); } @@ -518,9 +524,11 @@ public class PTAParser implements PTAParserConstants { for (int i = 0; i < 13; 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); @@ -530,10 +538,11 @@ public class PTAParser implements PTAParserConstants { for (int i = 0; i < 13; i++) jj_la1[i] = -1; } + /** Constructor. */ public PTAParser(java.io.Reader stream) { if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. You must"); - System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); + 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(); } @@ -546,6 +555,7 @@ public class PTAParser implements PTAParserConstants { for (int i = 0; i < 13; 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); @@ -555,10 +565,11 @@ public class PTAParser implements PTAParserConstants { for (int i = 0; i < 13; i++) jj_la1[i] = -1; } + /** Constructor with generated Token Manager. */ public PTAParser(PTAParserTokenManager tm) { if (jj_initialized_once) { - System.out.println("ERROR: Second call to constructor of static parser. You must"); - System.out.println(" either use ReInit() or set the JavaCC option STATIC to false"); + 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(); } @@ -570,6 +581,7 @@ public class PTAParser implements PTAParserConstants { for (int i = 0; i < 13; i++) jj_la1[i] = -1; } + /** Reinitialise. */ public void ReInit(PTAParserTokenManager tm) { token_source = tm; token = new Token(); @@ -578,7 +590,7 @@ public class PTAParser implements PTAParserConstants { for (int i = 0; i < 13; i++) jj_la1[i] = -1; } - static final private Token jj_consume_token(int kind) throws ParseException { + 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(); @@ -592,6 +604,8 @@ public class PTAParser implements PTAParserConstants { 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(); @@ -600,6 +614,7 @@ public class PTAParser implements PTAParserConstants { return token; } +/** Get the specific Token. */ static final public Token getToken(int index) { Token t = token; for (int i = 0; i < index; i++) { @@ -609,23 +624,21 @@ public class PTAParser implements PTAParserConstants { return t; } - static final private int jj_ntk() { + static private int jj_ntk() { 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.Vector jj_expentries = new java.util.Vector(); + static private java.util.List jj_expentries = new java.util.ArrayList(); static private int[] jj_expentry; static private int jj_kind = -1; + /** Generate ParseException. */ static public ParseException generateParseException() { - jj_expentries.removeAllElements(); + jj_expentries.clear(); boolean[] la1tokens = new boolean[42]; - for (int i = 0; i < 42; i++) { - la1tokens[i] = false; - } if (jj_kind >= 0) { la1tokens[jj_kind] = true; jj_kind = -1; @@ -646,19 +659,21 @@ public class PTAParser implements PTAParserConstants { if (la1tokens[i]) { jj_expentry = new int[1]; jj_expentry[0] = i; - jj_expentries.addElement(jj_expentry); + jj_expentries.add(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); + 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() { } diff --git a/prism/src/pta/parser/PTAParserConstants.java b/prism/src/pta/parser/PTAParserConstants.java index 5eb0f3e9..a0df27e8 100644 --- a/prism/src/pta/parser/PTAParserConstants.java +++ b/prism/src/pta/parser/PTAParserConstants.java @@ -1,53 +1,102 @@ /* Generated By:JavaCC: Do not edit this line. PTAParserConstants.java */ package pta.parser; + +/** + * Token literal values and constants. + * Generated by org.javacc.parser.OtherFilesGen#start() + */ public interface PTAParserConstants { + /** End of File. */ int EOF = 0; + /** RegularExpression Id. */ int WHITESPACE = 1; + /** RegularExpression Id. */ int COMMENT = 2; + /** RegularExpression Id. */ int INIT = 3; + /** RegularExpression Id. */ int NODE = 4; + /** RegularExpression Id. */ int NULL = 5; + /** RegularExpression Id. */ int TRAN = 6; + /** RegularExpression Id. */ int TRUE = 7; + /** RegularExpression Id. */ int NOT = 8; + /** RegularExpression Id. */ int AND = 9; + /** RegularExpression Id. */ int OR = 10; + /** RegularExpression Id. */ int IMPLIES = 11; + /** RegularExpression Id. */ int RARROW = 12; + /** RegularExpression Id. */ int COLON = 13; + /** RegularExpression Id. */ int SEMICOLON = 14; + /** RegularExpression Id. */ int COMMA = 15; + /** RegularExpression Id. */ int DOTS = 16; + /** RegularExpression Id. */ int LPARENTH = 17; + /** RegularExpression Id. */ int RPARENTH = 18; + /** RegularExpression Id. */ int LBRACKET = 19; + /** RegularExpression Id. */ int RBRACKET = 20; + /** RegularExpression Id. */ int LBRACE = 21; + /** RegularExpression Id. */ int RBRACE = 22; + /** RegularExpression Id. */ int EQ = 23; + /** RegularExpression Id. */ int NE = 24; + /** RegularExpression Id. */ int LT = 25; + /** RegularExpression Id. */ int GT = 26; + /** RegularExpression Id. */ int LE = 27; + /** RegularExpression Id. */ int GE = 28; + /** RegularExpression Id. */ int PLUS = 29; + /** RegularExpression Id. */ int MINUS = 30; + /** RegularExpression Id. */ int TIMES = 31; + /** RegularExpression Id. */ int DIVIDE = 32; + /** RegularExpression Id. */ int PRIME = 33; + /** RegularExpression Id. */ int RENAME = 34; + /** RegularExpression Id. */ int QMARK = 35; + /** RegularExpression Id. */ int DQUOTE = 36; + /** RegularExpression Id. */ int REG_INT = 37; + /** RegularExpression Id. */ int REG_DOUBLE = 38; + /** RegularExpression Id. */ int REG_IDENTPRIME = 39; + /** RegularExpression Id. */ int REG_IDENT = 40; + /** RegularExpression Id. */ int LEXICAL_ERROR = 41; + /** Lexical state. */ int DEFAULT = 0; + /** Literal token values. */ String[] tokenImage = { "", "", diff --git a/prism/src/pta/parser/PTAParserTokenManager.java b/prism/src/pta/parser/PTAParserTokenManager.java index a84d7ebf..d80906c3 100644 --- a/prism/src/pta/parser/PTAParserTokenManager.java +++ b/prism/src/pta/parser/PTAParserTokenManager.java @@ -5,9 +5,13 @@ import java.util.*; import pta.*; import prism.PrismLangException; +/** Token Manager. */ public class PTAParserTokenManager implements PTAParserConstants { + + /** Debug output. */ public static java.io.PrintStream debugStream = System.out; + /** Set debug output. */ public static void setDebugStream(java.io.PrintStream ds) { debugStream = ds; } private static final int jjStopStringLiteralDfa_0(int pos, long active0) { @@ -46,21 +50,13 @@ private static final int jjStartNfa_0(int pos, long active0) { return jjMoveNfa_0(jjStopStringLiteralDfa_0(pos, active0), pos + 1); } -static private final int jjStopAtPos(int pos, int kind) +static private int jjStopAtPos(int pos, int kind) { jjmatchedKind = kind; jjmatchedPos = pos; return pos + 1; } -static private final int jjStartNfaWithStates_0(int pos, int kind, int state) -{ - jjmatchedKind = kind; - jjmatchedPos = pos; - try { curChar = input_stream.readChar(); } - catch(java.io.IOException e) { return pos + 1; } - return jjMoveNfa_0(state, pos + 1); -} -static private final int jjMoveStringLiteralDfa0_0() +static private int jjMoveStringLiteralDfa0_0() { switch(curChar) { @@ -125,7 +121,7 @@ static private final int jjMoveStringLiteralDfa0_0() return jjMoveNfa_0(0, 0); } } -static private final int jjMoveStringLiteralDfa1_0(long active0) +static private int jjMoveStringLiteralDfa1_0(long active0) { try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { @@ -169,10 +165,10 @@ static private final int jjMoveStringLiteralDfa1_0(long active0) } return jjStartNfa_0(0, active0); } -static private final int jjMoveStringLiteralDfa2_0(long old0, long active0) +static private int jjMoveStringLiteralDfa2_0(long old0, long active0) { if (((active0 &= old0)) == 0L) - return jjStartNfa_0(0, old0); + return jjStartNfa_0(0, old0); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(1, active0); @@ -195,10 +191,10 @@ static private final int jjMoveStringLiteralDfa2_0(long old0, long active0) } return jjStartNfa_0(1, active0); } -static private final int jjMoveStringLiteralDfa3_0(long old0, long active0) +static private int jjMoveStringLiteralDfa3_0(long old0, long active0) { if (((active0 &= old0)) == 0L) - return jjStartNfa_0(1, old0); + return jjStartNfa_0(1, old0); try { curChar = input_stream.readChar(); } catch(java.io.IOException e) { jjStopStringLiteralDfa_0(2, active0); @@ -229,47 +225,24 @@ static private final int jjMoveStringLiteralDfa3_0(long old0, long active0) } return jjStartNfa_0(2, active0); } -static private final void jjCheckNAdd(int state) -{ - if (jjrounds[state] != jjround) - { - jjstateSet[jjnewStateCnt++] = state; - jjrounds[state] = jjround; - } -} -static private final void jjAddStates(int start, int end) -{ - do { - jjstateSet[jjnewStateCnt++] = jjnextStates[start]; - } while (start++ != end); -} -static private final void jjCheckNAddTwoStates(int state1, int state2) +static private int jjStartNfaWithStates_0(int pos, int kind, int state) { - jjCheckNAdd(state1); - jjCheckNAdd(state2); -} -static private final void jjCheckNAddStates(int start, int end) -{ - do { - jjCheckNAdd(jjnextStates[start]); - } while (start++ != end); -} -static private final void jjCheckNAddStates(int start) -{ - jjCheckNAdd(jjnextStates[start]); - jjCheckNAdd(jjnextStates[start + 1]); + jjmatchedKind = kind; + jjmatchedPos = pos; + try { curChar = input_stream.readChar(); } + catch(java.io.IOException e) { return pos + 1; } + return jjMoveNfa_0(state, pos + 1); } static final long[] jjbitVec0 = { 0x0L, 0x0L, 0xffffffffffffffffL, 0xffffffffffffffffL }; -static private final int jjMoveNfa_0(int startState, int curPos) +static private int jjMoveNfa_0(int startState, int curPos) { - int[] nextStates; int startsAt = 0; jjnewStateCnt = 19; int i = 1; jjstateSet[0] = startState; - int j, kind = 0x7fffffff; + int kind = 0x7fffffff; for (;;) { if (++jjround == 0x7fffffff) @@ -277,7 +250,7 @@ static private final int jjMoveNfa_0(int startState, int curPos) if (curChar < 64) { long l = 1L << curChar; - MatchLoop: do + do { switch(jjstateSet[--i]) { @@ -413,7 +386,7 @@ static private final int jjMoveNfa_0(int startState, int curPos) else if (curChar < 128) { long l = 1L << (curChar & 077); - MatchLoop: do + do { switch(jjstateSet[--i]) { @@ -460,7 +433,7 @@ static private final int jjMoveNfa_0(int startState, int curPos) { int i2 = (curChar & 0xff) >> 6; long l2 = 1L << (curChar & 077); - MatchLoop: do + do { switch(jjstateSet[--i]) { @@ -488,14 +461,18 @@ static private final int jjMoveNfa_0(int startState, int curPos) static final int[] jjnextStates = { 9, 10, 11, 14, 2, 3, 5, 16, 17, 18, 12, 13, }; + +/** Token literal values. */ public static final String[] jjstrLiteralImages = { "", null, null, "\151\156\151\164", "\156\157\144\145", "\156\165\154\154", "\164\162\141\156", "\164\162\165\145", "\41", "\46", "\174", "\75\76", "\55\76", "\72", "\73", "\54", "\56\56", "\50", "\51", "\133", "\135", "\173", "\175", "\75", "\41\75", "\74", "\76", "\74\75", "\76\75", "\53", "\55", "\52", "\57", "\47", "\74\55", "\77", "\42", null, null, null, null, null, }; + +/** Lexer state names. */ public static final String[] lexStateNames = { - "DEFAULT", + "DEFAULT", }; static final long[] jjtoToken = { 0x3fffffffff9L, @@ -510,15 +487,20 @@ static protected SimpleCharStream input_stream; static private final int[] jjrounds = new int[19]; static private final int[] jjstateSet = new int[38]; static protected char curChar; +/** Constructor. */ public PTAParserTokenManager(SimpleCharStream stream){ if (input_stream != null) throw new TokenMgrError("ERROR: Second call to constructor of static lexer. You must use ReInit() to initialize the static variables.", TokenMgrError.STATIC_LEXER_ERROR); input_stream = stream; } + +/** Constructor. */ public PTAParserTokenManager(SimpleCharStream stream, int lexState){ this(stream); SwitchTo(lexState); } + +/** Reinitialise parser. */ static public void ReInit(SimpleCharStream stream) { jjmatchedPos = jjnewStateCnt = 0; @@ -526,18 +508,22 @@ static public void ReInit(SimpleCharStream stream) input_stream = stream; ReInitRounds(); } -static private final void ReInitRounds() +static private void ReInitRounds() { int i; jjround = 0x80000001; for (i = 19; i-- > 0;) jjrounds[i] = 0x80000000; } + +/** Reinitialise parser. */ static public void ReInit(SimpleCharStream stream, int lexState) { ReInit(stream); SwitchTo(lexState); } + +/** Switch to specified lex state. */ static public void SwitchTo(int lexState) { if (lexState >= 1 || lexState < 0) @@ -548,14 +534,25 @@ static public void SwitchTo(int lexState) static protected Token jjFillToken() { - Token t = Token.newToken(jjmatchedKind); - t.kind = jjmatchedKind; + final Token t; + final String curTokenImage; + final int beginLine; + final int endLine; + final int beginColumn; + final int endColumn; String im = jjstrLiteralImages[jjmatchedKind]; - t.image = (im == null) ? input_stream.GetImage() : im; - t.beginLine = input_stream.getBeginLine(); - t.beginColumn = input_stream.getBeginColumn(); - t.endLine = input_stream.getEndLine(); - t.endColumn = input_stream.getEndColumn(); + curTokenImage = (im == null) ? input_stream.GetImage() : im; + beginLine = input_stream.getBeginLine(); + beginColumn = input_stream.getBeginColumn(); + endLine = input_stream.getEndLine(); + endColumn = input_stream.getEndColumn(); + t = Token.newToken(jjmatchedKind, curTokenImage); + + t.beginLine = beginLine; + t.endLine = endLine; + t.beginColumn = beginColumn; + t.endColumn = endColumn; + return t; } @@ -566,22 +563,22 @@ static int jjround; static int jjmatchedPos; static int jjmatchedKind; +/** Get the next Token. */ public static Token getNextToken() { - int kind; Token specialToken = null; Token matchedToken; int curPos = 0; EOFLoop : for (;;) - { - try - { + { + try + { curChar = input_stream.BeginToken(); - } + } catch(java.io.IOException e) - { + { jjmatchedKind = 0; matchedToken = jjFillToken(); matchedToken.specialToken = specialToken; @@ -644,4 +641,31 @@ public static Token getNextToken() } } +static private void jjCheckNAdd(int state) +{ + if (jjrounds[state] != jjround) + { + jjstateSet[jjnewStateCnt++] = state; + jjrounds[state] = jjround; + } +} +static private void jjAddStates(int start, int end) +{ + do { + jjstateSet[jjnewStateCnt++] = jjnextStates[start]; + } while (start++ != end); +} +static private void jjCheckNAddTwoStates(int state1, int state2) +{ + jjCheckNAdd(state1); + jjCheckNAdd(state2); +} + +static private void jjCheckNAddStates(int start, int end) +{ + do { + jjCheckNAdd(jjnextStates[start]); + } while (start++ != end); +} + } diff --git a/prism/src/pta/parser/ParseException.java b/prism/src/pta/parser/ParseException.java index 7a85a42d..7cb8e768 100644 --- a/prism/src/pta/parser/ParseException.java +++ b/prism/src/pta/parser/ParseException.java @@ -1,4 +1,5 @@ -/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 3.0 */ +/* Generated By:JavaCC: Do not edit this line. ParseException.java Version 5.0 */ +/* JavaCCOptions:KEEP_LINE_COL=null */ package pta.parser; /** @@ -12,25 +13,25 @@ package pta.parser; */ public class ParseException extends Exception { + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; + /** * This constructor is used by the method "generateParseException" * in the generated parser. Calling this constructor generates * a new object of this type with the fields "currentToken", - * "expectedTokenSequences", and "tokenImage" set. The boolean - * flag "specialConstructor" is also set to true to indicate that - * this constructor was used to create this object. - * This constructor calls its super class with the empty string - * to force the "toString" method of parent class "Throwable" to - * print the error message in the form: - * ParseException: + * "expectedTokenSequences", and "tokenImage" set. */ public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal ) { - super(""); - specialConstructor = true; + super(initialise(currentTokenVal, expectedTokenSequencesVal, tokenImageVal)); currentToken = currentTokenVal; expectedTokenSequences = expectedTokenSequencesVal; tokenImage = tokenImageVal; @@ -48,20 +49,13 @@ public class ParseException extends Exception { public ParseException() { super(); - specialConstructor = false; } + /** Constructor with message. */ public ParseException(String message) { super(message); - specialConstructor = false; } - /** - * This variable determines which constructor was used to create - * this object and thereby affects the semantics of the - * "getMessage" method (see below). - */ - protected boolean specialConstructor; /** * This is the last token that has been consumed successfully. If @@ -85,19 +79,16 @@ public class ParseException extends Exception { public String[] tokenImage; /** - * This method has the standard behavior when this object has been - * created using the standard constructors. Otherwise, it uses - * "currentToken" and "expectedTokenSequences" to generate a parse + * It uses "currentToken" and "expectedTokenSequences" to generate a parse * error message and returns it. If this object has been created * due to a parse error, and you do not catch it (it gets thrown - * from the parser), then this method is called during the printing - * of the final stack trace, and hence the correct error message + * from the parser) the correct error message * gets displayed. */ - public String getMessage() { - if (!specialConstructor) { - return super.getMessage(); - } + private static String initialise(Token currentToken, + int[][] expectedTokenSequences, + String[] tokenImage) { + String eol = System.getProperty("line.separator", "\n"); StringBuffer expected = new StringBuffer(); int maxSize = 0; for (int i = 0; i < expectedTokenSequences.length; i++) { @@ -105,7 +96,7 @@ public class ParseException extends Exception { maxSize = expectedTokenSequences[i].length; } for (int j = 0; j < expectedTokenSequences[i].length; j++) { - expected.append(tokenImage[expectedTokenSequences[i][j]]).append(" "); + expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' '); } if (expectedTokenSequences[i][expectedTokenSequences[i].length - 1] != 0) { expected.append("..."); @@ -120,8 +111,11 @@ public class ParseException extends Exception { retval += tokenImage[0]; break; } + retval += " " + tokenImage[tok.kind]; + retval += " \""; retval += add_escapes(tok.image); - tok = tok.next; + retval += " \""; + tok = tok.next; } retval += "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn; retval += "." + eol; @@ -138,13 +132,13 @@ public class ParseException extends Exception { * The end of line string for this machine. */ protected String eol = System.getProperty("line.separator", "\n"); - + /** * Used to convert raw characters to their escaped version * when these raw version cannot be used as part of an ASCII * string literal. */ - protected String add_escapes(String str) { + static String add_escapes(String str) { StringBuffer retval = new StringBuffer(); char ch; for (int i = 0; i < str.length(); i++) { @@ -190,3 +184,4 @@ public class ParseException extends Exception { } } +/* JavaCC - OriginalChecksum=66646d5c4f8e1407808fefab06fde22c (do not edit this line) */ diff --git a/prism/src/pta/parser/SimpleCharStream.java b/prism/src/pta/parser/SimpleCharStream.java index 0ced4a07..ff3c7516 100644 --- a/prism/src/pta/parser/SimpleCharStream.java +++ b/prism/src/pta/parser/SimpleCharStream.java @@ -1,4 +1,5 @@ -/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 4.0 */ +/* Generated By:JavaCC: Do not edit this line. SimpleCharStream.java Version 5.0 */ +/* JavaCCOptions:STATIC=true,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ package pta.parser; /** @@ -8,10 +9,12 @@ package pta.parser; public class SimpleCharStream { +/** Whether parser is static. */ public static final boolean staticFlag = true; static int bufsize; static int available; static int tokenBegin; +/** Position in buffer. */ static public int bufpos = -1; static protected int bufline[]; static protected int bufcolumn[]; @@ -35,217 +38,225 @@ public class SimpleCharStream static protected void ExpandBuff(boolean wrapAround) { - char[] newbuffer = new char[bufsize + 2048]; - int newbufline[] = new int[bufsize + 2048]; - int newbufcolumn[] = new int[bufsize + 2048]; + char[] newbuffer = new char[bufsize + 2048]; + int newbufline[] = new int[bufsize + 2048]; + int newbufcolumn[] = new int[bufsize + 2048]; - try - { - if (wrapAround) - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - System.arraycopy(buffer, 0, newbuffer, - bufsize - tokenBegin, bufpos); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); - bufcolumn = newbufcolumn; - - maxNextCharInd = (bufpos += (bufsize - tokenBegin)); - } - else - { - System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); - buffer = newbuffer; - - System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); - bufline = newbufline; - - System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); - bufcolumn = newbufcolumn; - - maxNextCharInd = (bufpos -= tokenBegin); - } - } - catch (Throwable t) - { - throw new Error(t.getMessage()); - } + try + { + if (wrapAround) + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + System.arraycopy(buffer, 0, newbuffer, bufsize - tokenBegin, bufpos); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + System.arraycopy(bufline, 0, newbufline, bufsize - tokenBegin, bufpos); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + System.arraycopy(bufcolumn, 0, newbufcolumn, bufsize - tokenBegin, bufpos); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos += (bufsize - tokenBegin)); + } + else + { + System.arraycopy(buffer, tokenBegin, newbuffer, 0, bufsize - tokenBegin); + buffer = newbuffer; + + System.arraycopy(bufline, tokenBegin, newbufline, 0, bufsize - tokenBegin); + bufline = newbufline; + + System.arraycopy(bufcolumn, tokenBegin, newbufcolumn, 0, bufsize - tokenBegin); + bufcolumn = newbufcolumn; + + maxNextCharInd = (bufpos -= tokenBegin); + } + } + catch (Throwable t) + { + throw new Error(t.getMessage()); + } - bufsize += 2048; - available = bufsize; - tokenBegin = 0; + bufsize += 2048; + available = bufsize; + tokenBegin = 0; } static protected void FillBuff() throws java.io.IOException { - if (maxNextCharInd == available) - { - if (available == bufsize) + if (maxNextCharInd == available) + { + if (available == bufsize) + { + if (tokenBegin > 2048) { - if (tokenBegin > 2048) - { - bufpos = maxNextCharInd = 0; - available = tokenBegin; - } - else if (tokenBegin < 0) - bufpos = maxNextCharInd = 0; - else - ExpandBuff(false); + bufpos = maxNextCharInd = 0; + available = tokenBegin; } - else if (available > tokenBegin) - available = bufsize; - else if ((tokenBegin - available) < 2048) - ExpandBuff(true); + else if (tokenBegin < 0) + bufpos = maxNextCharInd = 0; else - available = tokenBegin; - } + ExpandBuff(false); + } + else if (available > tokenBegin) + available = bufsize; + else if ((tokenBegin - available) < 2048) + ExpandBuff(true); + else + available = tokenBegin; + } - int i; - try { - if ((i = inputStream.read(buffer, maxNextCharInd, - available - maxNextCharInd)) == -1) - { - inputStream.close(); - throw new java.io.IOException(); - } - else - maxNextCharInd += i; - return; - } - catch(java.io.IOException e) { - --bufpos; - backup(0); - if (tokenBegin == -1) - tokenBegin = bufpos; - throw e; - } + int i; + try { + if ((i = inputStream.read(buffer, maxNextCharInd, available - maxNextCharInd)) == -1) + { + inputStream.close(); + throw new java.io.IOException(); + } + else + maxNextCharInd += i; + return; + } + catch(java.io.IOException e) { + --bufpos; + backup(0); + if (tokenBegin == -1) + tokenBegin = bufpos; + throw e; + } } +/** Start. */ static public char BeginToken() throws java.io.IOException { - tokenBegin = -1; - char c = readChar(); - tokenBegin = bufpos; + tokenBegin = -1; + char c = readChar(); + tokenBegin = bufpos; - return c; + return c; } static protected void UpdateLineColumn(char c) { - column++; + column++; - if (prevCharIsLF) - { - prevCharIsLF = false; + if (prevCharIsLF) + { + prevCharIsLF = false; + line += (column = 1); + } + else if (prevCharIsCR) + { + prevCharIsCR = false; + if (c == '\n') + { + prevCharIsLF = true; + } + else line += (column = 1); - } - else if (prevCharIsCR) - { - prevCharIsCR = false; - if (c == '\n') - { - prevCharIsLF = true; - } - else - line += (column = 1); - } - - switch (c) - { - case '\r' : - prevCharIsCR = true; - break; - case '\n' : - prevCharIsLF = true; - break; - case '\t' : - column--; - column += (tabSize - (column % tabSize)); - break; - default : - break; - } - - bufline[bufpos] = line; - bufcolumn[bufpos] = column; + } + + switch (c) + { + case '\r' : + prevCharIsCR = true; + break; + case '\n' : + prevCharIsLF = true; + break; + case '\t' : + column--; + column += (tabSize - (column % tabSize)); + break; + default : + break; + } + + bufline[bufpos] = line; + bufcolumn[bufpos] = column; } +/** Read a character. */ static public char readChar() throws java.io.IOException { - if (inBuf > 0) - { - --inBuf; + if (inBuf > 0) + { + --inBuf; - if (++bufpos == bufsize) - bufpos = 0; + if (++bufpos == bufsize) + bufpos = 0; - return buffer[bufpos]; - } + return buffer[bufpos]; + } - if (++bufpos >= maxNextCharInd) - FillBuff(); + if (++bufpos >= maxNextCharInd) + FillBuff(); - char c = buffer[bufpos]; + char c = buffer[bufpos]; - UpdateLineColumn(c); - return (c); + UpdateLineColumn(c); + return c; } + @Deprecated /** - * @deprecated + * @deprecated * @see #getEndColumn */ static public int getColumn() { - return bufcolumn[bufpos]; + return bufcolumn[bufpos]; } + @Deprecated /** - * @deprecated + * @deprecated * @see #getEndLine */ static public int getLine() { - return bufline[bufpos]; + return bufline[bufpos]; } + /** Get token end column number. */ static public int getEndColumn() { - return bufcolumn[bufpos]; + return bufcolumn[bufpos]; } + /** Get token end line number. */ static public int getEndLine() { return bufline[bufpos]; } + /** Get token beginning column number. */ static public int getBeginColumn() { - return bufcolumn[tokenBegin]; + return bufcolumn[tokenBegin]; } + /** Get token beginning line number. */ static public int getBeginLine() { - return bufline[tokenBegin]; + return bufline[tokenBegin]; } +/** Backup a number of characters. */ static public void backup(int amount) { inBuf += amount; if ((bufpos -= amount) < 0) - bufpos += bufsize; + bufpos += bufsize; } + /** Constructor. */ public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { if (inputStream != null) - throw new Error("\n ERROR: Second call to the constructor of a static SimpleCharStream. You must\n" + - " either use ReInit() or set the JavaCC option STATIC to false\n" + - " during the generation of this class."); + throw new Error("\n ERROR: Second call to the constructor of a static SimpleCharStream.\n" + + " You must either use ReInit() or set the JavaCC option STATIC to false\n" + + " during the generation of this class."); inputStream = dstream; line = startline; column = startcolumn - 1; @@ -256,16 +267,20 @@ public class SimpleCharStream bufcolumn = new int[buffersize]; } + /** Constructor. */ public SimpleCharStream(java.io.Reader dstream, int startline, int startcolumn) { - this(dstream, startline, startcolumn, 4096); + this(dstream, startline, startcolumn, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.Reader dstream) { - this(dstream, 1, 1, 4096); + this(dstream, 1, 1, 4096); } + + /** Reinitialise. */ public void ReInit(java.io.Reader dstream, int startline, int startcolumn, int buffersize) { @@ -285,111 +300,128 @@ public class SimpleCharStream bufpos = -1; } + /** Reinitialise. */ public void ReInit(java.io.Reader dstream, int startline, int startcolumn) { - ReInit(dstream, startline, startcolumn, 4096); + ReInit(dstream, startline, startcolumn, 4096); } + /** Reinitialise. */ public void ReInit(java.io.Reader dstream) { - ReInit(dstream, 1, 1, 4096); + ReInit(dstream, 1, 1, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { - this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + this(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { - this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + this(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, String encoding, int startline, int startcolumn) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, startline, startcolumn, 4096); + this(dstream, encoding, startline, startcolumn, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, int startline, int startcolumn) { - this(dstream, startline, startcolumn, 4096); + this(dstream, startline, startcolumn, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - this(dstream, encoding, 1, 1, 4096); + this(dstream, encoding, 1, 1, 4096); } + /** Constructor. */ public SimpleCharStream(java.io.InputStream dstream) { - this(dstream, 1, 1, 4096); + this(dstream, 1, 1, 4096); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn, int buffersize) throws java.io.UnsupportedEncodingException { - ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); + ReInit(encoding == null ? new java.io.InputStreamReader(dstream) : new java.io.InputStreamReader(dstream, encoding), startline, startcolumn, buffersize); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, int startline, int startcolumn, int buffersize) { - ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); + ReInit(new java.io.InputStreamReader(dstream), startline, startcolumn, buffersize); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, String encoding) throws java.io.UnsupportedEncodingException { - ReInit(dstream, encoding, 1, 1, 4096); + ReInit(dstream, encoding, 1, 1, 4096); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream) { - ReInit(dstream, 1, 1, 4096); + ReInit(dstream, 1, 1, 4096); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, String encoding, int startline, int startcolumn) throws java.io.UnsupportedEncodingException { - ReInit(dstream, encoding, startline, startcolumn, 4096); + ReInit(dstream, encoding, startline, startcolumn, 4096); } + /** Reinitialise. */ public void ReInit(java.io.InputStream dstream, int startline, int startcolumn) { - ReInit(dstream, startline, startcolumn, 4096); + ReInit(dstream, startline, startcolumn, 4096); } + /** Get token literal value. */ static public String GetImage() { - if (bufpos >= tokenBegin) - return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); - else - return new String(buffer, tokenBegin, bufsize - tokenBegin) + - new String(buffer, 0, bufpos + 1); + if (bufpos >= tokenBegin) + return new String(buffer, tokenBegin, bufpos - tokenBegin + 1); + else + return new String(buffer, tokenBegin, bufsize - tokenBegin) + + new String(buffer, 0, bufpos + 1); } + /** Get the suffix. */ static public char[] GetSuffix(int len) { - char[] ret = new char[len]; + char[] ret = new char[len]; - if ((bufpos + 1) >= len) - System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); - else - { - System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, - len - bufpos - 1); - System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); - } + if ((bufpos + 1) >= len) + System.arraycopy(buffer, bufpos - len + 1, ret, 0, len); + else + { + System.arraycopy(buffer, bufsize - (len - bufpos - 1), ret, 0, + len - bufpos - 1); + System.arraycopy(buffer, 0, ret, len - bufpos - 1, bufpos + 1); + } - return ret; + return ret; } + /** Reset buffer when finished. */ static public void Done() { - buffer = null; - bufline = null; - bufcolumn = null; + buffer = null; + bufline = null; + bufcolumn = null; } /** @@ -397,47 +429,47 @@ public class SimpleCharStream */ static public void adjustBeginLineColumn(int newLine, int newCol) { - int start = tokenBegin; - int len; - - if (bufpos >= tokenBegin) - { - len = bufpos - tokenBegin + inBuf + 1; - } - else - { - len = bufsize - tokenBegin + bufpos + 1 + inBuf; - } - - int i = 0, j = 0, k = 0; - int nextColDiff = 0, columnDiff = 0; - - while (i < len && - bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) - { - bufline[j] = newLine; - nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; - bufcolumn[j] = newCol + columnDiff; - columnDiff = nextColDiff; - i++; - } - - if (i < len) - { - bufline[j] = newLine++; - bufcolumn[j] = newCol + columnDiff; - - while (i++ < len) - { - if (bufline[j = start % bufsize] != bufline[++start % bufsize]) - bufline[j] = newLine++; - else - bufline[j] = newLine; - } - } + int start = tokenBegin; + int len; + + if (bufpos >= tokenBegin) + { + len = bufpos - tokenBegin + inBuf + 1; + } + else + { + len = bufsize - tokenBegin + bufpos + 1 + inBuf; + } + + int i = 0, j = 0, k = 0; + int nextColDiff = 0, columnDiff = 0; + + while (i < len && bufline[j = start % bufsize] == bufline[k = ++start % bufsize]) + { + bufline[j] = newLine; + nextColDiff = columnDiff + bufcolumn[k] - bufcolumn[j]; + bufcolumn[j] = newCol + columnDiff; + columnDiff = nextColDiff; + i++; + } + + if (i < len) + { + bufline[j] = newLine++; + bufcolumn[j] = newCol + columnDiff; + + while (i++ < len) + { + if (bufline[j = start % bufsize] != bufline[++start % bufsize]) + bufline[j] = newLine++; + else + bufline[j] = newLine; + } + } - line = bufline[j]; - column = bufcolumn[j]; + line = bufline[j]; + column = bufcolumn[j]; } } +/* JavaCC - OriginalChecksum=3508e18b871f03c08f232f31778aadb6 (do not edit this line) */ diff --git a/prism/src/pta/parser/Token.java b/prism/src/pta/parser/Token.java index ba4d8b76..71e83f03 100644 --- a/prism/src/pta/parser/Token.java +++ b/prism/src/pta/parser/Token.java @@ -1,11 +1,19 @@ -/* Generated By:JavaCC: Do not edit this line. Token.java Version 3.0 */ +/* Generated By:JavaCC: Do not edit this line. Token.java Version 5.0 */ +/* JavaCCOptions:TOKEN_EXTENDS=,KEEP_LINE_COL=null,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */ package pta.parser; /** * Describes the input token stream. */ -public class Token { +public class Token implements java.io.Serializable { + + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; /** * An integer that describes the kind of this token. This numbering @@ -14,12 +22,14 @@ public class Token { */ public int kind; - /** - * beginLine and beginColumn describe the position of the first character - * of this token; endLine and endColumn describe the position of the - * last character of this token. - */ - public int beginLine, beginColumn, endLine, endColumn; + /** The line number of the first character of this Token. */ + public int beginLine; + /** The column number of the first character of this Token. */ + public int beginColumn; + /** The line number of the last character of this Token. */ + public int endLine; + /** The column number of the last character of this Token. */ + public int endColumn; /** * The string image of the token. @@ -50,12 +60,46 @@ public class Token { */ public Token specialToken; + /** + * An optional attribute value of the Token. + * Tokens which are not used as syntactic sugar will often contain + * meaningful values that will be used later on by the compiler or + * interpreter. This attribute value is often different from the image. + * Any subclass of Token that actually wants to return a non-null value can + * override this method as appropriate. + */ + public Object getValue() { + return null; + } + + /** + * No-argument constructor + */ + public Token() {} + + /** + * Constructs a new token for the specified Image. + */ + public Token(int kind) + { + this(kind, null); + } + + /** + * Constructs a new token for the specified Image and Kind. + */ + public Token(int kind, String image) + { + this.kind = kind; + this.image = image; + } + /** * Returns the image. */ public String toString() { - return image; + return image; } /** @@ -63,19 +107,25 @@ public class Token { * can create and return subclass objects based on the value of ofKind. * Simply add the cases to the switch for all those special cases. * For example, if you have a subclass of Token called IDToken that - * you want to create if ofKind is ID, simlpy add something like : + * you want to create if ofKind is ID, simply add something like : * - * case MyParserConstants.ID : return new IDToken(); + * case MyParserConstants.ID : return new IDToken(ofKind, image); * * to the following switch statement. Then you can cast matchedToken - * variable to the appropriate type and use it in your lexical actions. + * variable to the appropriate type and use sit in your lexical actions. */ - public static final Token newToken(int ofKind) + public static Token newToken(int ofKind, String image) + { + switch(ofKind) + { + default : return new Token(ofKind, image); + } + } + + public static Token newToken(int ofKind) { - switch(ofKind) - { - default : return new Token(); - } + return newToken(ofKind, null); } } +/* JavaCC - OriginalChecksum=30180ca4550a56d1b05d411407c9e400 (do not edit this line) */ diff --git a/prism/src/pta/parser/TokenMgrError.java b/prism/src/pta/parser/TokenMgrError.java index 0036c52b..c38f52c5 100644 --- a/prism/src/pta/parser/TokenMgrError.java +++ b/prism/src/pta/parser/TokenMgrError.java @@ -1,133 +1,147 @@ -/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 3.0 */ +/* Generated By:JavaCC: Do not edit this line. TokenMgrError.java Version 5.0 */ +/* JavaCCOptions: */ package pta.parser; +/** Token Manager Error. */ public class TokenMgrError extends Error { - /* - * Ordinals for various reasons why an Error of this type can be thrown. - */ - /** - * Lexical error occured. - */ - static final int LEXICAL_ERROR = 0; + /** + * The version identifier for this Serializable class. + * Increment only if the serialized form of the + * class changes. + */ + private static final long serialVersionUID = 1L; - /** - * An attempt wass made to create a second instance of a static token manager. - */ - static final int STATIC_LEXER_ERROR = 1; + /* + * Ordinals for various reasons why an Error of this type can be thrown. + */ - /** - * Tried to change to an invalid lexical state. - */ - static final int INVALID_LEXICAL_STATE = 2; + /** + * Lexical error occurred. + */ + static final int LEXICAL_ERROR = 0; - /** - * Detected (and bailed out of) an infinite loop in the token manager. - */ - static final int LOOP_DETECTED = 3; + /** + * An attempt was made to create a second instance of a static token manager. + */ + static final int STATIC_LEXER_ERROR = 1; - /** - * Indicates the reason why the exception is thrown. It will have - * one of the above 4 values. - */ - int errorCode; + /** + * Tried to change to an invalid lexical state. + */ + static final int INVALID_LEXICAL_STATE = 2; - /** - * Replaces unprintable characters by their espaced (or unicode escaped) - * equivalents in the given string - */ - protected static final String addEscapes(String str) { - StringBuffer retval = new StringBuffer(); - char ch; - for (int i = 0; i < str.length(); i++) { - switch (str.charAt(i)) - { - case 0 : - continue; - case '\b': - retval.append("\\b"); - continue; - case '\t': - retval.append("\\t"); - continue; - case '\n': - retval.append("\\n"); - continue; - case '\f': - retval.append("\\f"); - continue; - case '\r': - retval.append("\\r"); - continue; - case '\"': - retval.append("\\\""); - continue; - case '\'': - retval.append("\\\'"); - continue; - case '\\': - retval.append("\\\\"); - continue; - default: - if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { - String s = "0000" + Integer.toString(ch, 16); - retval.append("\\u" + s.substring(s.length() - 4, s.length())); - } else { - retval.append(ch); - } - continue; - } + /** + * Detected (and bailed out of) an infinite loop in the token manager. + */ + static final int LOOP_DETECTED = 3; + + /** + * Indicates the reason why the exception is thrown. It will have + * one of the above 4 values. + */ + int errorCode; + + /** + * Replaces unprintable characters by their escaped (or unicode escaped) + * equivalents in the given string + */ + protected static final String addEscapes(String str) { + StringBuffer retval = new StringBuffer(); + char ch; + for (int i = 0; i < str.length(); i++) { + switch (str.charAt(i)) + { + case 0 : + continue; + case '\b': + retval.append("\\b"); + continue; + case '\t': + retval.append("\\t"); + continue; + case '\n': + retval.append("\\n"); + continue; + case '\f': + retval.append("\\f"); + continue; + case '\r': + retval.append("\\r"); + continue; + case '\"': + retval.append("\\\""); + continue; + case '\'': + retval.append("\\\'"); + continue; + case '\\': + retval.append("\\\\"); + continue; + default: + if ((ch = str.charAt(i)) < 0x20 || ch > 0x7e) { + String s = "0000" + Integer.toString(ch, 16); + retval.append("\\u" + s.substring(s.length() - 4, s.length())); + } else { + retval.append(ch); + } + continue; } - return retval.toString(); - } + } + return retval.toString(); + } - /** - * Returns a detailed message for the Error when it is thrown by the - * token manager to indicate a lexical error. - * Parameters : - * EOFSeen : indicates if EOF caused the lexicl error - * curLexState : lexical state in which this error occured - * errorLine : line number when the error occured - * errorColumn : column number when the error occured - * errorAfter : prefix that was seen before this error occured - * curchar : the offending character - * Note: You can customize the lexical error message by modifying this method. - */ - protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { - return("Lexical error at line " + - errorLine + ", column " + - errorColumn + ". Encountered: " + - (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + - "after : \"" + addEscapes(errorAfter) + "\""); - } + /** + * Returns a detailed message for the Error when it is thrown by the + * token manager to indicate a lexical error. + * Parameters : + * EOFSeen : indicates if EOF caused the lexical error + * curLexState : lexical state in which this error occurred + * errorLine : line number when the error occurred + * errorColumn : column number when the error occurred + * errorAfter : prefix that was seen before this error occurred + * curchar : the offending character + * Note: You can customize the lexical error message by modifying this method. + */ + protected static String LexicalError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar) { + return("Lexical error at line " + + errorLine + ", column " + + errorColumn + ". Encountered: " + + (EOFSeen ? " " : ("\"" + addEscapes(String.valueOf(curChar)) + "\"") + " (" + (int)curChar + "), ") + + "after : \"" + addEscapes(errorAfter) + "\""); + } - /** - * You can also modify the body of this method to customize your error messages. - * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not - * of end-users concern, so you can return something like : - * - * "Internal Error : Please file a bug report .... " - * - * from this method for such cases in the release version of your parser. - */ - public String getMessage() { - return super.getMessage(); - } + /** + * You can also modify the body of this method to customize your error messages. + * For example, cases like LOOP_DETECTED and INVALID_LEXICAL_STATE are not + * of end-users concern, so you can return something like : + * + * "Internal Error : Please file a bug report .... " + * + * from this method for such cases in the release version of your parser. + */ + public String getMessage() { + return super.getMessage(); + } - /* - * Constructors of various flavors follow. - */ + /* + * Constructors of various flavors follow. + */ - public TokenMgrError() { - } + /** No arg constructor. */ + public TokenMgrError() { + } - public TokenMgrError(String message, int reason) { - super(message); - errorCode = reason; - } + /** Constructor with message and reason. */ + public TokenMgrError(String message, int reason) { + super(message); + errorCode = reason; + } - public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { - this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); - } + /** Full Constructor. */ + public TokenMgrError(boolean EOFSeen, int lexState, int errorLine, int errorColumn, String errorAfter, char curChar, int reason) { + this(LexicalError(EOFSeen, lexState, errorLine, errorColumn, errorAfter, curChar), reason); + } } +/* JavaCC - OriginalChecksum=3ba52b1aad3a7caf3b9352f06a64b532 (do not edit this line) */