using System; using Microsoft.Contracts; namespace -->namespace { public class Parser { -->constants const bool T = true; const bool x = false; const int minErrDist = 2; static Token/*!*/ token; // last recognized token static Token/*!*/ t; // lookahead token static int errDist = minErrDist; -->declarations static void Error(int n) { if (errDist >= minErrDist) Errors.SynErr(n, t.filename, t.line, t.col); errDist = 0; } public static void SemErr(string! msg) { if (errDist >= minErrDist) Errors.SemErr(token.filename, token.line, token.col, msg); errDist = 0; } public static void SemErr(IToken! tok, string! msg) { Errors.SemErr(tok.filename, tok.line, tok.col, msg); } static void Get() { for (;;) { token = t; t = Scanner.Scan(); if (t.kind<=maxT) {errDist++; return;} -->pragmas t = token; } } static void Expect(int n) { if (t.kind==n) Get(); else Error(n); } static bool StartOf(int s) { return set[s, t.kind]; } static void ExpectWeak(int n, int follow) { if (t.kind == n) Get(); else { Error(n); while (!StartOf(follow)) Get(); } } static bool WeakSeparator(int n, int syFol, int repFol) { bool[] s = new bool[maxT+1]; if (t.kind == n) {Get(); return true;} else if (StartOf(repFol)) return false; else { for (int i=0; i <= maxT; i++) { s[i] = set[syFol, i] || set[repFol, i] || set[0, i]; } Error(n); while (!s[t.kind]) Get(); return StartOf(syFol); } } -->productions public static void Parse() { Errors.SynErr = new ErrorProc(SynErr); t = new Token(); Get(); -->parseRoot } [Microsoft.Contracts.Verify(false)] static void SynErr(int n, string filename, int line, int col) { Errors.count++; Console.Write("{0}({1},{2}): syntax error: ", filename, line, col); string s; switch (n) { -->errors default: s = "error " + n; break; } Console.WriteLine(s); } static bool[,]! set = { -->initialization }; [Microsoft.Contracts.Verify(false)] static Parser() {} } // end Parser } // end namespace $$$