public SclVal(Token token, SclElement owner) { Token = token; Owner = owner; Val = Read(token); }
private string Read(Token token) { var str = token.val; if (token.kind == _sVal) return str; var sb = new StringBuilder(str.Length - 2); for (int i = 1; i < str.Length - 1; i++) { var c = str[i]; if (c == '\\') { i++; c = str[i]; if (c == 'a') c = '\a'; else if (c == 'b') c = '\b'; else if (c == 'f') c = '\f'; else if (c == 'n') c = '\n'; else if (c == 'r') c = '\r'; else if (c == 't') c = '\t'; else if (c == 'v') c = '\v'; else if (c == '"') c = '"'; else if (c == '\\') c = '\\'; } sb.Append(c); } return sb.ToString(); }
public void Parse() { la = new Token(); la.val = ""; Get(); Scl(); Expect(0); }
void Get() { for (;;) { t = la; la = scanner.Scan(); if (la.kind <= maxT) { ++errDist; break; } la = t; } }
Token NextToken() { while (ch == ' ' || ch == 9 || ch == 13 || ch == ' ' ) NextCh(); if (ch == '#' && Comment0()) 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: {t.kind = 1; break;} case 2: {t.kind = 2; break;} case 3: recEnd = pos; recKind = 3; if (ch <= 8 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= 31 || ch == '!' || ch >= '#' && ch <= ':' || ch >= '<' && ch <= 65535) {AddCh(); goto case 3;} else {t.kind = 3; t.val = new String(tval, 0, tlen); CheckLiteral(); return t;} case 4: if (ch == '"') {AddCh(); goto case 5;} else if (ch <= 9 || ch >= 11 && ch <= 12 || ch >= 14 && ch <= '!' || ch >= '#' && ch <= '[' || ch >= ']' && ch <= 65535) {AddCh(); goto case 4;} else if (ch == 92) {AddCh(); goto case 6;} else {goto case 0;} case 5: {t.kind = 4; break;} case 6: if (ch == '"' || ch == '0' || ch == 92 || ch >= 'a' && ch <= 'b' || ch == 'f' || ch == 'n' || ch == 'r' || ch == 't' || ch == 'v') {AddCh(); goto case 4;} else {goto case 0;} } t.val = new String(tval, 0, tlen); return t; }
void Init() { pos = -1; line = 1; col = 0; charPos = -1; oldEols = 0; NextCh(); if (ch == 0xEF) { // check optional byte order mark for UTF-8 NextCh(); int ch1 = ch; NextCh(); int ch2 = ch; if (ch1 != 0xBB || ch2 != 0xBF) { throw new FatalError(String.Format("illegal byte order mark: EF {0,2:X} {1,2:X}", ch1, ch2)); } col = 0; charPos = -1; NextCh(); } pt = tokens = new Token(); // first token is a dummy }
// get the next token (possibly a token already seen during peeking) public Token Scan() { if (tokens.next == null) { return NextToken(); } else { pt = tokens = tokens.next; return tokens; } }
// make sure that peeking starts at the current scan position public void ResetPeek() { pt = tokens; }
// peek for the next token, ignore pragmas public Token Peek() { do { if (pt.next == null) { pt.next = NextToken(); } pt = pt.next; } while (pt.kind > maxT); // skip pragmas return pt; }