void Get() { while (true) { t = la; la = _scanner.Scan(); if (la.kind <= maxT) { errDist++; break; } la = t; } }
public string Parse() { la = Scanner.EmptyToken; try { Get(); ScriptVM(); Expect(0); } catch (Exception ex) { return ex.Message; } return null; }
public string Load(string s) { if (string.IsNullOrEmpty (s)) { return "No source code"; } buffer.Data = s; Reset(); try { Token t; while (true) { t = NextToken (); if (t.kind == 0) { break; } if (t.kind == Parser._STRING) { t.val = t.val.Substring (1, t.val.Length - 2); } _tokens.Add (t); //Console.WriteLine ("token " + (_tokens.Count - 1) + " : " + t.kind + " => " + t.val); } } catch (Exception ex) { return ex.Message; } return null; }
public string CallFunction() { la = Scanner.EmptyToken; _isReturned = false; RetVal = new ScriptVar(); try { Get(); Block(); } catch (Exception ex) { return ex.Message; } return null; }
// get the next token (possibly a token already seen during peeking) public Token NextToken() { while (ch == ' ' || ch >= 9 && ch <= 10 || ch == 13 ) NextCh(); if (ch == '/' && Comment0() ||ch == '/' && Comment1()) return NextToken(); int recKind = noSym; int recEnd = pos; t = new Token(); t.pos = pos; t.col = col; t.line = line; t.charPos = charPos; int state; if (start.ContainsKey(ch)) { state = (int) start[ch]; } else { state = 0; } tlen = 0; AddCh(); switch (state) { case -1: { t.kind = eofSym; break; } // NextCh already done case 0: { if (recKind != noSym) { tlen = recEnd - t.pos; SetScannerBehindT(); } t.kind = recKind; break; } // NextCh already done case 1: recEnd = pos; recKind = 1; if (ch >= '0' && ch <= '9' || ch >= 'A' && ch <= 'Z' || ch == '_' || ch >= 'a' && ch <= 'z') {AddCh(); goto case 1;} else {t.kind = 1; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 2: recEnd = pos; recKind = 2; if (ch >= '0' && ch <= '9') {AddCh(); goto case 2;} else if (ch == '.') {AddCh(); goto case 3;} else {t.kind = 2; break;} case 3: if (ch >= '0' && ch <= '9') {AddCh(); goto case 4;} else {goto case 0;} case 4: recEnd = pos; recKind = 2; if (ch >= '0' && ch <= '9') {AddCh(); goto case 4;} else {t.kind = 2; break;} case 5: if (ch <= '&' || ch >= '(' && ch <= 65535) {AddCh(); goto case 5;} else if (ch == 39) {AddCh(); goto case 6;} else {goto case 0;} case 6: {t.kind = 3; break;} case 7: {t.kind = 5; break;} case 8: {t.kind = 6; break;} case 9: {t.kind = 7; break;} case 10: {t.kind = 8; break;} case 11: {t.kind = 9; break;} case 12: {t.kind = 11; break;} case 13: if (ch == '|') {AddCh(); goto case 14;} else {goto case 0;} case 14: {t.kind = 12; break;} case 15: if (ch == '&') {AddCh(); goto case 16;} else {goto case 0;} case 16: {t.kind = 13; break;} case 17: {t.kind = 14; break;} case 18: if (ch == '=') {AddCh(); goto case 19;} else {goto case 0;} case 19: {t.kind = 15; break;} case 20: {t.kind = 18; break;} case 21: {t.kind = 19; break;} case 22: {t.kind = 20; break;} case 23: {t.kind = 21; break;} case 24: {t.kind = 22; break;} case 25: {t.kind = 23; break;} case 26: {t.kind = 30; break;} case 27: recEnd = pos; recKind = 25; if (ch == '=') {AddCh(); goto case 17;} else {t.kind = 25; break;} case 28: recEnd = pos; recKind = 16; if (ch == '=') {AddCh(); goto case 20;} else {t.kind = 16; break;} case 29: recEnd = pos; recKind = 17; if (ch == '=') {AddCh(); goto case 21;} else {t.kind = 17; break;} } t.val = new String(tval, 0, tlen); return t; }