Esempio n. 1
0
        private IToken ScanNumber(int start)
        {
            bool ParsingFraction = false;

            while (Advancable())
            {
                if (CurrentCharacter.IsNumeric())
                {
                    continue;
                }
                else if (CurrentCharacter.IsWhiteSpace())
                {
                    return(Add(EToken.Number, start, this));
                }
                else if (CurrentCharacter != '.')
                {
                    return(Add(EToken.Number, start, Formula.Substring(start - 1, CharPosition-- - start)));
                }
                else if (ParsingFraction)
                {
                    return(Add(EToken.ScanError, start, this));
                }
                else
                {
                    ParsingFraction = true;
                }
            }
            return(Add(EToken.Number, start, this));
        }
Esempio n. 2
0
        public IToken Scan()
        {
            if (CharPosition == 1 && CurrentCharacter == '\'')
            {
                return(Add(EToken.StringLiteral, 1, Formula));
            }
            while (Advancable())
            {
                if (!CurrentCharacter.IsWhiteSpace())
                {
                    var start = CharPosition;
                    switch (CurrentCharacter)
                    {
                    case '!': return(Add(EToken.Bang, start, GetText(start)));

                    case '=': return(Add(EToken.EqualsOperator, start, GetText(start)));

                    case ',': return(Add(EToken.Comma, start, GetText(start)));

                    case ';': return(Add(EToken.Semicolon, start, GetText(start)));

                    case '+':
                    case '-':
                    case '%': return(Add(EToken.UnaryOperator, start, GetText(start)));

                    case '*':
                    case '/':
                    case '&':
                    case '^': return(Add(EToken.BinaryOperator, start, GetText(start)));

                    case '<':
                    case '>': if (IsEOT)
                        {
                            break;
                        }
                        if (NextCharacterIs('='))
                        {
                            CharPosition++;
                        }
                        return(Add(EToken.BinaryOperator, start, GetText(start)));

                    case '(': ParenDepth++; return(Add(EToken.OpenParen, start, GetText(start)));

                    case ')': ParenDepth--; return(Add(EToken.CloseParen, start, GetText(start)));

                    case '{': BraceDepth++; return(Add(EToken.OpenBrace, start, GetText(start)));

                    case '}': BraceDepth--; return(Add(EToken.CloseBrace, start, GetText(start)));

                    case '#': return(ScanErrorIdent(start));

                    case '"': return(ScanStringLiteral(start));

                    case '\'': return(ScanClosedExternalRef(start));

                    case '[': return(ScanOpenExternalRef(start));

                    default:
                        if (CurrentCharacter.IsNumeric())
                        {
                            return(ScanNumber(start));
                        }
                        if (CurrentCharacter.IsAlpha())
                        {
                            return(ScanIdentifier(start));
                        }
                        return(Add(EToken.ScanError, start, this));
                    }
                }
            }
            return(IsEOT ? Add(EToken.EOT, CharPosition, this)
                         : Add(EToken.ScanError, CharPosition, this));
        }