use of java_cup.runtime.Symbol in project org.alloytools.alloy by AlloyTools.
the class CompLexer method alloy_binarynum.
private final Symbol alloy_binarynum(String txt) throws Err {
Pos p = alloy_here(txt);
int n = 0;
try {
txt = txt.substring(2).replaceAll("_", "");
n = Integer.parseInt(txt, 2);
} catch (NumberFormatException ex) {
throw new ErrorSyntax(p, "The binary number " + txt + " " + ex);
}
return new Symbol(CompSym.NUMBER, p, ExprConstant.Op.NUMBER.make(p, n));
}
use of java_cup.runtime.Symbol in project org.alloytools.alloy by AlloyTools.
the class CompLexer method next_token.
/**
* Resumes scanning until the next regular expression is matched, the end of
* input is encountered or an I/O-Error occurs.
*
* @return the next token
* @exception java.io.IOException if any I/O-Error occurs
*/
@Override
public java_cup.runtime.Symbol next_token() throws java.io.IOException {
int zzInput;
int zzAction;
// cached fields:
int zzCurrentPosL;
int zzMarkedPosL;
int zzEndReadL = zzEndRead;
char[] zzBufferL = zzBuffer;
char[] zzCMapL = ZZ_CMAP;
int[] zzTransL = ZZ_TRANS;
int[] zzRowMapL = ZZ_ROWMAP;
int[] zzAttrL = ZZ_ATTRIBUTE;
while (true) {
zzMarkedPosL = zzMarkedPos;
boolean zzR = false;
for (zzCurrentPosL = zzStartRead; zzCurrentPosL < zzMarkedPosL; zzCurrentPosL++) {
switch(zzBufferL[zzCurrentPosL]) {
case '\u000B':
case '\u000C':
case '\u0085':
case '\u2028':
case '\u2029':
yyline++;
yycolumn = 0;
zzR = false;
break;
case '\r':
yyline++;
yycolumn = 0;
zzR = true;
break;
case '\n':
if (zzR)
zzR = false;
else {
yyline++;
yycolumn = 0;
}
break;
default:
zzR = false;
yycolumn++;
}
}
if (zzR) {
// peek one character ahead if it is \n (if we have counted one line too much)
boolean zzPeek;
if (zzMarkedPosL < zzEndReadL)
zzPeek = zzBufferL[zzMarkedPosL] == '\n';
else if (zzAtEOF)
zzPeek = false;
else {
boolean eof = zzRefill();
zzEndReadL = zzEndRead;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
if (eof)
zzPeek = false;
else
zzPeek = zzBufferL[zzMarkedPosL] == '\n';
}
if (zzPeek)
yyline--;
}
zzAction = -1;
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
zzState = zzLexicalState;
zzForAction: {
while (true) {
if (zzCurrentPosL < zzEndReadL)
zzInput = zzBufferL[zzCurrentPosL++];
else if (zzAtEOF) {
zzInput = YYEOF;
break zzForAction;
} else {
// store back cached positions
zzCurrentPos = zzCurrentPosL;
zzMarkedPos = zzMarkedPosL;
boolean eof = zzRefill();
// get translated positions and possibly new buffer
zzCurrentPosL = zzCurrentPos;
zzMarkedPosL = zzMarkedPos;
zzBufferL = zzBuffer;
zzEndReadL = zzEndRead;
if (eof) {
zzInput = YYEOF;
break zzForAction;
} else {
zzInput = zzBufferL[zzCurrentPosL++];
}
}
int zzNext = zzTransL[zzRowMapL[zzState] + zzCMapL[zzInput]];
if (zzNext == -1)
break zzForAction;
zzState = zzNext;
int zzAttributes = zzAttrL[zzState];
if ((zzAttributes & 1) == 1) {
zzAction = zzState;
zzMarkedPosL = zzCurrentPosL;
if ((zzAttributes & 8) == 8)
break zzForAction;
}
}
}
// store back cached position
zzMarkedPos = zzMarkedPosL;
switch(zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
case 4:
{
return alloy_sym(yytext(), CompSym.AMPERSAND);
}
case 86:
break;
case 50:
{
return alloy_sym(yytext(), CompSym.SEQ);
}
case 87:
break;
case 62:
{
return alloy_binarynum(yytext());
}
case 88:
break;
case 38:
{
return alloy_sym(yytext(), CompSym.IMPLIES);
}
case 89:
break;
case 23:
{
return alloy_sym(yytext(), CompSym.RBRACE);
}
case 90:
break;
case 82:
{
return alloy_sym(yytext(), CompSym.EXACTLY);
}
case 91:
break;
case 1:
{
throw new ErrorSyntax(alloy_here(" "), "Syntax error at the " + yytext() + " character. HEX: \\u" + Integer.toString(yytext().charAt(0), 16) + ")");
}
case 92:
break;
case 53:
{
return alloy_sym(yytext(), CompSym.RUN);
}
case 93:
break;
case 36:
{
return alloy_sym(yytext(), CompSym.SHL);
}
case 94:
break;
case 35:
{
return alloy_sym(yytext(), CompSym.DOMAIN);
}
case 95:
break;
case 60:
{
return alloy_sym(yytext(), CompSym.SIGINT);
}
case 96:
break;
case 24:
{
return alloy_sym(yytext(), CompSym.TILDE);
}
case 97:
break;
case 21:
{
return alloy_sym(yytext(), CompSym.LBRACE);
}
case 98:
break;
case 7:
{
return alloy_sym(yytext(), CompSym.STAR);
}
case 99:
break;
case 30:
{
return alloy_sym(yytext(), CompSym.PLUSPLUS);
}
case 100:
break;
case 58:
{
return alloy_sym(yytext(), CompSym.FUN);
}
case 101:
break;
case 81:
{
return alloy_sym(yytext(), CompSym.STRING);
}
case 102:
break;
case 55:
{
return alloy_sym(yytext(), CompSym.EXH);
}
case 103:
break;
case 56:
{
return alloy_sym(yytext(), CompSym.INT);
}
case 104:
break;
case 52:
{
return alloy_sym(yytext(), CompSym.SIG);
}
case 105:
break;
case 75:
{
return alloy_sym(yytext(), CompSym.PRED);
}
case 106:
break;
case 25:
{
return alloy_id(yytext());
}
case 107:
break;
case 66:
{
return alloy_sym(yytext(), CompSym.LONE);
}
case 108:
break;
case 41:
{
return alloy_sym(yytext(), CompSym.NO);
}
case 109:
break;
case 9:
{
return alloy_sym(yytext(), CompSym.COMMA);
}
case 110:
break;
case 40:
{
return alloy_sym(yytext(), CompSym.AS);
}
case 111:
break;
case 65:
{
return alloy_sym(yytext(), CompSym.THIS);
}
case 112:
break;
case 13:
{
return alloy_sym(yytext(), CompSym.SLASH);
}
case 113:
break;
case 48:
{
return alloy_sym(yytext(), CompSym.BUT);
}
case 114:
break;
case 43:
{
return alloy_string(yytext());
}
case 115:
break;
case 68:
{
return alloy_sym(yytext(), CompSym.DISJ);
}
case 116:
break;
case 32:
{
return alloy_sym(yytext(), CompSym.SHA);
}
case 117:
break;
case 39:
{
return alloy_sym(yytext(), CompSym.OR);
}
case 118:
break;
case 45:
{
return alloy_sym(yytext(), CompSym.SHR);
}
case 119:
break;
case 84:
{
return alloy_sym(yytext(), CompSym.PRIVATE);
}
case 120:
break;
case 31:
{
return alloy_sym(yytext(), CompSym.ARROW);
}
case 121:
break;
case 33:
{
return alloy_sym(yytext(), CompSym.GTE);
}
case 122:
break;
case 20:
{
return alloy_sym(yytext(), CompSym.CARET);
}
case 123:
break;
case 46:
{
return alloy_sym(yytext(), CompSym.IFF);
}
case 124:
break;
case 69:
{
return alloy_sym(yytext(), CompSym.ELSE);
}
case 125:
break;
case 3:
{
return alloy_sym(yytext(), CompSym.HASH);
}
case 126:
break;
case 12:
{
return alloy_sym(yytext(), CompSym.DOT);
}
case 127:
break;
case 22:
{
return alloy_sym(yytext(), CompSym.BAR);
}
case 128:
break;
case 79:
{
return alloy_sym(yytext(), CompSym.EXPECT);
}
case 129:
break;
case 8:
{
return alloy_sym(yytext(), CompSym.PLUS);
}
case 130:
break;
case 37:
{
return alloy_sym(yytext(), CompSym.LTE);
}
case 131:
break;
case 57:
{
return alloy_sym(yytext(), CompSym.ONE);
}
case 132:
break;
case 73:
{
return alloy_sym(yytext(), CompSym.OPEN);
}
case 133:
break;
case 63:
{
return alloy_hexnum(yytext());
}
case 134:
break;
case 11:
{
return alloy_sym(yytext(), CompSym.GT);
}
case 135:
break;
case 80:
{
return alloy_sym(yytext(), CompSym.MODULE);
}
case 136:
break;
case 14:
{
return alloy_sym(yytext(), CompSym.COLON);
}
case 137:
break;
case 51:
{
return alloy_sym(yytext(), CompSym.SUM);
}
case 138:
break;
case 74:
{
return alloy_sym(yytext(), CompSym.PART);
}
case 139:
break;
case 16:
{
return alloy_sym(yytext(), CompSym.EQUALS);
}
case 140:
break;
case 83:
{
return alloy_sym(yytext(), CompSym.EXTENDS);
}
case 141:
break;
case 26:
{
throw new ErrorSyntax(alloy_here(yytext()), "String literal is missing its closing \" character");
}
case 142:
break;
case 59:
{
return alloy_sym(yytext(), CompSym.FOR);
}
case 143:
break;
case 28:
{
return alloy_num(yytext());
}
case 144:
break;
case 72:
{
return alloy_sym(yytext(), CompSym.IDEN);
}
case 145:
break;
case 15:
{
return alloy_sym(yytext(), CompSym.LT);
}
case 146:
break;
case 17:
{
return alloy_sym(yytext(), CompSym.AT);
}
case 147:
break;
case 34:
{
return alloy_sym(yytext(), CompSym.RANGE);
}
case 148:
break;
case 71:
{
return alloy_sym(yytext(), CompSym.UNIV);
}
case 149:
break;
case 2:
{
return alloy_sym(yytext(), CompSym.NOT);
}
case 150:
break;
case 49:
{
return alloy_sym(yytext(), CompSym.SET);
}
case 151:
break;
case 6:
{
return alloy_sym(yytext(), CompSym.RPAREN);
}
case 152:
break;
case 42:
{
return alloy_sym(yytext(), CompSym.IN);
}
case 153:
break;
case 77:
{
return alloy_sym(yytext(), CompSym.CHECK);
}
case 154:
break;
case 29:
{
return alloy_sym(yytext(), CompSym.AND);
}
case 155:
break;
case 64:
{
return alloy_sym(yytext(), CompSym.SOME);
}
case 156:
break;
case 76:
{
return alloy_sym(yytext(), CompSym.FACT);
}
case 157:
break;
case 10:
{
return alloy_sym(yytext(), CompSym.MINUS);
}
case 158:
break;
case 5:
{
return alloy_sym(yytext(), CompSym.LPAREN);
}
case 159:
break;
case 67:
{
return alloy_sym(yytext(), CompSym.NONE);
}
case 160:
break;
case 18:
{
return alloy_sym(yytext(), CompSym.LBRACKET);
}
case 161:
break;
case 19:
{
return alloy_sym(yytext(), CompSym.RBRACKET);
}
case 162:
break;
case 70:
{
return alloy_sym(yytext(), CompSym.ENUM);
}
case 163:
break;
case 47:
{
return alloy_sym(yytext(), CompSym.ALL);
}
case 164:
break;
case 85:
{
return alloy_sym(yytext(), CompSym.ABSTRACT);
}
case 165:
break;
case 78:
{
return alloy_sym(yytext(), CompSym.ASSERT);
}
case 166:
break;
case 61:
{
throw new ErrorSyntax(alloy_here(yytext()), "String literal cannot be followed by a legal identifier character.");
}
case 167:
break;
case 54:
{
return alloy_sym(yytext(), CompSym.LET);
}
case 168:
break;
case 27:
{
}
case 169:
break;
case 44:
{
throw new ErrorSyntax(alloy_here(yytext()), "Name cannot start with a number.");
}
case 170:
break;
default:
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
zzAtEOF = true;
zzDoEOF();
{
return new Symbol(CompSym.EOF, alloy_here(" "), alloy_here(" "));
}
} else {
zzScanError(ZZ_NO_MATCH);
}
}
}
}
use of java_cup.runtime.Symbol in project org.alloytools.alloy by AlloyTools.
the class CompFilter method next_token.
/**
* Reads one or more tokens from the underlying lexer, transform them if
* necessarly.
*/
@Override
public Symbol next_token() throws Err {
Symbol a = myread(), b;
int c;
if (last == null || (last.sym != COLON && last.sym != DISJ)) {
if (a.sym == NO)
c = NO2;
else if (a.sym == ALL)
c = ALL2;
else if (a.sym == SUM)
c = SUM2;
else if (a.sym == LONE)
c = LONE2;
else if (a.sym == ONE)
c = ONE2;
else if (a.sym == SOME)
c = SOME2;
else
return last = a;
final ArrayList<Symbol> temp = new ArrayList<Symbol>();
temp.add(b = myread());
if (b.sym == PRIVATE)
temp.add(b = myread());
if (b.sym == DISJ || b.sym == PART || b.sym == EXH)
temp.add(b = myread());
while (b.sym == ID) {
temp.add(b = myread());
if (b.sym == COMMA)
temp.add(b = myread());
else if (b.sym == COLON) {
a.sym = c;
break;
} else {
break;
}
}
for (int i = temp.size() - 1; i >= 0; i--) undo.add(0, temp.get(i));
}
return last = a;
}
use of java_cup.runtime.Symbol in project org.alloytools.alloy by AlloyTools.
the class CUP$CompParser$actions method syntax_error.
@Override
public void syntax_error(Symbol x) throws Err {
Map<Integer, String> ch = new LinkedHashMap<Integer, String>();
ch.put(CompSym.ARROW, "->");
ch.put(CompSym.ANY_ARROW_SOME, "->");
ch.put(CompSym.ANY_ARROW_ONE, "->");
ch.put(CompSym.ANY_ARROW_LONE, "->");
ch.put(CompSym.SOME_ARROW_ANY, "some");
ch.put(CompSym.SOME_ARROW_SOME, "some");
ch.put(CompSym.SOME_ARROW_ONE, "some");
ch.put(CompSym.SOME_ARROW_LONE, "some");
ch.put(CompSym.ONE_ARROW_ANY, "one");
ch.put(CompSym.ONE_ARROW_SOME, "one");
ch.put(CompSym.ONE_ARROW_ONE, "one");
ch.put(CompSym.ONE_ARROW_LONE, "one");
ch.put(CompSym.LONE_ARROW_ANY, "lone");
ch.put(CompSym.LONE_ARROW_SOME, "lone");
ch.put(CompSym.LONE_ARROW_ONE, "lone");
ch.put(CompSym.LONE_ARROW_LONE, "lone");
ch.put(CompSym.INTADD, "fun");
ch.put(CompSym.INTSUB, "fun");
ch.put(CompSym.INTMUL, "fun");
ch.put(CompSym.INTDIV, "fun");
ch.put(CompSym.INTREM, "fun");
ch.put(CompSym.INTMIN, "fun");
ch.put(CompSym.INTMAX, "fun");
ch.put(CompSym.INTNEXT, "fun");
ch.put(CompSym.TOTALORDER, "pred");
ch.put(CompSym.ABSTRACT, "abstract");
ch.put(CompSym.ALL, "all");
ch.put(CompSym.ALL2, "all");
ch.put(CompSym.AMPERSAND, "&");
ch.put(CompSym.AND, "&&");
ch.put(CompSym.AS, "as");
ch.put(CompSym.ASSERT, "assert");
ch.put(CompSym.AT, "@");
ch.put(CompSym.BAR, "|");
ch.put(CompSym.BUT, "but");
ch.put(CompSym.CARET, "^");
ch.put(CompSym.CHECK, "check");
ch.put(CompSym.COLON, ":");
ch.put(CompSym.COMMA, ", ");
ch.put(CompSym.DISJ, "disj");
ch.put(CompSym.DOMAIN, "<:");
ch.put(CompSym.DOT, ".");
ch.put(CompSym.ELSE, "else");
ch.put(CompSym.ENUM, "enum");
ch.put(CompSym.EQUALS, "=");
ch.put(CompSym.EXACTLY, "exactly");
ch.put(CompSym.EXH, "exh");
ch.put(CompSym.EXPECT, "expect");
ch.put(CompSym.EXTENDS, "extends");
ch.put(CompSym.FACT, "fact");
ch.put(CompSym.FOR, "for");
ch.put(CompSym.FUN, "fun");
ch.put(CompSym.GT, ">");
ch.put(CompSym.GTE, ">=");
ch.put(CompSym.HASH, "#");
ch.put(CompSym.IDEN, "iden");
ch.put(CompSym.IFF, "iff");
ch.put(CompSym.IMPLIES, "=>");
ch.put(CompSym.IN, "in");
ch.put(CompSym.INT, "int");
ch.put(CompSym.LBRACE, "{");
ch.put(CompSym.LBRACKET, "[");
ch.put(CompSym.LET, "let");
ch.put(CompSym.LONE2, "lone");
ch.put(CompSym.LONE, "lone");
ch.put(CompSym.LPAREN, "(");
ch.put(CompSym.LT, "<");
ch.put(CompSym.LTE, "<=");
ch.put(CompSym.MINUS, "-");
ch.put(CompSym.MODULE, "module");
ch.put(CompSym.NO2, "no");
ch.put(CompSym.NO, "no");
ch.put(CompSym.NONE, "none");
ch.put(CompSym.NOT, "!");
ch.put(CompSym.NOTEQUALS, "!");
ch.put(CompSym.NOTGT, "!");
ch.put(CompSym.NOTGTE, "!");
ch.put(CompSym.NOTIN, "!");
ch.put(CompSym.NOTLT, "!");
ch.put(CompSym.NOTLTE, "!");
ch.put(CompSym.ONE2, "one");
ch.put(CompSym.ONE, "one");
ch.put(CompSym.OPEN, "open");
ch.put(CompSym.OR, "||");
ch.put(CompSym.PART, "part");
ch.put(CompSym.PLUS, "+");
ch.put(CompSym.PLUSPLUS, "++");
ch.put(CompSym.PRED, "pred");
ch.put(CompSym.PRIVATE, "private");
ch.put(CompSym.RANGE, ":>");
ch.put(CompSym.RBRACE, "}");
ch.put(CompSym.RBRACKET, "]");
ch.put(CompSym.RPAREN, ")");
ch.put(CompSym.RUN, "run");
ch.put(CompSym.SEQ, "seq");
ch.put(CompSym.SET, "set");
ch.put(CompSym.SHL, "<<");
ch.put(CompSym.SHR, ">>>");
ch.put(CompSym.SHA, ">>");
ch.put(CompSym.SIG, "sig");
ch.put(CompSym.SIGINT, "Int");
ch.put(CompSym.SLASH, "/");
ch.put(CompSym.SOME2, "some");
ch.put(CompSym.SOME, "some");
ch.put(CompSym.STAR, "*");
ch.put(CompSym.STRING, "String");
ch.put(CompSym.SUM2, "sum");
ch.put(CompSym.SUM, "sum");
ch.put(CompSym.THIS, "this");
ch.put(CompSym.TILDE, "~");
ch.put(CompSym.UNIV, "univ");
ch.put(CompSym.ID, "NAME");
ch.put(CompSym.NUMBER, "NUMBER");
ch.put(CompSym.STR, "STRING");
TreeSet<String> list = new TreeSet<String>();
Pos p = Pos.UNKNOWN;
if (x != null && x.value instanceof Pos)
p = (Pos) (x.value);
else if (x != null && x.value instanceof Expr)
p = ((Expr) (x.value)).pos;
else if (x != null)
p = x.pos;
if (!stack.empty())
for (Map.Entry<Integer, String> e : ch.entrySet()) {
int key = e.getKey(), act = get_action(((Symbol) stack.peek()).parse_state, key);
if (act == 0)
continue;
try {
if (act > 0 || alloy_confirm(key))
list.add(e.getValue());
} catch (Throwable ex) {
// If the parser is really really confused, alloy_confirm() could fail with array out-of-bound exception, etc.
}
}
String result = "There are " + list.size() + " possible tokens that can appear here:\n";
for (String item : list) result = result + item + " ";
throw new ErrorSyntax(p, (list.size() != 0) ? result : "");
}
use of java_cup.runtime.Symbol in project mondrian by pentaho.
the class Scanner method makeSymbol.
private Symbol makeSymbol(int id, Object o) {
int iPrevPrevChar = iPrevChar;
this.iPrevChar = iChar;
this.previousSymbol = id;
return trace(new Symbol(id, iPrevPrevChar, iChar, o));
}
Aggregations