Ejemplo n.º 1
0
Archivo: Level.cs Proyecto: nope/ioke
 internal Level(int precedence, IokeObject op, Level parent, Type type)
 {
     this.precedence = precedence;
     this.operatorMessage = op;
     this.parent = parent;
     this.type = type;
 }
Ejemplo n.º 2
0
        internal void Add(IokeObject msg)
        {
            if(head == null) {
                head = last = msg;
            } else {
                Message.SetNext(last, msg);
                Message.SetPrev(msg, last);
                last = msg;
            }

            if(currentLevel.type == Level.Type.UNARY) {
                currentLevel.operatorMessage.Arguments.Add(Pop());
                currentLevel = currentLevel.parent;
            }
        }
Ejemplo n.º 3
0
        internal void PopOperatorsTo(int precedence)
        {
            while((currentLevel.precedence != -1 || currentLevel.type == Level.Type.UNARY) && currentLevel.precedence <= precedence) {
                IokeObject arg = Pop();
                if(arg != null && Message.IsTerminator(arg) && Message.GetNext(arg) == null) {
                    arg = null;
                }

                IokeObject op = currentLevel.operatorMessage;
                if(currentLevel.type == Level.Type.INVERTED && Message.GetPrev(op) != null) {
                    Message.SetNext(Message.GetPrev(op), null);
                    op.Arguments.Add(head);
                    head = arg;
                    Message.SetNextOfLast(head, op);
                    last = op;
                } else {
                    if(arg != null) {
                        op.Arguments.Add(arg);
                    }
                }
                currentLevel = currentLevel.parent;
            }
        }
Ejemplo n.º 4
0
Archivo: Levels.cs Proyecto: fronx/ioke
 private void AttachAndReplace(Level self, IokeObject msg)
 {
     self.Attach(msg);
     self.type = Level.Type.Attach;
     self.message = msg;
 }
Ejemplo n.º 5
0
Archivo: Levels.cs Proyecto: fronx/ioke
        public void Reset()
        {
            currentLevel = 1;
            for(int i=0;i<OP_LEVEL_MAX;i++) {
                pool[i] = new Level(Level.Type.Unused);
            }
            Level level = pool[0];
            level.message = null;
            level.type = Level.Type.New;
            level.precedence = OP_LEVEL_MAX;

            stack.Clear();
            stack.Add(pool[0]);
        }
Ejemplo n.º 6
0
        internal IokeObject PrepareAssignmentMessage()
        {
            if(chains.last != null && chains.last == currentLevel.operatorMessage) {
                if(currentLevel.type == Level.Type.ASSIGNMENT && head == null) {
                    IokeObject assgn = currentLevel.operatorMessage;
                    IokeObject prev = (IokeObject)assgn.Arguments[0];
                    assgn.Arguments.Clear();
                    Pop();
                    currentLevel = currentLevel.parent;

                    IokeObject realPrev = Message.GetPrev(assgn);
                    if(realPrev != null) {
                        Message.SetNext(realPrev, prev);
                        if(prev != null) {
                            Message.SetPrev(prev, realPrev);
                        }
                        Message.SetPrev(assgn, null);
                    }
                    if(head == last) {
                        head = prev;
                    }
                    last = prev;
                    return assgn;
                } else if(last == null && currentLevel.type != Level.Type.ASSIGNMENT) {
                    Pop();
                    currentLevel = currentLevel.parent;
                }
            }

            if(last == null) {
                return null;
            }

            IokeObject l = last;
            if(head == l) {
                head = last = null;
            } else {
                last = Message.GetPrev(l);
                Message.SetNext(last, null);
            }

            Message.SetPrev(l, null);
            Message.SetNext(l, null);

            return l;
        }
Ejemplo n.º 7
0
 internal void Push(int precedence, IokeObject op, Level.Type type)
 {
     currentLevel = new Level(precedence, op, currentLevel, type);
     chains = new BufferedChain(chains, last, head);
     last = head = null;
 }