Пример #1
0
        private bool _return()
        {
            TokenTry();
            bool is_value = _value();

            if (!Accept(NakoTokenType.RETURN))
            {
                TokenBack();
                return(false);
            }
            TokenFinally();
            if (is_value)
            {
                NakoNodeLet      node = new NakoNodeLet();
                NakoNodeVariable sore = new NakoNodeVariable();
                sore.varNo   = (int)0;
                sore.scope   = NakoVariableScope.Global;
                node.VarNode = sore;
                NakoNodeLetValue valuenode = new NakoNodeLetValue();
                while (calcStack.Count > 0)
                {
                    valuenode.AddChild(calcStack.Shift());
                }
                node.ValueNode = (NakoNode)valuenode;
                parentNode.AddChild(node);
            }
            parentNode.AddChild(new NakoNodeReturn());
            tok.MoveNext();
            return(true);
        }
Пример #2
0
        //> _let : _setVariable EQ _value
        private bool _let()
        {
            TokenTry();
            if (!_setVariable())
            {
                TokenBack();
                return(false);
            }
            if (!Accept(NakoTokenType.EQ))
            {
                TokenBack();
                return(false);
            }

            NakoNodeLet node = new NakoNodeLet();

            node.VarNode = (NakoNodeVariable)lastNode; // _setVariable のノード
            tok.MoveNext();
            if (!_value())
            {
                throw new NakoParserException("代入文で値がありません。", tok.CurrentToken);
            }
            TokenFinally();

            NakoNodeLetValue valuenode = new NakoNodeLetValue();

            while (calcStack.Count > 0)
            {
                valuenode.AddChild(calcStack.Shift());
            }
            node.ValueNode = (NakoNode)valuenode;
            parentNode.AddChild(node);
            lastNode = node;

            return(true);
        }