Пример #1
0
        public AstLiteral Binary(string value)
        {
            var b = new byte[value.Length / 2];

            for (var i = 0; i < b.Length; ++i)
            {
                int n;
                if (!Int32.TryParse(value.Substring(i * 2, 2), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out n))
                {
                    return(null);
                }
                b[i] = (byte)n;
            }
            return(LitValue(BinaryValue.Create(b)));
        }
Пример #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);
        }