예제 #1
0
        public Value[] parseParameters(Qontext context)
        {
            List <Value> parameters = new List <Value>();
            Token        t          = peek();

            if (t.check(Struqture.Call[OPEN]))
            {
                do
                {
                    var seg = Segmentizer.parseOne(context, readBody(false, ",)"));
                    parameters.Add(seg.execute(context));
                    shift(-1);
                    if (peek().check(Struqture.Call[CLOSE]))
                    {
                        break;
                    }
                    if (peek().check(Struqture.Call[DEL]))
                    {
                        continue;
                    }
                    else
                    {
                        throw new ParseException("unexpected token found when trying to parse funqtion call", t);
                    }
                } while (!endOfStack());
                return(parameters.ToArray());
            }
            else
            {
                throw new ParseException("unexpected funqtion call parameter opening, expected '('", t);
            }
        }
예제 #2
0
        public Value readNextValue(Qontext context, ValueType expected = ValueType.Any)
        {
            Log.spam("Interpretoken.readNextValue()");
            Token t      = peek();
            Value result = null;

            if ((t.check(ValueType.Identifier)) ||
                (t.check(ValueType.Keyword) &&
                 (t.check(Keyword.CURRENT_CONTEXT.name) ||
                  t.check(Keyword.PARENT_CONTEXT.name))))
            {
                Log.spam("detected possible reference / identifier");
                Reference[] _r = rrra(context);
                Reference   r  = _r[_r.Length - 1];
                if (peek().check(Struqture.Call[OPEN]))
                {
                    Log.spam("hey, it's a funqtion call!");
                    if (r.getValueType() == ValueType.Funqtion || r.getValueType() == ValueType.NativeCall)
                    {
                        Value[] p = Funqtionizer.parseParameters(context, readBody(true));
                        result = (r.getTrueValue() as Funqtion).execute(p, (_r.Length > 1 ? _r[_r.Length - 2] : null));
                    }
                    else
                    {
                        throw new ParseException("can not call " + peek(-1) + ": not a funqtion.");
                    }
                }
                else
                {
                    result = r;
                }
            }
            else if (t.check(ValueType.Struqture))
            {
                Log.spam("detected possible structure");
                if (t.check(Struqture.Funqtion[OPEN]))
                {
                    Log.spam("...it's a funqtion");
                    Funqtion f = Funqtionizer.parse(context, readBody(true));
                    if (peek().check(Struqture.Call[OPEN]))
                    {
                        Value[] p = Funqtionizer.parseParameters(context, readBody(true));
                        result = f.execute(p);
                    }
                    else
                    {
                        result = f;
                    }
                }
                else if (t.check(Struqture.Context[OPEN]))
                {
                    Obqect o = Colleqtionizer.readObqect(context, readBody(true));
                    result = o;
                }
                else if (t.check(Struqture.Collection[OPEN]))
                {
                    Array a = Colleqtionizer.readArray(context, readBody(true));
                    result = a;
                }
                else if (t.check(Struqture.Call[OPEN]))
                {
                    Segment s = Segmentizer.parseOne(context, readBody());
                    result = s.execute(context);
                }
            }
            else if (t.check(ValueType.Primitive))
            {
                result = digest().makeValue();
            }
            else if (t.check(ValueType.Operator))
            {
                throw new ParseException("next token was unreadable as value: " + t, t);
            }

            return(result);
        }