Exemplo n.º 1
0
 public abstract void Visit(VariableExpression expression);
Exemplo n.º 2
0
 public override void Visit(VariableExpression expression)
 {
     this.writer.Write(ToVariableName(expression.Name));
 }
Exemplo n.º 3
0
 public override void Visit(VariableExpression expression)
 {
     this.block.CompileGet(expression.Name);
 }
Exemplo n.º 4
0
        private IExpression ParseHeadExpression()
        {
            Token token = this.NextToken();

            if (token == null)
                return null;

            switch (token.Type)
            {
                case TokenType.Name:
                    if (token.Value == "self")
                        return new SelfExpression();
                    if (token.Value == "true")
                        return new ConstantExpression(true);
                    if (token.Value == "false")
                        return new ConstantExpression(false);
                    if (token.Value == "nil" || token.Value == "null")
                        return new ConstantExpression(null);

                    if (this.@class != null && this.isClassMethod == false && [email protected](token.Value))
                        return new InstanceVariableExpression(token.Value);

                    if (this.@class != null && this.isClassMethod == true && [email protected](token.Value))
                        return new ClassVariableExpression(token.Value, this.@class);

                    return new VariableExpression(token.Value);

                case TokenType.DottedName:
                    string[] names = token.Value.Split('.');
                    IExpression expr = new VariableExpression(names[0]);

                    foreach (var name in names.Skip(1))
                        expr = new MessageExpression(expr, "at:", new IExpression[] { new ConstantExpression(name) });

                    return expr;

                case TokenType.String:
                    return new ConstantExpression(token.Value);

                case TokenType.Character:
                    return new ConstantExpression(token.Value[0]);

                case TokenType.Symbol:
                    return new SymbolExpression(token.Value);

                case TokenType.Operator:
                    if (token.Value == "<")
                        return this.ParsePrimitive();
                    if (token.Value == "-")
                        return new MessageExpression(this.ParseHeadExpression(), "-", null);
                    break;

                case TokenType.Punctuation:
                    if (token.Value == "[")
                    {
                        var result = this.ParseInternalBlock();
                        this.ParseToken(TokenType.Punctuation, "]");
                        return result;
                    }

                    if (token.Value == "#(")
                        return this.ParseArray();

                    if (token.Value == "#[")
                        return this.ParseByteArray();

                    if (token.Value == "{")
                        return this.ParseDynamicArray();

                    if (token.Value == "(")
                    {
                        IExpression expression = this.ParseExpression();
                        Token lasttoken = this.NextToken();

                        if (lasttoken == null || lasttoken.Type != TokenType.Punctuation || lasttoken.Value != ")")
                        {
                            this.PushToken(lasttoken);
                            return this.ParseExpression(expression);
                        }

                        return expression;
                    }

                    break;

                case TokenType.Integer:
                    long value = 0;
                    int position = token.Value.IndexOf('r');

                    if (position > 0)
                    {
                        string strradix = token.Value.Substring(0, position);
                        string strnumber = token.Value.Substring(position + 1);
                        value = Convert.ToInt64(strnumber, Convert.ToInt32(strradix));
                    }
                    else
                        value = Convert.ToInt64(token.Value);

                    if (value > int.MaxValue || value < int.MinValue)
                        return new ConstantExpression(value);
                    else
                        return new ConstantExpression((int)value);

                case TokenType.Real:
                    return new ConstantExpression(Convert.ToDouble(token.Value, CultureInfo.InvariantCulture));
            }

            this.PushToken(token);

            return null;
        }