public void Update (TokenValue a) { if (sRow == -1) sRow = a.sRow; else if (a.sRow != -1 && a.sRow < sRow) sRow = a.sRow; if (eRow == -1) eRow = a.eRow; else if (a.eRow != -1 && a.eRow > eRow) eRow = a.eRow; }
public int xtoken () { int t; bool doread = false; int c; val = new TokenValue (); // optimization: eliminate col and implement #directive semantic correctly. for (;(c = getChar ()) != -1; col++) { if (c == ' ' || c == '\t' || c == '\f' || c == '\v' || c == '\r' || c == 0xa0){ if (c == '\t') col = (((col + 8) / 8) * 8) - 1; continue; } // Handle double-slash comments. if (c == '/'){ int d = peekChar (); if (d == '/'){ getChar (); while ((d = getChar ()) != -1 && (d != '\n') && d != '\r') col++; if (d == '\n'){ line++; ref_line++; col = 0; } any_token_seen |= tokens_seen; tokens_seen = false; continue; } else if (d == '*'){ getChar (); while ((d = getChar ()) != -1){ if (d == '*' && peekChar () == '/'){ getChar (); col++; break; } if (d == '\n'){ line++; ref_line++; col = 0; any_token_seen |= tokens_seen; tokens_seen = false; } } continue; } goto is_punct_label; } if (is_identifier_start_character ((char)c)){ tokens_seen = true; return consume_identifier (c, false); } is_punct_label: if ((t = is_punct ((char)c, ref doread)) != Token.ERROR){ tokens_seen = true; if (doread){ getChar (); col++; } return t; } // white space if (c == '\n'){ line++; ref_line++; col = 0; any_token_seen |= tokens_seen; tokens_seen = false; continue; } if (c >= '0' && c <= '9'){ tokens_seen = true; return is_number (c); } if (c == '.'){ tokens_seen = true; int peek = peekChar (); if (peek >= '0' && peek <= '9') return is_number (c); return Token.DOT; } /* For now, ignore pre-processor commands */ // FIXME: In C# the '#' is not limited to appear // on the first column. if (c == '#' && !tokens_seen){ bool cont = true; start_again: cont = handle_preprocessing_directive (cont); if (cont){ col = 0; continue; } col = 1; bool skipping = false; for (;(c = getChar ()) != -1; col++){ if (c == '\n'){ col = 0; line++; ref_line++; skipping = false; } else if (c == ' ' || c == '\t' || c == '\v' || c == '\r' || c == 0xa0) continue; else if (c != '#') skipping = true; if (c == '#' && !skipping) goto start_again; } any_token_seen |= tokens_seen; tokens_seen = false; if (c == -1) Report.Error (1027, Location, "#endif/#endregion expected"); continue; } if (c == '"') return consume_string (false); if (c == '\''){ c = getChar (); tokens_seen = true; if (c == '\''){ error_details = "Empty character literal"; Report.Error (1011, Location, error_details); return Token.ERROR; } c = escape (c); if (c == -1) return Token.ERROR; val.val = new System.Char (); val.val = (char) c; c = getChar (); if (c != '\''){ error_details = "Too many characters in character literal"; Report.Error (1012, Location, error_details); // Try to recover, read until newline or next "'" while ((c = getChar ()) != -1){ if (c == '\n' || c == '\''){ line++; ref_line++; col = 0; break; } else col++; } return Token.ERROR; } return Token.LITERAL_CHARACTER; } if (c == '@') { c = getChar (); if (c == '"') { tokens_seen = true; return consume_string (true); } else if (is_identifier_start_character ((char) c)){ return consume_identifier (c, true); } else { Report.Error (1033, Location, "'@' must be followed by string constant or identifier"); } } error_details = ((char)c).ToString (); return Token.ERROR; } return Token.EOF; }
/** the generated parser. Maintains a state and a value stack, currently with fixed maximum size. @param yyLex scanner. @return result of the last reduction, if any. @throws yyException on irrecoverable parse error. */ public Object yyparse (yyParser.yyInput yyLex) { if (yyMax <= 0) yyMax = 256; // initial size int yyState = 0; // state stack ptr int [] yyStates = new int[yyMax]; // state stack Object yyVal = null; // value stack ptr Object [] yyVals = new Object[yyMax]; // value stack int yyToken = -1; // current input int yyErrorFlag = 0; // #tks to shift int yyTop = 0; goto skip; yyLoop: yyTop++; skip: for (;; ++ yyTop) { if (yyTop >= yyStates.Length) { // dynamically increase int[] i = new int[yyStates.Length+yyMax]; yyStates.CopyTo (i, 0); yyStates = i; Object[] o = new Object[yyVals.Length+yyMax]; yyVals.CopyTo (o, 0); yyVals = o; } yyStates[yyTop] = yyState; yyVals[yyTop] = yyVal; if (debug != null) debug.push(yyState, yyVal); yyDiscarded: for (;;) { // discarding a token does not change stack int yyN; if ((yyN = yyDefRed[yyState]) == 0) { // else [default] reduce (yyN) if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0; if (debug != null) debug.lex(yyState, yyToken, yyname(yyToken), yyLex.value()); } if ((yyN = yySindex[yyState]) != 0 && ((yyN += yyToken) >= 0) && (yyN < yyTable.Length) && (yyCheck[yyN] == yyToken)) { if (debug != null) debug.shift(yyState, yyTable[yyN], yyErrorFlag-1); yyState = yyTable[yyN]; // shift to yyN yyVal = yyLex.value(); yyToken = -1; if (yyErrorFlag > 0) -- yyErrorFlag; goto yyLoop; } if ((yyN = yyRindex[yyState]) != 0 && (yyN += yyToken) >= 0 && yyN < yyTable.Length && yyCheck[yyN] == yyToken) yyN = yyTable[yyN]; // reduce (yyN) else switch (yyErrorFlag) { case 0: yyerror("syntax error", yyExpecting(yyState)); if (debug != null) debug.error("syntax error"); goto case 1; case 1: case 2: yyErrorFlag = 3; do { if ((yyN = yySindex[yyStates[yyTop]]) != 0 && (yyN += Token.yyErrorCode) >= 0 && yyN < yyTable.Length && yyCheck[yyN] == Token.yyErrorCode) { if (debug != null) debug.shift(yyStates[yyTop], yyTable[yyN], 3); yyState = yyTable[yyN]; yyVal = yyLex.value(); goto yyLoop; } if (debug != null) debug.pop(yyStates[yyTop]); } while (-- yyTop >= 0); if (debug != null) debug.reject(); throw new yyParser.yyException("irrecoverable syntax error"); case 3: if (yyToken == 0) { if (debug != null) debug.reject(); throw new yyParser.yyException("irrecoverable syntax error at end-of-file"); } if (debug != null) debug.discard(yyState, yyToken, yyname(yyToken), yyLex.value()); yyToken = -1; goto yyDiscarded; // leave stack alone } } int yyV = yyTop + 1-yyLen[yyN]; if (debug != null) debug.reduce(yyState, yyStates[yyV-1], yyN, yyRule[yyN], yyLen[yyN]); yyVal = yyDefault(yyV > yyTop ? null : yyVals[yyV]); switch (yyN) { case 17: #line 271 "cs-parser.jay" { Namespace = Namespace + (Namespace.Length > 0 ? "." : "") + ((TokenValue)yyVals[0+yyTop]).val.s; Namespaces.Push (((TokenValue)yyVals[0+yyTop]).val.s.Length); } break; case 18: #line 276 "cs-parser.jay" { int idx = (int) Namespaces.Pop (); Namespace = Namespace.Remove (Namespace.Length - idx, idx); } break; case 19: #line 283 "cs-parser.jay" { yyVal = new TokenValue (); } break; case 24: #line 294 "cs-parser.jay" { ((TokenValue)yyVal).val = ((TokenValue)yyVals[-2+yyTop]).val.s + "." + ((TokenValue)yyVals[0+yyTop]).val.s; } break; case 26: #line 308 "cs-parser.jay" { } break; case 40: #line 351 "cs-parser.jay" { yyVal = new TokenValue (); } break; case 43: #line 358 "cs-parser.jay" { ((TokenValue)yyVals[-1+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); } break; case 44: #line 365 "cs-parser.jay" { ((TokenValue)yyVals[-4+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); } break; case 45: #line 369 "cs-parser.jay" { ((TokenValue)yyVals[-3+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); } break; case 46: #line 376 "cs-parser.jay" { yyVal = yyVals[-1+yyTop]; } break; case 47: #line 383 "cs-parser.jay" { yyVal = ((TokenValue)yyVals[0+yyTop]); } break; case 48: #line 386 "cs-parser.jay" { yyVal = "event"; } break; case 49: #line 387 "cs-parser.jay" { yyVal = "return"; } break; case 53: #line 401 "cs-parser.jay" { /* reserved attribute name or identifier: 17.4 */ } break; case 54: #line 405 "cs-parser.jay" { yyVal = null; } break; case 59: #line 418 "cs-parser.jay" { yyVal = null; } break; case 66: #line 439 "cs-parser.jay" { ((TokenValue)yyVals[-2+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); } break; case 101: #line 533 "cs-parser.jay" { ((TokenValue)yyVals[-4+yyTop]).Update (((TokenValue)yyVals[-3+yyTop])); ((TokenValue)yyVals[-4+yyTop]).Update (((TokenValue)yyVals[-2+yyTop])); ((TokenValue)yyVals[-4+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); /*Console.WriteLine ("fi {0}", $2);*/ foreach (string name in ((TokenValue)yyVals[-1+yyTop]).val.s.Split (',')) db.AddMember (Namespace, type, name, new Part (fileID, ((TokenValue)yyVals[-4+yyTop]))); } break; case 103: #line 546 "cs-parser.jay" { ((TokenValue)yyVals[-2+yyTop]).Update (((TokenValue)yyVals[0+yyTop]), ((TokenValue)yyVals[-2+yyTop]).val.s + "," + ((TokenValue)yyVals[0+yyTop]).val.s); } break; case 104: #line 553 "cs-parser.jay" { ((TokenValue)yyVals[-2+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); } break; case 109: #line 568 "cs-parser.jay" { ((TokenValue)yyVals[-1+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); db.AddMember (Namespace, type, ((TokenValue)yyVals[-1+yyTop]), new Part (fileID, ((TokenValue)yyVals[-1+yyTop]))); } break; case 112: #line 585 "cs-parser.jay" { ((TokenValue)yyVals[-6+yyTop]).Update (((TokenValue)yyVals[-5+yyTop])); ((TokenValue)yyVals[-6+yyTop]).Update (((TokenValue)yyVals[-4+yyTop])); ((TokenValue)yyVals[-6+yyTop]).Update (((TokenValue)yyVals[0+yyTop]), ((TokenValue)yyVals[-3+yyTop]).val.s + " (" + ((TokenValue)yyVals[-1+yyTop]).val.s + "), " + ((TokenValue)yyVals[-4+yyTop]).val.s); } break; case 113: #line 595 "cs-parser.jay" { ((TokenValue)yyVals[-6+yyTop]).Update (((TokenValue)yyVals[-5+yyTop])); ((TokenValue)yyVals[-6+yyTop]).Update (((TokenValue)yyVals[-4+yyTop])); ((TokenValue)yyVals[-6+yyTop]).Update (((TokenValue)yyVals[0+yyTop]), ((TokenValue)yyVals[-3+yyTop]).val.s + " (" + ((TokenValue)yyVals[-1+yyTop]).val.s + "), void"); } break; case 116: #line 608 "cs-parser.jay" { yyVal = new TokenValue (); } break; case 119: #line 614 "cs-parser.jay" { ((TokenValue)yyVal).val = ((TokenValue)yyVals[-2+yyTop]).val.s + ", " + ((TokenValue)yyVals[0+yyTop]).val.s; } break; case 122: #line 620 "cs-parser.jay" { ((TokenValue)yyVal).val = ((TokenValue)yyVals[-2+yyTop]).val.s + ", " + ((TokenValue)yyVals[0+yyTop]).val.s; } break; case 123: #line 628 "cs-parser.jay" { ((TokenValue)yyVal).val = ((TokenValue)yyVals[-1+yyTop]).val.s + " " + ((TokenValue)yyVals[0+yyTop]).val.s; } break; case 124: #line 634 "cs-parser.jay" { yyVal = new TokenValue (); } break; case 130: #line 656 "cs-parser.jay" { Rows.Push (lexer.Location.Row); } break; case 131: #line 660 "cs-parser.jay" { lexer.PropertyParsing = true; } break; case 132: #line 664 "cs-parser.jay" { lexer.PropertyParsing = false; } break; case 133: #line 668 "cs-parser.jay" { db.AddMember (Namespace, type, ((TokenValue)yyVals[-7+yyTop]).val.s + " " + ((TokenValue)yyVals[-6+yyTop]).val.s, new Part (fileID, (int) Rows.Pop (), lexer.Location.Row)); } break; case 136: #line 679 "cs-parser.jay" { yyVal = null; } break; case 138: #line 684 "cs-parser.jay" { yyVal = null; } break; case 140: #line 690 "cs-parser.jay" { lexer.PropertyParsing = false; } break; case 141: #line 694 "cs-parser.jay" { lexer.PropertyParsing = true; } break; case 142: #line 701 "cs-parser.jay" { lexer.PropertyParsing = false; } break; case 143: #line 705 "cs-parser.jay" { lexer.PropertyParsing = true; } break; case 145: #line 712 "cs-parser.jay" { yyVal = null; } break; case 147: #line 724 "cs-parser.jay" { yyVal = null; } break; case 149: #line 729 "cs-parser.jay" { yyVal = yyVals[0+yyTop]; } break; case 161: #line 761 "cs-parser.jay" { yyVal = false; } break; case 162: #line 762 "cs-parser.jay" { yyVal = true; } break; case 165: #line 779 "cs-parser.jay" { lexer.PropertyParsing = true; } break; case 166: #line 781 "cs-parser.jay" { lexer.PropertyParsing = false; } break; case 168: #line 786 "cs-parser.jay" { yyVal = 1; } break; case 169: #line 787 "cs-parser.jay" { yyVal = 2; } break; case 170: #line 789 "cs-parser.jay" { yyVal = 3; } break; case 171: #line 791 "cs-parser.jay" { yyVal = 3; } break; case 173: #line 802 "cs-parser.jay" { lexer.PropertyParsing = true; } break; case 174: #line 804 "cs-parser.jay" { lexer.PropertyParsing = false; } break; case 178: #line 814 "cs-parser.jay" { yyVal = null; } break; case 208: #line 867 "cs-parser.jay" { ((TokenValue)yyVals[-3+yyTop]).Update (((TokenValue)yyVals[-2+yyTop])); ((TokenValue)yyVals[-3+yyTop]).Update (((TokenValue)yyVals[-1+yyTop])); ((TokenValue)yyVals[-3+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); db.AddMember (Namespace, type, ((TokenValue)yyVals[-1+yyTop]), new Part (fileID, ((TokenValue)yyVals[-3+yyTop]))); } break; case 209: #line 879 "cs-parser.jay" { ((TokenValue)yyVals[-4+yyTop]).Update (((TokenValue)yyVals[-1+yyTop])); ((TokenValue)yyVals[-4+yyTop]).Update (((TokenValue)yyVals[0+yyTop]), (modStatic ? ".cctor" : ".ctor") + " (" + ((TokenValue)yyVals[-2+yyTop]).val.s + ")"); } break; case 212: #line 891 "cs-parser.jay" { yyVal = new TokenValue (); } break; case 214: #line 897 "cs-parser.jay" { ((TokenValue)yyVals[-4+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); } break; case 215: #line 901 "cs-parser.jay" { ((TokenValue)yyVals[-4+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); } break; case 218: #line 918 "cs-parser.jay" { lexer.EventParsing = true; } break; case 219: #line 922 "cs-parser.jay" { lexer.EventParsing = false; } break; case 223: #line 935 "cs-parser.jay" { lexer.EventParsing = false; } break; case 224: #line 939 "cs-parser.jay" { lexer.EventParsing = true; } break; case 225: #line 946 "cs-parser.jay" { lexer.EventParsing = false; } break; case 226: #line 950 "cs-parser.jay" { lexer.EventParsing = true; } break; case 227: #line 958 "cs-parser.jay" { lexer.PropertyParsing = true; } break; case 228: #line 962 "cs-parser.jay" { lexer.PropertyParsing = false; } break; case 278: #line 1102 "cs-parser.jay" { ((TokenValue)yyVal).val = ((TokenValue)yyVals[-1+yyTop]).val.s + ((TokenValue)yyVals[0+yyTop]).val.s; } break; case 312: #line 1170 "cs-parser.jay" { yyVal = null; } break; case 319: #line 1186 "cs-parser.jay" { note ("section 5.4"); yyVal = yyVals[0+yyTop]; } break; case 335: #line 1234 "cs-parser.jay" { yyVal = new TokenValue (); } break; case 337: #line 1240 "cs-parser.jay" { ((TokenValue)yyVal).val = ((TokenValue)yyVals[0+yyTop]).val.s + ((TokenValue)yyVals[-1+yyTop]).val.s; } break; case 338: #line 1247 "cs-parser.jay" { ((TokenValue)yyVal).val.s = "[" + ((TokenValue)yyVals[-1+yyTop]).val.s + "]"; } break; case 339: #line 1253 "cs-parser.jay" { yyVal = new TokenValue (); } break; case 341: #line 1258 "cs-parser.jay" { ((TokenValue)yyVal).val = ","; } break; case 342: #line 1260 "cs-parser.jay" { ((TokenValue)yyVal).val = ((TokenValue)yyVals[-1+yyTop]).val.s + ","; } break; case 416: #line 1433 "cs-parser.jay" { Types.Push (type); type += (type.Length > 0 ? "." : "") + ((TokenValue)yyVals[-1+yyTop]).val.s; } break; case 417: #line 1439 "cs-parser.jay" { ((TokenValue)yyVals[-7+yyTop]).Update (((TokenValue)yyVals[-6+yyTop])); ((TokenValue)yyVals[-7+yyTop]).Update (((TokenValue)yyVals[-5+yyTop])); ((TokenValue)yyVals[-7+yyTop]).Update (((TokenValue)yyVals[-1+yyTop])); ((TokenValue)yyVals[-7+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); db.AddType (Namespace, type, new Part (fileID, ((TokenValue)yyVals[-7+yyTop]))); type = (string) Types.Pop (); } break; case 418: #line 1450 "cs-parser.jay" { yyVal = new TokenValue (); modStatic = false; } break; case 419: #line 1452 "cs-parser.jay" { modStatic = ((TokenValue)yyVals[0+yyTop]).val.s.IndexOf ("static") >= 0; } break; case 421: #line 1459 "cs-parser.jay" { ((TokenValue)yyVal).val = ((TokenValue)yyVals[-1+yyTop]).val.s + " " + ((TokenValue)yyVals[0+yyTop]).val.s; } break; case 436: #line 1480 "cs-parser.jay" { yyVal = new TokenValue (); } break; case 438: #line 1485 "cs-parser.jay" { yyVal = yyVals[0+yyTop]; } break; case 439: #line 1504 "cs-parser.jay" { ((TokenValue)yyVals[-2+yyTop]).Update (((TokenValue)yyVals[0+yyTop])); } break; case 473: #line 1584 "cs-parser.jay" { yyVal = yyVals[-1+yyTop]; } break; case 482: #line 1606 "cs-parser.jay" { note ("complain if this is a delegate maybe?"); } break; case 485: #line 1616 "cs-parser.jay" { yyVal = yyVals[0+yyTop]; } break; case 490: #line 1642 "cs-parser.jay" { yyVal = yyVals[-1+yyTop]; } break; case 537: #line 1776 "cs-parser.jay" { yyVal = null; } break; case 541: #line 1786 "cs-parser.jay" { yyVal = null; } break; case 544: #line 1796 "cs-parser.jay" { yyVal = null; } break; #line 1319 "-" } yyTop -= yyLen[yyN]; yyState = yyStates[yyTop]; int yyM = yyLhs[yyN]; if (yyState == 0 && yyM == 0) { if (debug != null) debug.shift(0, yyFinal); yyState = yyFinal; if (yyToken < 0) { yyToken = yyLex.advance() ? yyLex.token() : 0; if (debug != null) debug.lex(yyState, yyToken,yyname(yyToken), yyLex.value()); } if (yyToken == 0) { if (debug != null) debug.accept(yyVal); return yyVal; } goto yyLoop; } if (((yyN = yyGindex[yyM]) != 0) && ((yyN += yyState) >= 0) && (yyN < yyTable.Length) && (yyCheck[yyN] == yyState)) yyState = yyTable[yyN]; else yyState = yyDgoto[yyM]; if (debug != null) debug.shift(yyStates[yyTop], yyState); goto yyLoop; } } }
public void Update (TokenValue a, string s) { val = s; Update (a); }
public Part (int id, TokenValue tv) { fileID = id; startRow = tv.sRow; endRow = tv.eRow; }