示例#1
0
        IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
        {
            switch (Read)
            {
            case 'a':
                Current.Append('\a');
                return(States.StringLiteral);

            case 'n':
                Current.AppendNewLine();
                return(States.StringLiteral);

            case '"':
                Current.End(Symbol.StringLiteral);
                return(States.Base);

            case '\\':
                Current.Append('\\');
                return(States.StringLiteral);

            default:
                Current.Append('\\');
                return(States.StringLiteral.Read(Current, Read, States));
            }
        }
示例#2
0
文件: B.cs 项目: tmakij/MiniPascal
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (Read == 'o')
     {
         Current.Append(Read);
         return(States.Boolean);
     }
     if (Read == 'e')
     {
         Current.Append(Read);
         return(States.Begin);
     }
     return(States.Identifier.Read(Current, Read, States));
 }
示例#3
0
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (Read == 'l')
     {
         Current.Append(Read);
         return(States.Else);
     }
     if (Read == 'n')
     {
         Current.Append(Read);
         return(States.End);
     }
     return(States.Identifier.Read(Current, Read, States));
 }
示例#4
0
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (Read == 'c')
     {
         Current.Append(Read);
         return(States.PROcedure);
     }
     if (Read == 'g')
     {
         Current.Append(Read);
         return(States.PROgram);
     }
     return(States.Identifier.Read(Current, Read, States));
 }
示例#5
0
文件: W.cs 项目: tmakij/MiniPascal
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (Read == 'h')
     {
         Current.Append(Read);
         return(States.While);
     }
     if (Read == 'r')
     {
         Current.Append(Read);
         return(States.Write);
     }
     return(States.Identifier.Read(Current, Read, States));
 }
示例#6
0
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (char.IsNumber(Read))
     {
         Current.Append(Read);
         return(this);
     }
     if (Read == '.')
     {
         Current.Append(Read);
         return(States.RealLiteral);
     }
     Current.End(Symbol.IntegerLiteral);
     return(States.Base.Read(Current, Read, States));
 }
示例#7
0
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (Read == '\\')
     {
         return(States.EscapeCharacter);
     }
     Current.Append(Read);
     return(this);
 }
示例#8
0
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (moves.ContainsKey(Read))
     {
         Current.Append(Read);
         return(moves[Read]);
     }
     return(States.Identifier.Read(Current, Read, States));
 }
示例#9
0
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (Read == '+' || Read == '-' || char.IsNumber(Read))
     {
         Current.Append(Read);
         return(States.Exponent);
     }
     throw new LexerException("Expected digits or sign, found " + Read, Current.Line);
 }
示例#10
0
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (Read == nextChar)
     {
         Current.Append(Read);
         return(nextState);
     }
     return(States.Identifier.Read(Current, Read, States));
 }
示例#11
0
 IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
 {
     if (char.IsLetterOrDigit(Read) || Read == '_')
     {
         Current.Append(Read);
         return(this);
     }
     Current.End(Symbol.Identifier);
     return(States.Base.Read(Current, Read, States));
 }
示例#12
0
文件: Base.cs 项目: tmakij/MiniPascal
        IScannerState IScannerState.Read(TokenConstruction Current, char Read, StateStorage States)
        {
            if (char.IsWhiteSpace(Read))
            {
                return(this);
            }
            if (char.IsLetter(Read))
            {
                Current.Append(Read);
                switch (Read)
                {
                case 'a':
                    /*assert, and, array*/
                    return(States.A);

                case 'b':
                    /*begin, boolean */
                    return(States.B);

                case 'd':
                    return(States.Do);

                case 'e':
                    /* else, end */
                    return(States.E);

                case 'f':
                    /* false, function*/
                    return(States.F);

                case 'i':
                    /*integer, if*/
                    return(States.I);

                case 'n':
                    return(States.Not);

                case 'o':
                    return(States.O);

                case 'p':
                    /* procedure, program */
                    return(States.P);

                case 'r':
                    /* real, read*/
                    return(States.R);

                case 's':
                    /* size, string*/
                    return(States.S);

                case 't':
                    /* then, true */
                    return(States.T);

                case 'v':
                    return(States.Variable);

                case 'w':
                    /* while, writeln*/
                    return(States.W);

                default:
                    return(States.Identifier);
                }
            }
            if (char.IsNumber(Read))
            {
                Current.Append(Read);
                return(States.IntegerLiteral);
            }
            switch (Read)
            {
            case '{':
                return(States.CommentOpen);

            case '/':
                return(States.ForwardSlash);

            case ':':
                return(States.Colon);

            case '\\':
                return(States.StringLiteralStart);

            case '<':
                return(States.Less);

            case '>':
                return(States.Greater);

            case '%':
                Current.End(Symbol.Modulo);
                return(this);

            case ',':
                Current.End(Symbol.Comma);
                return(this);

            case '.':
                Current.End(Symbol.Period);
                return(this);

            case '&':
                Current.End(Symbol.LogicalAnd);
                return(this);

            case '!':
                Current.End(Symbol.LogicalNot);
                return(this);

            case '=':
                Current.End(Symbol.Equality);
                return(this);

            case '+':
                Current.End(Symbol.Addition);
                return(this);

            case '*':
                Current.End(Symbol.Multiplication);
                return(this);

            case ';':
                Current.End(Symbol.SemiColon);
                return(this);

            case '(':
                Current.End(Symbol.ClosureOpen);
                return(this);

            case ')':
                Current.End(Symbol.ClosureClose);
                return(this);

            case '-':
                Current.End(Symbol.Substraction);
                return(this);

            case '[':
                Current.End(Symbol.IndexOpen);
                return(this);

            case ']':
                Current.End(Symbol.IndexClose);
                return(this);
            }
            throw new LexerException("Invalid character " + Read, Current.Line);
        }