Exemplo n.º 1
0
        public virtual bool canLiteralBeAssigned <T>(KeywordNode keyword, T t) where T : NodeImpl
        {
            if (keyword.Instructions[0] is FinalNode)
            {
                FinalNode finalNode = (FinalNode)keyword.Instructions[0];
                string    dataType  = finalNode.dataString();

                string rvalueDataString = ((FinalNode)t.Instructions.get(0)).dataString();

                switch (finalNode.IntegralType)
                {
                case jinteger:
                {
                    try
                    {
                        Convert.ToInt32(rvalueDataString);
                    }
                    catch (NumberFormatException)
                    {
                        throw new Exception("invalid r-Value");
                    }

                    return(true);
                }
                }
            }

            return(false);
        }
Exemplo n.º 2
0
        private int aggregateVariable(IList <VariableNode> variableNodeList, ActivationFrame frame)
        {
            int sum = 0;

            for (int i = 0; i < variableNodeList.Count; i++)
            {
                Node      v         = frame.variableSet[variableNodeList[i].variableName];
                FinalNode finalNode = null;

                if (v is FinalNode && v.Instructions.Count == 0)
                {
                    finalNode = (FinalNode)v;
                }

                if (v is PrimitiveNode)
                {
                    PrimitiveNode primitiveNode = (PrimitiveNode)v;
                    finalNode = (FinalNode)primitiveNode.Instructions[0];
                }

                if (finalNode != null)
                {
                    sum += Convert.ToInt32(finalNode.dataString());
                }
            }

            return(sum);
        }
Exemplo n.º 3
0
 public static string sysExec(Node argumentNode)
 {
     if (argumentNode is FinalNode)
     {
         FinalNode finalNode = (FinalNode)argumentNode;
         return(com.juliar.pal.Primitives.sysExec(finalNode.dataString()));
     }
     return("");
 }
Exemplo n.º 4
0
        private static string fileOpen(Node argumentNode)
        {
            if (argumentNode is FinalNode)
            {
                FinalNode finalNode = (FinalNode)argumentNode;
                return(sysFileOpen(finalNode.dataString()));
            }

            return("");
        }
Exemplo n.º 5
0
        public static bool canPrimitiveValueBeAssignedToVar(VariableDeclarationNode lvalue, PrimitiveNode rvalue)
        {
            FinalNode rvalueTerminal = (FinalNode)rvalue.Instructions[0];

            VariableNode variableNode;

            if (juserDefined == lvalue.IntegralType)
            {
                variableNode = lvalue.UserDefinedNode.VariableNode;
            }
            else
            {
                variableNode = (VariableNode)lvalue.Instructions[1];
            }
            string data = rvalueTerminal.dataString();

            try
            {
                switch (variableNode.IntegralType)
                {
                case jinteger:
                    return(true);

                case jdouble:
                    return(true);

                case jfloat:
                    return(true);

                case jlong:
                    return(true);

                case jstring:
                    return(true);

                case jobject:
                    return(false);

                case jboolean:
                    return(Convert.ToBoolean(data));

                case juserDefined:
                    return(true);

                default:
                    return(false);
                }
            }
            catch (NumberFormatException)
            {
                return(false);
            }
        }
Exemplo n.º 6
0
        private static void getByteFromString(ActivationFrame activationFrame, Node argumentNode, Node index)
        {
            string variableName = ((VariableNode)argumentNode).variableName;
            object variable     = activationFrame.variableSet[variableName];

            if (variable is FinalNode)
            {
                char[] array = sysGetByteFromString(((FinalNode)variable).dataString());

                FinalNode finalNode = new FinalNode();

                string argTwoVariableName = ((VariableNode)index).variableName;
                object argTwo             = activationFrame.variableSet[argTwoVariableName];

                FinalNode argumentTwo = null;

                if (argTwo is PrimitiveNode)
                {
                    argumentTwo = (FinalNode)activationFrame.variableSet[argTwoVariableName].Instructions[0];
                }
                else if (argTwo is FinalNode)
                {
                    argumentTwo = (FinalNode)activationFrame.variableSet[argTwoVariableName];
                }

                assert(argumentTwo != null ? argumentTwo.dataString() : null) != null;
                int parsedIndex = Convert.ToInt32(argumentTwo.dataString());

                if (parsedIndex > array.Length)
                {
                    throw new Exception("\r\nJuliar runtime exception - Index out of bounds accessing variable - '" + variableName + "'");
                }
                if (parsedIndex < array.Length)
                {
                    finalNode.DataString = array[parsedIndex];
                    activationFrame.pushReturnNode(finalNode);
                    //activationFrame.returnNode = finalNode;
                }
            }
        }
Exemplo n.º 7
0
        private IList <Node> evalIfStatement(Node node, ActivationFrame frame, Interpreter callback)
        {
            IList <Node> instructionList = node.Instructions;
            int          size            = instructionList.Count;


            IList <Node> trueExpressions = new List <Node>();
            BooleanNode  booleanNode     = getBooleanExpressionNode(instructionList, size, trueExpressions);

            if (booleanNode != null && booleanNode.Instructions.Count == 1)
            {
                FinalNode finalNode = (FinalNode)booleanNode.Instructions[0];
                if (finalNode.IntegralType == IntegralType.jboolean)
                {
                    bool? @bool = Convert.ToBoolean(finalNode.dataString());
                    if (@bool)
                    {
                        return(trueExpressions);
                    }
                }
            }
            else if (booleanNode != null && booleanNode.Instructions.Count > 0)
            {
                Node currentValue = frame.popNode();
                frame.pushReturnNode(null);
                bool?booleanResult = false;
                evalBooleanNode(booleanNode, frame, callback);

                if (frame.peekReturnNode() != null && frame.peekReturnNode() is BooleanNode)
                {
                    Node      booleanEvalReturnNode = frame.popNode();
                    FinalNode result = getFinalNodeFromAnyNode(booleanEvalReturnNode);
                    booleanResult = Convert.ToBoolean(result.dataString());
                }

                // TODO - FINISH THIS
                if (booleanResult && frame.peekReturnNode() != null)
                {
                    Node returnNode = frame.popNode();
                    if (returnNode is BreakExprNode)
                    {
                        IList <Node> returnList = new List <Node>();
                        returnList.Add(returnNode);
                        return(new List <>());
                    }
                }

                frame.pushReturnNode(currentValue);
            }

            return(new List <>());
        }
Exemplo n.º 8
0
        public static void commandInstance(CommandNode commandNode, ActivationFrame activationFrame, VariableDeclarationNode variableToAssignTo)
        {
            IList <Node> slotList = new List <Node>();

            slotList.Add(commandNode);
            interpreterCallback.execute(slotList);

            FinalNode variableNameTerminalNode = (FinalNode)variableToAssignTo.Instructions[1].Instructions[0];

            string variableName = variableNameTerminalNode.dataString();

            if (activationFrame.variableSet.ContainsKey(variableName))
            {
                activationFrame.variableSet.Remove(variableName);
            }

            activationFrame.variableSet[variableName] = activationFrame.peekReturnNode();
            //activationFrame.returnNode = null;
        }
Exemplo n.º 9
0
        private int getOperatorPrecedenceValue(FinalNode node)
        {
            int    precedence = -1;
            string dataString = node.dataString();

            switch (dataString)
            {
            case "*":
            case "/":
            case "%":
                precedence = 7;
                break;

            case "+":
            case "-":
                precedence = 0;
                break;

            case "(":
                precedence = 9;
                break;

            case ")":
                precedence = 10;
                break;

            case "==":
                precedence = 13;
                break;

            case "&&":
                precedence = 14;
                break;

            case "||":
                precedence = 15;
                break;
            }

            return(precedence);
        }
Exemplo n.º 10
0
        public static void primitiveInstance(PrimitiveNode primitiveNode, ActivationFrame activationFrame, VariableDeclarationNode variableToAssignTo)
        {
            if (canPrimitiveValueBeAssignedToVar(variableToAssignTo, primitiveNode))
            {
                string variableName;

                if (variableToAssignTo.IntegralType == juserDefined)
                {
                    variableName = variableToAssignTo.UserDefinedNode.FullyQualifiedVariableName;
                }
                else
                {
                    FinalNode variableNameTerminalNode = (FinalNode)variableToAssignTo.Instructions[1].Instructions[0];
                    variableName = variableNameTerminalNode.dataString();
                }

                if (activationFrame.variableSet.ContainsKey(variableName))
                {
                    activationFrame.variableSet.Remove(variableName);
                }

                activationFrame.variableSet[variableName] = primitiveNode;
            }
        }