public int lex() { pushPos(); messageChain(); if (!onNULL()) { if (errorToken == null) { if (tokenStream.Count != 0) { errorToken = currentToken(); } else { int restLength = s.Length - currentPos; int limit = restLength < MaxErrorToken ? restLength : MaxErrorToken; errorToken = addTokenStringType(s.Substring(currentPos, limit), IoTokenType.NO_TOKEN); } errorToken.error = "Syntax error near this location"; } return(-1); } return(0); }
public IoToken pop() { IoToken first = top(); resultIndex++; return(first); }
// terminators public int readTerminator() { int terminated = 0; pushPos(); readSeparator(); while (readTerminatorChar() != 0) { terminated = 1; readSeparator(); } if (terminated != 0) { IoToken top = currentToken(); // avoid double terminators if (top != null && top.type == IoTokenType.TERMINATOR_TOKEN) { return(1); } addTokenStringType(";", IoTokenType.TERMINATOR_TOKEN); popPos(); return(1); } popPosBack(); return(0); }
void parseName(IoState state, IoLexer lexer) { IoToken token = lexer.pop(); messageName = IoSeq.createSymbolInMachine(state, token.name); ifPossibleCacheToken(token); //rawSetLineNumber(token.lineNumber); //rawSetCharNumber(token.charNumber); }
public void print() { IoToken first = tokenStream[0]; if (first != null) { first.print(); } Console.WriteLine(); }
public void printTokens() { int i; for (i = 0; i < tokenStream.Count; i++) { IoToken t = tokenStream[i]; Console.Write("'{0}' {1}", t.name, t.typeName()); if (i < tokenStream.Count - 1) { Console.Write(", "); } } Console.WriteLine(); }
public void popPosBack() { int i = Convert.ToInt32(tokenStack.Pop()); int topIndex = Convert.ToInt32(tokenStack.Peek()); if (i > -1) { if (i != topIndex) { IoToken parent = currentToken(); if (parent != null) { parent.nextToken = null; } } } currentPos = Convert.ToInt32(posStack.Pop()); }
public int readMonoQuote() { pushPos(); if (nextChar() == '"') { while (true) { char c = nextChar(); if (c == '"') { break; } if (c == '\\') { nextChar(); continue; } if (c == 0) { errorToken = currentToken(); if (errorToken != null) { errorToken.error = "unterminated quote"; } popPosBack(); return(0); } } grabTokenType(IoTokenType.MONOQUOTE_TOKEN); popPos(); return(1); } popPosBack(); return(0); }
void ifPossibleCacheToken(IoToken token) { IoSeq method = this.messageName; IoObject r = null; switch (token.type) { case IoTokenType.TRIQUOTE_TOKEN: break; case IoTokenType.MONOQUOTE_TOKEN: r = IoSeq.createSymbolInMachine( method.state, IoSeq.rawAsUnescapedSymbol( IoSeq.rawAsUnquotedSymbol( IoSeq.createObject(method.state, method.value) ) ).value ); break; case IoTokenType.NUMBER_TOKEN: r = IoNumber.newWithDouble(this.state, Convert.ToDouble(method.value, CultureInfo.InvariantCulture)); break; default: if (method.value.Equals("nil")) { r = state.ioNil; } else if (method.value.Equals("true")) { r = state.ioTrue; } else if (method.value.Equals("false")) { r = state.ioFalse; } break; } this.cachedResult = r; }
public IoToken addTokenStringType(string s1, IoTokenType type) { IoToken top = currentToken(); IoToken t = new IoToken(); t.lineNumber = currentLineNumber(); t.charNumber = currentPos; if (t.charNumber < 0) { System.Console.WriteLine("bad t->charNumber = %i\n", t.charNumber); } t.name = s1; t.type = type; if (top != null) { top.nextToken = t; } tokenStream.Add(t); return(t); }
public int lex() { pushPos(); messageChain(); if (!onNULL()) { if (errorToken == null) { if (tokenStream.Count != 0) { errorToken = currentToken(); } else { errorToken = addTokenStringType(s.Substring(currentPos, 30), IoTokenType.NO_TOKEN); } errorToken.error = "Syntax error near this location"; } return(-1); } return(0); }
public IoToken addTokenStringType(string s1, IoTokenType type) { IoToken top = currentToken(); IoToken t = new IoToken(); t.lineNumber = currentLineNumber(); t.charNumber = currentPos; if (t.charNumber < 0) { System.Console.WriteLine("bad t->charNumber = %i\n", t.charNumber); } t.name = s1; t.type = type; if (top != null) { top.nextToken = t; } tokenStream.Add(t); return t; }
public int lex() { pushPos(); messageChain(); if (!onNULL()) { if (errorToken == null) { if (tokenStream.Count != 0) { errorToken = currentToken(); } else { errorToken = addTokenStringType(s.Substring(currentPos, 30), IoTokenType.NO_TOKEN); } errorToken.error = "Syntax error near this location"; } return -1; } return 0; }
public int readMonoQuote() { pushPos(); if (nextChar() == '"') { while (true) { char c = nextChar(); if (c == '"') { break; } if (c == '\\') { nextChar(); continue; } if (c == 0) { errorToken = currentToken(); if (errorToken != null) { errorToken.error = "unterminated quote"; } popPosBack(); return 0; } } grabTokenType(IoTokenType.MONOQUOTE_TOKEN); popPos(); return 1; } popPosBack(); return 0; }
public void readMessageError(string name) { popPosBack(); errorToken = currentToken(); errorToken.error = name; }