Пример #1
0
Файл: Level.cs Проект: nope/ioke
 internal Level(int precedence, IokeObject op, Level parent, Type type)
 {
     this.precedence = precedence;
     this.operatorMessage = op;
     this.parent = parent;
     this.type = type;
 }
Пример #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;
            }
        }
Пример #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;
            }
        }
Пример #4
0
 private void AttachAndReplace(Level self, IokeObject msg)
 {
     self.Attach(msg);
     self.type = Level.Type.Attach;
     self.message = msg;
 }
Пример #5
0
        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]);
        }
Пример #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;
        }
Пример #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;
 }