示例#1
0
        public AstLiteral Time(string value)
        {
            DateTime tret;

            if (DateTime.TryParse(value, out tret))
            {
                return(LitValue(TimeValue.Create(tret)));
            }
            Parser.ParseError("invalid date or time: {0}", value);
            return(null);
        }
示例#2
0
        // Get symbol from token, add to symbol table as needed
        // Look for existing symbol in catalog and nested scopes
        // If not found, define according to lexer type
        internal Symbol GetSymbol(Token token)
        {
            // First look for existing symbol
            Symbol sym;

            if (token.IsDefinable)
            {
                sym = Find(token.Value);
                if (sym != null)
                {
                    while (sym.Atom == Atoms.ALIAS)
                    {
                        sym = sym.Link;
                    }
                    return(sym);
                }
            }
            // source code line token masquerades as another eol
            if (token.TokenType == TokenTypes.LINE)
            {
                return(Find(Token.EolName));
            }
            // Create new symbol from token
            if (token.TokenType == TokenTypes.Number || token.TokenType == TokenTypes.HexNumber)
            {
                sym = MakeLiteral(NumberValue.Create(token.GetNumber() ?? Decimal.Zero));
            }
            else if (token.TokenType == TokenTypes.Time)
            {
                sym = MakeLiteral(TimeValue.Create(token.GetTime() ?? DateTime.MinValue));
            }
            else if (token.TokenType == TokenTypes.Identifier || token.TokenType == TokenTypes.IdLit)
            {
                sym = MakeIdent();
            }
            else if (token.TokenType == TokenTypes.Binary)
            {
                sym = MakeLiteral(BinaryValue.Create(token.GetBinary()));
            }
            else
            {
                sym = MakeLiteral(TextValue.Create(token.Value));
            }
            // note: only names for those we might define
            sym.Name = token.Value;
            return(sym);
        }