2009-09-19 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / jay / skeleton.cs
index 8584cb24a18f1056d02da6038e9aed19aec2ff99..ebed7b7c15cd26bea65eae4e018b1186d5de21b1 100644 (file)
@@ -23,6 +23,9 @@
 .    yyerror(message, null);
 .  }
 .
+.  /* An EOF token */
+.  public int eof_token;
+.
 .  /** (syntax) error message.
 .      Can be overwritten to control message format.
 .      @param message text to be displayed.
@@ -56,14 +59,14 @@ t    if ((name = yyNames[token]) != null) return name;
 t    return "[unknown]";
 t  }
 .
+.  int yyExpectingState;
 .  /** computes list of expected tokens on error by tracing the tables.
 .      @param state for which to compute the list.
 .      @return list of token names.
 .    */
-.  protected string[] yyExpecting (int state) {
+.  protected int [] yyExpectingTokens (int state){
 .    int token, n, len = 0;
 .    bool[] ok = new bool[yyNames.Length];
-.
 .    if ((n = yySindex[state]) != 0)
 .      for (token = n < 0 ? -n : 0;
 .           (token < yyNames.Length) && (n+token < yyTable.Length); ++ token)
@@ -78,10 +81,16 @@ t  }
 .          ++ len;
 .          ok[token] = true;
 .        }
-.
-.    string [] result = new string[len];
+.    int [] result = new int [len];
 .    for (n = token = 0; n < len;  ++ token)
-.      if (ok[token]) result[n++] = yyNames[token];
+.      if (ok[token]) result[n++] = token;
+.    return result;
+.  }
+.  protected string[] yyExpecting (int state) {
+.    int [] tokens = yyExpectingTokens (state);
+.    string [] result = new string[tokens.Length];
+.    for (int n = 0; n < tokens.Length;  n++)
+.      result[n++] = yyNames[tokens [n]];
 .    return result;
 .  }
 .
@@ -171,8 +180,10 @@ t              debug.shift(yyState, yyTable[yyN], yyErrorFlag-1);
 .            switch (yyErrorFlag) {
 .  
 .            case 0:
+.              yyExpectingState = yyState;
 .              // yyerror(String.Format ("syntax error, got token `{0}'", yyname (yyToken)), yyExpecting(yyState));
 t              if (debug != null) debug.error("syntax error");
+.              if (yyToken == 0 /*eof*/ || yyToken == eof_token) throw new yyParser.yyUnexpectedEof ();
 .              goto case 1;
 .            case 1: case 2:
 .              yyErrorFlag = 3;
@@ -332,6 +343,12 @@ t        if (debug != null) debug.shift(yyStates[yyTop], yyState);
 .    public yyException (string message) : base (message) {
 .    }
 .  }
+.  internal class yyUnexpectedEof : yyException {
+.    public yyUnexpectedEof (string message) : base (message) {
+.    }
+.    public yyUnexpectedEof () : base ("") {
+.    }
+.  }
 .
 .  /** must be implemented by a scanner object to supply input to the parser.
 .    */