private void Unexpected(Report Report, TokenInfo token)
 {
     throw new NotImplementedException();
 }
 private Modifier GetModifier(TokenInfo token)
 {
     return (Modifier) Enum.Parse(typeof (Modifier), token.Value);
 }
        private bool Expect(Token token, ref TokenInfo tokenInfo, string message)
        {
            tokenInfo = GetNextToken();

            if (tokenInfo.Is(token))
            {
                return true;
            }

            Report.AddError("?", message, tokenInfo.SourceFile,
                            new SourceSpan(tokenInfo.GetSourceLocation(), default(SourceLocation)),
                            null);

            return false;
        }
        private bool ExpectIdentifier(ref TokenInfo tokenInfo)
        {
            tokenInfo = GetNextToken();

            if (tokenInfo.Is(Token.Identifier))
            {
                return true;
            }

            Report.AddItem(VBErrors.IdentifierExpected, SourceFile,
                           new SourceSpan(tokenInfo.GetSourceLocation(), default(SourceLocation)),
                           null);

            return false;
        }
        private bool Expect(Token token, ref TokenInfo tokenInfo)
        {
            tokenInfo = GetNextToken();

            if (tokenInfo.Is(token))
            {
                return true;
            }

            Expected(Report, token, ref tokenInfo);
            return false;
        }
 private void Expected(Report Report, Token token, ref TokenInfo token_2)
 {
     throw new NotImplementedException();
 }
 private bool charStringCond(TokenInfo token)
 {
     return !token.Is(Token.DoubleQuote) && !(token.Is(Token.EOL) || token.Is(Token.EOF));
 }
 private void FeatureNotImplemented(Report Report, string p, TokenInfo token)
 {
     throw new NotImplementedException();
 }
        /// <summary>
        /// Scans for the next token in the stream.
        /// </summary>
        /// <returns>A token. If it is end-of-stream then it is an EOF token.</returns>
        private TokenInfo scan()
        {
            var sb = new StringBuilder();

            int ln, col; //The start location of the token

            //bool isBad = false; //Is it a bad token?

            char ch; //First lookahead variable
            //char? ch2 = null; //Second lookahead variable (temporary)

            ln = 1;
            col = 1;

            while (!isEos())
            {
                ln = Ln;
                col = Col;

                ch = peekChar();

                if (char.IsLetter(ch) || ch == '_')
                {
                    //An identifier token.

                    while (!isEos() && (char.IsLetterOrDigit(ch) || ch == '_'))
                    {
                        readChar();

                        sb.Append(ch);

                        ch = peekChar();
                    }

                    //string rw = getReservedWord(sb.ToString());

                    //if (rw != null)
                    //{
                    //    return reservedWord(rw, sourceFile, ln, col);
                    //}

                    string rw = sb.ToString();

                    if (isReservedWord(rw))
                    {
                        return reservedWord(rw, sourceFile, ln, col);
                    }

                    return identifier(sb, sourceFile, ln, col);
                }
                else if (char.IsNumber(ch))
                {
                    #region Old code

                    ////A number token.

                    //bool hasReadPeriod = false;
                    //bool isReal = false;

                    //while (!this.isEos() && (char.IsDigit(ch) || ch == '.'))
                    //{
                    //    this.readChar();

                    //    if (hasReadPeriod)
                    //    {
                    //        if (char.IsDigit((char)ch))
                    //        {
                    //            hasReadPeriod = false;
                    //        }
                    //    }
                    //    else
                    //    {
                    //        if (ch2 != null)
                    //        {
                    //            if (char.IsDigit((char)ch2) && ch == '.')
                    //            {
                    //                hasReadPeriod = true;
                    //                isReal = true;

                    //                ch2 = this.peekChar();

                    //                if (!char.IsDigit((char)ch2))
                    //                {
                    //                    this.Report.ReportError("Expected digit.", this.sourceFile, this.GetSourceLocation(), null);
                    //                    isBad = true;
                    //                }
                    //            }
                    //        }

                    //    }

                    //    sb.Append(ch);

                    //    ch2 = ch;
                    //    ch = this.peekChar();
                    //}

                    //if (isBad)
                    //{
                    //    //It is a bad token.
                    //    return badToken(sb.ToString(), ln, col);
                    //}

                    //if (isReal)
                    //{
                    //    return realNumber(sb, ln, col);
                    //}

                    #endregion

                    while (char.IsDigit(ch))
                    {
                        readChar();

                        sb.Append(ch);

                        ch = peekChar();
                    }

                    return number(sb, sourceFile, ln, col);

                    #region Old code

                    // return integerNumber(sb, this.sourceFile, ln, col);

                    #endregion
                }
                else
                {
                    //Symbol tokens.
                    TokenInfo token;

                    switch (ch)
                    {
                        case '+':
                            token = new TokenInfo(Token.Plus, TokenStringConstants.Plus, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '-':
                            token = new TokenInfo(Token.Minus, TokenStringConstants.Minus, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '*':
                            token = new TokenInfo(Token.Star, TokenStringConstants.Star, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '/':
                            token = new TokenInfo(Token.Slash, TokenStringConstants.Slash, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '\\':
                            token = new TokenInfo(Token.Backslash, TokenStringConstants.Backslash, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '%':
                            token = new TokenInfo(Token.Percent, TokenStringConstants.Percent, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '&':
                            token = new TokenInfo(Token.Ampersand, TokenStringConstants.Ampersand, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '=':
                            token = new TokenInfo(Token.Equality, TokenStringConstants.Equality, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '^':
                            token = new TokenInfo(Token.Caret, TokenStringConstants.Caret, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '\'':
                            token = new TokenInfo(Token.SingleQuote, TokenStringConstants.SingleQuote, sourceFile, ln,
                                                  col);
                            readChar();
                            return token;

                        case '\"':
                            token = new TokenInfo(Token.DoubleQuote, TokenStringConstants.DoubleQuote, sourceFile, ln,
                                                  col);
                            readChar();
                            return token;

                        case '.':
                            token = new TokenInfo(Token.Period, TokenStringConstants.Period, sourceFile, ln, col);
                            readChar();
                            return token;

                        case ',':
                            token = new TokenInfo(Token.Comma, TokenStringConstants.Comma, sourceFile, ln, col);
                            readChar();
                            return token;

                        case ':':
                            token = new TokenInfo(Token.Colon, TokenStringConstants.Colon, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '(':
                            token = new TokenInfo(Token.LeftParenthesis, TokenStringConstants.LeftParenthesis,
                                                  sourceFile, ln, col);
                            readChar();
                            return token;

                        case ')':
                            token = new TokenInfo(Token.RightParenthesis, TokenStringConstants.RightParenthesis,
                                                  sourceFile, ln, col);
                            readChar();
                            return token;

                        case '{':
                            token = new TokenInfo(Token.LeftBrace, TokenStringConstants.LeftBrace, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '}':
                            token = new TokenInfo(Token.RightBrace, TokenStringConstants.RightBrace, sourceFile, ln, col);
                            readChar();
                            return token;

                        case '[':
                            token = new TokenInfo(Token.LeftSquareBracket, TokenStringConstants.LeftSquareBracket,
                                                  sourceFile, ln, col);
                            readChar();
                            return token;

                        case ']':
                            token = new TokenInfo(Token.RightSquareBracket, TokenStringConstants.RightSquareBracket,
                                                  sourceFile, ln, col);
                            readChar();
                            return token;

                        case '<':
                            token = new TokenInfo(Token.LeftAngleBracket, TokenStringConstants.LeftAngleBracket,
                                                  sourceFile, ln, col);
                            readChar();
                            return token;

                        case '>':
                            token = new TokenInfo(Token.RightAngleBracket, TokenStringConstants.RightAngleBracket,
                                                  sourceFile, ln, col);
                            readChar();
                            return token;

                        case ' ':
                            readChar();
                            if (!IgnoreSpaces)
                            {
                                token = space(sourceFile, ln, col);
                                return token;
                            }
                            continue;

                        case '\t':
                            readChar2();
                            continue;

                        case '\r':
                            readChar2();
                            continue;

                        case '\n':
                            readChar();
                            if (!IgnoreEOLs)
                            {
                                token = eol(sourceFile, ln, col);
                                return token;
                            }
                            continue;
                    }

                    //An unspecified token
                    readChar();
                    return new TokenInfo(Token.UNSPECIFIED, ch.ToString(), sourceFile, ln, col);
                }
            }

            return eof(sourceFile, ln, col);
        }