/// <summary>Returns next token</summary> public Token RawNextToken() { Token token; if (_ch == Eof) { token = new Token(Line, Column, _buffer.Position) { End = new Position(Line, Column, _buffer.Position) }; return(token); } var startPosition = _buffer.Position - 1; token = new Token(Line, Column, startPosition); var lastLine = Line; var lastColumn = Column; var lastAcceptingState = int.MinValue; var lastAcceptingPosition = -1; var stateIndex = 0; while (true) { var nextState = GetNextState(stateIndex); if (nextState <= 0) { if (lastAcceptingState == int.MinValue) { lastAcceptingPosition = _buffer.Position - 1; lastAcceptingState = -1; } var value = _buffer.GetString(startPosition, lastAcceptingPosition); token.Set(lastAcceptingState, value, lastLine, lastColumn, lastAcceptingPosition - 1); if (_buffer.Position > lastAcceptingPosition + 1) { _buffer.Position = lastAcceptingPosition; Line = lastLine; Column = lastColumn; NextChar(); } return(token); } else { var acceptingState = _states[nextState, 0]; if (acceptingState != 0) { lastAcceptingState = acceptingState; lastAcceptingPosition = _buffer.Position; lastLine = Line; lastColumn = Column; } } stateIndex = nextState; NextChar(); } }
public string Process(IBuffer buffer) { // _msgLength = _bytesLeftForCurrentMsg = BitConverter.ToInt32(_buffer, 0); // Encoding.GetString(_buffer, 0, _msgLength) var message = buffer.GetString(0, buffer.Size, encoding); //System.Console.WriteLine("Decoded message: " + message); return(message); }
public Token RawNextToken() { Token token; if (ch == Eof) { return(new Token(line, column, buffer.Position)); } var startPosition = new Position(line, column, buffer.Position - 1); MarkAccepting(TokenStates.SyntaxError); if (ch == '0') { goto State1; } if (ch == '.') { goto State3; } if (ch == '=') { goto State6; } if (ch == '(') { goto State7; } if (ch == ')') { goto State8; } if (ch == '+') { goto State9; } if (ch == '-') { goto State10; } if (ch == '*') { goto State11; } if (ch == '/') { goto State12; } if (ch == '!') { goto State13; } if (ch == '~') { goto State14; } if (ch == 't') { goto State15; } if (ch == 'f') { goto State16; } if ((ch >= '1' && ch <= '9')) { goto State2; } if (ch == '\t' || ch == '\n' || ch == ' ') { goto State5; } if ((ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'e') || (ch >= 'g' && ch <= 's') || (ch >= 'u' && ch <= 'z')) { goto State4; } goto State26; State1: MarkAccepting(TokenStates.Int); NextChar(); if (ch == -1) { goto EndState; } if (ch == '.') { goto State3; } if (ch == 'D') { goto State25; } goto EndState; State2: MarkAccepting(TokenStates.Int); NextChar(); if (ch == -1) { goto EndState; } if (ch == '.') { goto State3; } if (ch == 'D') { goto State25; } if ((ch >= '0' && ch <= '9')) { goto State2; } goto EndState; State3: MarkAccepting(TokenStates.Double); NextChar(); if (ch == -1) { goto EndState; } if ((ch >= '0' && ch <= '9')) { goto State3; } goto EndState; State4: MarkAccepting(TokenStates.Identifier); NextChar(); if (ch == -1) { goto EndState; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) { goto State4; } goto EndState; State5: MarkAccepting(TokenStates.white_space); NextChar(); if (ch == -1) { goto EndState; } if (ch == '\t' || ch == '\n' || ch == ' ') { goto State5; } goto EndState; State6: NextChar(); if (ch == -1) { goto EndState; } if (ch == '>') { goto State24; } goto EndState; State7: MarkAccepting(TokenStates.LeftParen); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State8: MarkAccepting(TokenStates.RightParen); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State9: MarkAccepting(TokenStates.Plus); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State10: MarkAccepting(TokenStates.Minus); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State11: MarkAccepting(TokenStates.Asterisk); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State12: MarkAccepting(TokenStates.Slash); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State13: MarkAccepting(TokenStates.Exclamation); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State14: MarkAccepting(TokenStates.Tilde); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State15: MarkAccepting(TokenStates.Identifier); NextChar(); if (ch == -1) { goto EndState; } if (ch == 'r') { goto State21; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'q') || (ch >= 's' && ch <= 'z')) { goto State4; } goto EndState; State16: MarkAccepting(TokenStates.Identifier); NextChar(); if (ch == -1) { goto EndState; } if (ch == 'a') { goto State17; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'b' && ch <= 'z')) { goto State4; } goto EndState; State17: MarkAccepting(TokenStates.Identifier); NextChar(); if (ch == -1) { goto EndState; } if (ch == 'l') { goto State18; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'k') || (ch >= 'm' && ch <= 'z')) { goto State4; } goto EndState; State18: MarkAccepting(TokenStates.Identifier); NextChar(); if (ch == -1) { goto EndState; } if (ch == 's') { goto State19; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'r') || (ch >= 't' && ch <= 'z')) { goto State4; } goto EndState; State19: MarkAccepting(TokenStates.Identifier); NextChar(); if (ch == -1) { goto EndState; } if (ch == 'e') { goto State20; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'd') || (ch >= 'f' && ch <= 'z')) { goto State4; } goto EndState; State20: MarkAccepting(TokenStates.@false); NextChar(); if (ch == -1) { goto EndState; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) { goto State4; } goto EndState; State21: MarkAccepting(TokenStates.Identifier); NextChar(); if (ch == -1) { goto EndState; } if (ch == 'u') { goto State22; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 't') || (ch >= 'v' && ch <= 'z')) { goto State4; } goto EndState; State22: MarkAccepting(TokenStates.Identifier); NextChar(); if (ch == -1) { goto EndState; } if (ch == 'e') { goto State23; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'd') || (ch >= 'f' && ch <= 'z')) { goto State4; } goto EndState; State23: MarkAccepting(TokenStates.@true); NextChar(); if (ch == -1) { goto EndState; } if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z')) { goto State4; } goto EndState; State24: MarkAccepting(TokenStates.EqualGreaterThan); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State25: MarkAccepting(TokenStates.DoubleInt); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State26: MarkAccepting(TokenStates.SyntaxError); NextChar(); if (ch == -1) { goto EndState; } if (ch == '\t' || ch == '\n' || ch == ' ' || ch == '!' || (ch >= '(' && ch <= '+') || (ch >= '-' && ch <= '9') || ch == '=' || (ch >= 'A' && ch <= 'Z') || ch == '_' || (ch >= 'a' && ch <= 'z') || ch == '~') { goto EndState; } goto State26; EndState: if (lastAcceptingPosition == -1) { lastAcceptingPosition = buffer.Position; } token = new Token(startPosition, new Position(lastLine, lastColumn, lastAcceptingPosition - 1), lastAcceptingState, buffer.GetString(startPosition.Ch, lastAcceptingPosition)); if (buffer.Position != lastAcceptingPosition) { buffer.Position = lastAcceptingPosition; line = lastLine; column = lastColumn; NextChar(); } return(token); EndState2: token = new Token(startPosition, new Position(lastLine, lastColumn, lastAcceptingPosition - 1), lastAcceptingState, buffer.GetString(startPosition.Ch, lastAcceptingPosition)); NextChar(); return(token); }
Token RawNextToken() { Token token; if (ch == Eof) { return(new Token(line, column, buffer.Position)); } var startPosition = new Position(line, column, buffer.Position - 1); MarkAccepting(TokenStates.SyntaxError); if (ch == '0') { goto State2; } if (ch == '/') { goto State3; } if ((ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { goto State1; } goto EndState2; State1: MarkAccepting(TokenStates.word); NextChar(); if (ch == '-' || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z')) { goto State1; } goto EndState; State2: NextChar(); if (ch == 'x') { goto State8; } goto EndState; State3: NextChar(); if (ch == '/') { goto State4; } if (ch == '*') { goto State5; } goto EndState; State4: MarkAccepting(TokenStates.comment); NextChar(); if (!((ch == -1) || ch == '\n')) { goto State4; } goto EndState; State5: NextChar(); if (ch == '*') { goto State6; } if (!((ch == -1) || ch == '*')) { goto State5; } goto EndState; State6: NextChar(); if (ch == '/') { goto State7; } if (!((ch == -1) || ch == '/')) { goto State5; } goto EndState; State7: MarkAccepting(TokenStates.multi_line_comment); NextChar(); goto EndState; State8: NextChar(); if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { goto State9; } goto EndState; State9: MarkAccepting(TokenStates.hexadecimal); NextChar(); if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) { goto State9; } goto EndState; EndState: if (lastAcceptingState == TokenStates.SyntaxError) { lastAcceptingPosition = buffer.Position - 1; lastAcceptingState = -1; } token = new Token(startPosition, new Position(lastLine, lastColumn, lastAcceptingPosition - 1), lastAcceptingState, buffer.GetString(startPosition.Ch, lastAcceptingPosition)); if (buffer.Position != lastAcceptingPosition) { buffer.Position = lastAcceptingPosition; line = lastLine; column = lastColumn; NextChar(); } return(token); EndState2: token = new Token(startPosition, new Position(lastLine, lastColumn, lastAcceptingPosition - 1), lastAcceptingState, buffer.GetString(startPosition.Ch, lastAcceptingPosition)); NextChar(); return(token); }
Token RawNextToken() { var token = new Token(Line, Column, _buffer.Position); if (_ch != Eof) { MarkAccepting(TokenTypes.Empty); goto EndState; } MarkAccepting(TokenTypes.SyntaxError); State0: if (_ch == '0') { goto State1; } if (_ch == '+') { goto State5; } if (_ch == '-') { goto State6; } if (_ch == '*') { goto State7; } if (_ch == '/') { goto State8; } if (_ch == '\t' || _ch == '\n' || _ch == ' ') { goto State4; } if ((_ch >= '1' && _ch <= '9')) { goto State2; } if ((_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'z')) { goto State3; } goto EndState; State1: MarkAcceptable(TokenTypes.Int); goto EndState; State2: MarkAcceptable(TokenTypes.Int); if ((_ch >= '0' && _ch <= '9')) { goto State2; } goto EndState; State3: MarkAcceptable(TokenTypes.identifier); if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'z')) { goto State3; } goto EndState; State4: MarkAcceptable(TokenTypes.white_space); if (_ch == '\t' || _ch == '\n' || _ch == ' ') { goto State4; } goto EndState; State5: MarkAcceptable(TokenTypes.Plus); goto EndState; State6: MarkAcceptable(TokenTypes.Minus); goto EndState; State7: MarkAcceptable(TokenTypes.Asterisk); goto EndState; State8: MarkAcceptable(TokenTypes.Slash); goto EndState; EndState: if (_lastAcceptingState == TokenType.SyntaxError) { _lastAcceptingPosition = _buffer.Position - 1; _lastAcceptingState = -1; } var value = _buffer.GetString(token.Beg, _lastAcceptingPosition); token.Set(_lastAcceptingState, value, _lastLine, _lastColumn, _lastAcceptingPosition - 1); if (_buffer.Position != _lastAcceptingPosition) { _buffer.Position = lastAcceptingPosition; Line = _lastLine; Column = _lastColumn; NextChar(); } return(token); }
public Token RawNextToken() { Token token; if (ch == Eof) { return(new Token(line, column, buffer.Position)); } var startPosition = new Position(line, column, buffer.Position - 1); MarkAccepting(TokenStates.SyntaxError); if (ch == ',') { goto State1; } if (ch == 'a') { goto State2; } if (ch == 'b') { goto State3; } if (ch == 'x') { goto State4; } goto State13; State1: MarkAccepting(TokenStates.comma); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State2: NextChar(); if (ch == -1) { goto EndState; } if (ch == 'a') { goto State7; } goto EndState; State3: NextChar(); if (ch == -1) { goto EndState; } if (ch == 'b') { goto State5; } goto EndState; State4: MarkAccepting(TokenStates.t3); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State5: NextChar(); if (ch == -1) { goto EndState; } if (ch == 'b') { goto State6; } goto EndState; State6: MarkAccepting(TokenStates.t2); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State7: NextChar(); if (ch == -1) { goto EndState; } if (ch == 'a') { goto State8; } goto EndState; State8: MarkAccepting(TokenStates.t1); NextChar(); if (ch == -1) { goto EndState; } if (ch == 'b') { goto State9; } goto EndState; State9: NextChar(); if (ch == -1) { goto EndState; } if (ch == 'b') { goto State10; } goto EndState; State10: NextChar(); if (ch == -1) { goto EndState; } if (ch == 'b') { goto State11; } goto EndState; State11: NextChar(); if (ch == -1) { goto EndState; } if (ch == 'b') { goto State12; } goto EndState; State12: MarkAccepting(TokenStates.t1); NextChar(); if (ch == -1) { goto EndState; } goto EndState; State13: MarkAccepting(TokenStates.SyntaxError); NextChar(); if (ch == -1) { goto EndState; } if (ch == ',' || ch == 'a' || ch == 'b' || ch == 'x') { goto EndState; } goto State13; EndState: if (lastAcceptingPosition == -1) { lastAcceptingPosition = buffer.Position; } token = new Token(startPosition, new Position(lastLine, lastColumn, lastAcceptingPosition - 1), lastAcceptingState, buffer.GetString(startPosition.Ch, lastAcceptingPosition)); if (buffer.Position != lastAcceptingPosition) { buffer.Position = lastAcceptingPosition; line = lastLine; column = lastColumn; NextChar(); } return(token); EndState2: token = new Token(startPosition, new Position(lastLine, lastColumn, lastAcceptingPosition - 1), lastAcceptingState, buffer.GetString(startPosition.Ch, lastAcceptingPosition)); NextChar(); return(token); }
Token RawNextToken() { Token token; if (_ch == Eof) { token = new Token(_line, _column, _buffer.Position); MarkAccepting(TokenStates.Empty); goto EndState; } token = new Token(_line, _column, _buffer.Position - 1); MarkAccepting(TokenStates.SyntaxError); if (_ch == '0') { goto State1; } if (_ch == '.') { goto State3; } if (_ch == 't') { goto State6; } if (_ch == 'f') { goto State7; } if (_ch == '=') { goto State8; } if (_ch == '(') { goto State9; } if (_ch == ')') { goto State10; } if (_ch == '+') { goto State11; } if (_ch == '-') { goto State12; } if (_ch == '*') { goto State13; } if (_ch == '/') { goto State14; } if (_ch == '!') { goto State15; } if (_ch == '~') { goto State16; } if (_ch == '\t' || _ch == '\n' || _ch == ' ') { goto State5; } if ((_ch >= '1' && _ch <= '9')) { goto State2; } if ((_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'e') || (_ch >= 'g' && _ch <= 's') || (_ch >= 'u' && _ch <= 'z')) { goto State4; } goto EndState2; State1: MarkAccepting(TokenStates.Int); NextChar(); if (_ch == '.') { goto State3; } if (_ch == 'D') { goto State25; } goto EndState; State2: MarkAccepting(TokenStates.Int); NextChar(); if (_ch == '.') { goto State3; } if (_ch == 'D') { goto State25; } if ((_ch >= '0' && _ch <= '9')) { goto State2; } goto EndState; State3: MarkAccepting(TokenStates.Double); NextChar(); if ((_ch >= '0' && _ch <= '9')) { goto State3; } goto EndState; State4: MarkAccepting(TokenStates.Identifier); NextChar(); if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'z')) { goto State4; } goto EndState; State5: MarkAccepting(TokenStates.white_space); NextChar(); if (_ch == '\t' || _ch == '\n' || _ch == ' ') { goto State5; } goto EndState; State6: MarkAccepting(TokenStates.Identifier); NextChar(); if (_ch == 'r') { goto State22; } if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'q') || (_ch >= 's' && _ch <= 'z')) { goto State4; } goto EndState; State7: MarkAccepting(TokenStates.Identifier); NextChar(); if (_ch == 'a') { goto State18; } if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'b' && _ch <= 'z')) { goto State4; } goto EndState; State8: NextChar(); if (_ch == '>') { goto State17; } goto EndState; State9: MarkAccepting(TokenStates.LeftParen); NextChar(); goto EndState; State10: MarkAccepting(TokenStates.RightParen); NextChar(); goto EndState; State11: MarkAccepting(TokenStates.Plus); NextChar(); goto EndState; State12: MarkAccepting(TokenStates.Minus); NextChar(); goto EndState; State13: MarkAccepting(TokenStates.Asterisk); NextChar(); goto EndState; State14: MarkAccepting(TokenStates.Slash); NextChar(); goto EndState; State15: MarkAccepting(TokenStates.Exclamation); NextChar(); goto EndState; State16: MarkAccepting(TokenStates.Tilde); NextChar(); goto EndState; State17: MarkAccepting(TokenStates.EqualGreaterThan); NextChar(); goto EndState; State18: MarkAccepting(TokenStates.Identifier); NextChar(); if (_ch == 'l') { goto State19; } if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'k') || (_ch >= 'm' && _ch <= 'z')) { goto State4; } goto EndState; State19: MarkAccepting(TokenStates.Identifier); NextChar(); if (_ch == 's') { goto State20; } if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'r') || (_ch >= 't' && _ch <= 'z')) { goto State4; } goto EndState; State20: MarkAccepting(TokenStates.Identifier); NextChar(); if (_ch == 'e') { goto State21; } if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'd') || (_ch >= 'f' && _ch <= 'z')) { goto State4; } goto EndState; State21: MarkAccepting(TokenStates.False); NextChar(); if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'z')) { goto State4; } goto EndState; State22: MarkAccepting(TokenStates.Identifier); NextChar(); if (_ch == 'u') { goto State23; } if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 't') || (_ch >= 'v' && _ch <= 'z')) { goto State4; } goto EndState; State23: MarkAccepting(TokenStates.Identifier); NextChar(); if (_ch == 'e') { goto State24; } if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'd') || (_ch >= 'f' && _ch <= 'z')) { goto State4; } goto EndState; State24: MarkAccepting(TokenStates.True); NextChar(); if ((_ch >= '0' && _ch <= '9') || (_ch >= 'A' && _ch <= 'Z') || _ch == '_' || (_ch >= 'a' && _ch <= 'z')) { goto State4; } goto EndState; State25: MarkAccepting(TokenStates.DoubleInt); NextChar(); goto EndState; EndState: if (_lastAcceptingState == TokenStates.SyntaxError) { _lastAcceptingPosition = _buffer.Position - 1; _lastAcceptingState = -1; } var value = _buffer.GetString(token.Beg, _lastAcceptingPosition); token.Set(_lastAcceptingState, value, _lastLine, _lastColumn, _lastAcceptingPosition - 1); if (_buffer.Position != _lastAcceptingPosition) { _buffer.Position = _lastAcceptingPosition; _line = _lastLine; _column = _lastColumn; NextChar(); } return(token); EndState2: value = _buffer.GetString(token.Beg, _lastAcceptingPosition); token.Set(_lastAcceptingState, value, _lastLine, _lastColumn, _lastAcceptingPosition - 1); NextChar(); return(token); }