Beispiel #1
0
 private ParserErrorException Error(Token token, string message)
 {
     Lox.Error(token, message);
     return(new ParserErrorException());
 }
Beispiel #2
0
 private ParseError Error(Token token, string message)
 {
     Lox.Error(token, message);
     return(new ParseError());
 }
Beispiel #3
0
        private void ScanToken()
        {
            char c = Advance();

            switch (c)
            {
            case '(': AddToken(LEFT_PAREN); break;

            case ')': AddToken(RIGHT_PAREN); break;

            case '{': AddToken(LEFT_BRACE); break;

            case '}': AddToken(RIGHT_BRACE); break;

            case ',': AddToken(COMMA); break;

            case '.': AddToken(DOT); break;

            case '-': AddToken(MINUS); break;

            case '+': AddToken(PLUS); break;

            case ';': AddToken(SEMICOLON); break;

            case '*': AddToken(STAR); break;

            case '!': AddToken(Match('=') ? BANG_EQUAL : BANG); break;

            case '=': AddToken(Match('=') ? EQUAL_EQUAL : EQUAL); break;

            case '<': AddToken(Match('=') ? LESS_EQUAL : LESS); break;

            case '>': AddToken(Match('=') ? GREATER_EQUAL : GREATER); break;

            case '/':
                if (Match('/'))     //We are inside of a comment discard the whole line
                {
                    while (Peek() != '\n' && !IsAtEnd())
                    {
                        Advance();
                    }
                }
                else
                {
                    AddToken(SLASH);
                }
                break;

            case '"': ScanString(); break;

            case '\n':
                _line++;
                break;

            case ' ':
            case '\r':
            case '\t':
                // Ignore Whitespaces
                break;

            default:
                if (IsDigit(c))
                {
                    ScanNumber();
                }
                else if (IsAlpha(c))
                {
                    ScanIdentifier();
                }
                else
                {
                    Lox.Error(_line, "Unexpected character.");
                }

                break;
            }
        }