Exemplo n.º 1
0
        /**
         * If this is called, it's rather the end of a statement or it is a part of a OpNode
         */
        private INode TokenInt()
        {
            var value = Convert.ToInt32(_currentStatement[0].Value);
            var next  = ParseStatement(new IntNode(value));

            return(next switch
            {
                IntOpNode _ => next,
                null => new IntNode(value),
                _ => throw new SyntaxErrorException("Unexpected value after integer")
            });
Exemplo n.º 2
0
 /**
  * Recursive method which executes a node but the node method might execute its own nodes first
  */
 private INode Execute(INode node)
 {
     try
     {
         return(node switch
         {
             DeclareIntVarNode declarerNode => declarerNode.Execute(declarerNode.Left as ReferenceNode,
                                                                    Execute(declarerNode.Right) as IntNode),
             IntOpNode opNode => opNode.Execute(Execute(opNode.Left) as IntNode,
                                                Execute(opNode.Right) as IntNode),
             ReferenceNode identity => new IntNode(identity.Value),
             FuncCallNode call => ExecuteFunctionCall(call),
             IntNode intNode => intNode,
             MethodNode method => ExecuteDeclareMethod(method),
             LoopNode loop => ExecuteLoopNode(loop),
             ConditionalNode conditional => ExecuteConditional(conditional),
             _ => new IntNode(-1)
         });
     }