void Block(YSParseNode BlockNode)
 {
     Debug ("Entering a block");
     Current = BlockNode;
     foreach (YSParseNode StatementNode in BlockNode.Children) {
         if (StatementNode.Type == NType.Statement) {
             Statement (StatementNode);
         } else if (StatementNode.Type == NType.FunctionReturn) {
             if (STATE.current_scope.Type != ScopeFrame.FrameTypes.Function)
                 Error ("Only functions can have return statements");
             if (StatementNode.Children.Count == 1) {
                 IDPacket EXP = Expression (StatementNode.Children [0]);
                 IDPacket RETURN = IDPacket.CreateReturnPacket (EXP.Type);
                 STATE.COPY (RETURN, EXP);
             }
         } else {
             Error ("Unknown Node Type " + StatementNode.Type);
         }
     }
     Debug ("Exiting block");
 }
 public YSInterpreter(YSParseNode ParseTree)
 {
     Console.WriteLine ("Begining Interpreter");
     Node = ParseTree;
 }
Example #3
0
 void CreateTerminalChild(YSToken Token)
 {
     YSParseNode t = new YSParseNode (Token);
     current_node.Children.Add (t);
 }
 //identity expression
 void VarPrimitive(YSParseNode VarPrimitiveNode, IdentityType IType)
 {
     Current = VarPrimitiveNode;
     YSToken NameToken = VarPrimitiveNode.Children[0].Children[0].Token;
     ExpectNonExistance (NameToken.Content);
     IDPacket primitive = IDPacket.CreateIDPacket (STATE, NameToken.Content, IType);
     Debug ("Creating variable " + NameToken.Content + " of type " + IType);
     if (VarPrimitiveNode.Children.Count > 1) {
         IDPacket PEXP = Expression (VarPrimitiveNode.Children [1]);
         ExpectType (primitive.Type, PEXP.Type);
         STATE.COPY (primitive, PEXP);
         Debug ("Assignment complete");
     } else {
         switch (IType) {
         case IdentityType.Number:
             STATE.PutNumber (primitive, 0);
             break;
         case IdentityType.Boolean:
             STATE.PutBoolean (primitive, false);
             break;
         case IdentityType.Text:
             STATE.PutText (primitive, "");
             break;
         }
     }
     Debug ("Exit VarPrimitive");
 }
 void Statement(YSParseNode StatementNode)
 {
     //Statements have only one child
     Current = StatementNode;
     if (StatementNode.Children.Count < 1) {
         Error ("Empty Statement Error");
     }
     YSParseNode StatementChild = StatementNode.Children [0];
     switch (StatementChild.Type) {
     case NType.VarCreate:
         VarCreate (StatementChild);
         break;
     case NType.Structure:
         Structure (StatementChild);
         break;
     case NType.Function:
         Function (StatementChild);
         break;
     case NType.Set:
         Debug ("Set var statement");
         YSParseNode SetNode = StatementNode.Children [0];
         IDPacket ID = Identity (SetNode.Children [0]);
         IDPacket EXP = Expression (SetNode.Children [1]);
         STATE.COPY (ID, EXP);
         break;
     case NType.Call:
         Debug ("Call statement");
         YSParseNode CallNode = StatementNode.Children [0];
         IdentityFunction (CallNode);
         break;
     case NType.Condition:
         Condition (StatementNode.Children [0]);
         break;
     case NType.Loop:
         Loop (StatementNode.Children [0]);
         break;
     case NType.Output:
         Debug ("Output Statement");
         YSParseNode OutputNode = StatementNode.Children [0];
         IDPacket OID = Expression (OutputNode.Children [0]);
         STATE.OUTPUT (OID);
         break;
     default:
         Error ("Unknown Statement Type " + StatementChild.Type);
         break;
     }
     Debug ("Exit Statement");
 }
    IDPacket IdentityFunction(YSParseNode IFunctionNode)
    {
        Debug ("Attempting to execute function");
        Current = IFunctionNode;
        string FunctionName = IFunctionNode.Children [0].Token.Content;
        IDPacket FunctionPacket = IDPacket.CreateIDPacket (STATE, FunctionName, IdentityType.Function);

        //execute the function
        FunctionFrame FT;
        if (!STATE.TryGetFunction (FunctionPacket, out FT))
            Error ("Could not retreive function frame.");

        //Create bindings
        List<IDPacket> Bindings = new List<IDPacket> ();
        foreach (YSParseNode arg in IFunctionNode.Children[1].Children) {
            IDPacket argexp;
            if (arg.Type == NType.Expression) {
                argexp = Expression (arg);
            } else if (arg.Type == NType.ExpressionList) {
                List<int> dims = new List<int> ();
                IdentityType ResolvedType = IdentityType.Unknown;
                argexp = ExpressionList (arg, ref dims, ref ResolvedType);
                argexp.ArrayType = ResolvedType;
                dims.Reverse ();
                argexp.TypeDimensions = dims.ToArray ();
            } else {
                Error ("Expecting either an expression or an expression list");
                argexp = IDPacket.CreateSystemPacket ("TRASH", IdentityType.Unknown);
            }
            Bindings.Add (argexp);
        }

        ScopeFrame FunctionScope = STATE.CreateFunctionScope (FT, FunctionName, Bindings);
        FunctionScope.Name = FunctionName;
        FunctionScope.Type = ScopeFrame.FrameTypes.Function;
        STATE.PushScope (FunctionScope);

        YSParseNode FunctionBlockNode = FT.Block;
        Block (FunctionBlockNode);

        STATE.PopScopeNoSave ();
        Debug ("Finished execution");
        return IDPacket.CreateReturnPacket (FT.Returns);
    }
    void Loop(YSParseNode LoopNode)
    {
        Current = LoopNode;
        YSParseNode ConditionNode = LoopNode.Children [1];
        ScopeFrame LoopFrame = new ScopeFrame (STATE.current_scope, "Loop@" + LoopNode.Children [0].Token.Position, ScopeFrame.FrameTypes.Loop);
        STATE.PushScope (LoopFrame);

        IDPacket EVAL_COND = Expression (ConditionNode);
        ExpectType (IdentityType.Boolean, EVAL_COND.Type);
        bool EVAL_VAL;
        STATE.TryGetBoolean (EVAL_COND, out EVAL_VAL);
        while (EVAL_VAL) {
            Block (LoopNode.Children [2]);
            EVAL_COND = Expression (ConditionNode);
            STATE.TryGetBoolean (EVAL_COND, out EVAL_VAL);
        }

        STATE.PopScope ();
    }
    IDPacket ExpressionFactor(YSParseNode ExpressionFactorNode)
    {
        Debug ("ExpressionFactor Resolving...");
        Current = ExpressionFactorNode;
        switch (ExpressionFactorNode.Children [0].Type) {
        case NType.Identity:
        case NType.IdentityArray:
        case NType.IdentityFunction:
        case NType.IdentityStructure:
            IDPacket ID = Identity (ExpressionFactorNode.Children[0]);
            return ID;
        case NType.ExpressionFactor:
            IDPacket EFID = Expression (ExpressionFactorNode.Children [0]);
            ErrorIfUnknown ("Exit ExpressionFactor (ExpressionFactor)", EFID);
            return EFID;
        case NType.Text:
            IDPacket TEMP1 = IDPacket.CreateSystemPacket ("TEMP", IdentityType.Text);
            STATE.PutText (TEMP1, ExpressionFactorNode.Children [0].Children [0].Token.Content);
            ErrorIfUnknown ("Exit ExpressionFactor (Text)", TEMP1);
            return TEMP1;
        case NType.Number:
            IDPacket TEMP2 = IDPacket.CreateSystemPacket ("TEMP", IdentityType.Number);
            double d;
            if (!double.TryParse (ExpressionFactorNode.Children [0].Children [0].Token.Content, out d))
                Error ("Could not convert token to number");
            STATE.PutNumber (TEMP2, d);
            ErrorIfUnknown ("Exit ExpressionFactor (Number)", TEMP2);
            return TEMP2;

        default:
            Error ("Could not resolve Identity");
            return IDPacket.CreateSystemPacket("", IdentityType.Unknown);
        }
    }
    IDPacket ExpressionList(YSParseNode ExpressionListNode, ref List<int> DimensionsReversed, ref IdentityType ResolvedType)
    {
        DIMCNT = 0;
        Debug ("Expression List Resolving");
        //STATE.PutStructure (ARRAY, ArrayFrame);

        if (ExpressionListNode.Children.Count < 1) {
            Debug ("Expression List had no children");
            return null;
        }

        IDPacket ARRAY = IDPacket.CreateSystemPacket ("EXPL_TEMP", IdentityType.Structure);
        ScopeFrame ArrayScope = new ScopeFrame (new StructureFrame(), ARRAY.Name, ScopeFrame.FrameTypes.None);
        STATE.PushScope (ArrayScope);

        //List<IDPacket> RESULT = new List<IDPacket> ();
        //Look at the first node, all other nodes must conform to this node's type
        int NC = 0;
        YSParseNode FirstNode = ExpressionListNode.Children [NC++];
        //IdentityType ListType;
        int ListDimensions = 0;
        if (FirstNode.Type == NType.ExpressionList) {
            ListDimensions++;
            IDPacket IEXPL = ExpressionList (FirstNode, ref DimensionsReversed, ref ResolvedType);
            DimensionsReversed.AddRange (new List<int>(DimensionsReversed));
            //RESULT.Add (IEXPL);
            IDPacket FIRST = IDPacket.CreateIDPacket (STATE, "0", IdentityType.Structure);
            STATE.COPY (FIRST, IEXPL);
        } else {
            IDPacket EXP = Expression (FirstNode);
            ResolvedType = EXP.Type;
            if (!STATE.IsPrimitive (ResolvedType))
                Error ("Expression Lists can only contain identities that resolve to Primitive Types");
            //RESULT.Add (EXP);
            IDPacket FIRST = IDPacket.CreateIDPacket (STATE, "0", EXP.Type);
            STATE.COPY (FIRST, EXP);
        }
        int ELEMENT_COUNT = 1;
        while (NC < ExpressionListNode.Children.Count) {
            YSParseNode Node = ExpressionListNode.Children [NC++];
            if (Node.Type != FirstNode.Type)
                Error (String.Format("All children in an expression list must have the same dimensions " +
                    "Expecting {0} got {1}",
                    FirstNode.Type, Node.Type));
            if (FirstNode.Type == NType.ExpressionList) {
                IdentityType NodeType = IdentityType.Unknown;
                int NodeDimensions = 0;
                IDPacket NEXPL = ExpressionList (Node, ref DimensionsReversed, ref NodeType);
                if (NodeDimensions != ListDimensions) {
                    Error (String.Format ("All children of an expression list must have matching dimensions. " +
                    "Expected dimensions:{0} Found:{1}",
                        ListDimensions, NodeDimensions));
                }
                if (NodeType != ResolvedType) {
                    Error (String.Format ("All children of an expression list must have matching types. " +
                    "Expected type:{0} Found:{1}",
                        ResolvedType, NodeType));
                }
                //RESULT.Add (NEXPL);
                IDPacket NODE = IDPacket.CreateIDPacket (STATE, "" + ELEMENT_COUNT++, IdentityType.Structure);
                STATE.COPY (NODE, NEXPL);
            } else {
                IDPacket NEXP = Expression (Node);
                if (NEXP.Type != ResolvedType) {
                    Error (String.Format ("All children of an expression list must have matching types. " +
                    "Expected type:{0} Found:{1}",
                        ResolvedType, NEXP.Type));
                }
                //RESULT.Add (NEXP);
                IDPacket NODE = IDPacket.CreateIDPacket (STATE, "" + ELEMENT_COUNT++, NEXP.Type);
                STATE.COPY (NODE, NEXP);
            }
        }
        DIMCNT = ELEMENT_COUNT;
        DimensionsReversed.Add (DIMCNT);

        ArrayScope = STATE.PopScopeNoSave ();

        ArrayFrame ArrayFrame = new ArrayFrame (new IdentityType[] { ResolvedType });
        ArrayFrame.Merge ((GenericFrame)ArrayScope);
        ArrayFrame.ResolvedType = ResolvedType;
        DimensionsReversed.Reverse ();
        ArrayFrame.Dimensions = DimensionsReversed.ToArray();
        ARRAY.ArrayType = ResolvedType;
        STATE.PutGeneric (ARRAY, ArrayFrame);

        //ResolvedType = RESOLVED_TYPE;
        return ARRAY;
    }
Example #10
0
 //IDPacket id - IDPacket is the address to the location where the resolved
 //value of the Expression will be stored
 IDPacket Expression(YSParseNode ExpressionNode)
 {
     Debug ("Expression Resolving...");
     IDPacket output = ExpressionLogic (ExpressionNode.Children[0]);
     Debug ("Exit Expression, final type: " + output.Type);
     return output;
 }
Example #11
0
 IDPacket ExpressionBoolean(YSParseNode ExpressionBooleanNode)
 {
     Debug ("ExpressionBoolean Resolving...");
     Current = ExpressionBooleanNode;
     int CCNT = 0;
     IDPacket NUM1 = ExpressionNumber (ExpressionBooleanNode.Children [CCNT++]);
     while (CCNT < ExpressionBooleanNode.Children.Count) {
         YSToken CompOperator = ExpressionBooleanNode.Children [CCNT++].Token;
         IDPacket NUM2 = ExpressionNumber (ExpressionBooleanNode.Children [CCNT++]);
         NUM1 = STATE.COMP_OP (NUM1, NUM2, CompOperator);
     }
     Debug ("Exit ExpressionBoolean, final type: " + NUM1.Type);
     //TODO Operation
     return NUM1;
 }
Example #12
0
    bool DataType(YSParseNode DataTypeNode, out IdentityType Type, out List<int> Dimensions)
    {
        Debug ("Beginning a Data Type");

        if (DataTypeNode.Children.Count < 1) {
            Dimensions = null;
            Type = IdentityType.Unknown;
            return false;
        } else if (DataTypeNode.Children.Count > 1) {
            Dimensions = new List<int> ();
            Type = STATE.TranslateTokenTypeToIdentityType (DataTypeNode.Children [1].Token.Type);
            if (DataTypeNode.Children.Count > 2 && DataTypeNode.Children [2].Type == NType.ArrayDimensions) {
                YSParseNode ADNode = DataTypeNode.Children [2];
                foreach (YSParseNode Terminal in ADNode.Children) {
                    if (Terminal.Token.Type != YSToken.TokenType.NumberData &&
                        Terminal.Token.Type != YSToken.TokenType.Asterisk)
                        Error ("Expecting a number or *");
                    if (Terminal.Token.Type == YSToken.TokenType.Asterisk)
                        Dimensions.Add (-1);
                    else {
                        int dimval = int.Parse (Terminal.Token.Content);
                        if (dimval < 0)
                            Error ("Dimension values cannot be under 0");
                        Dimensions.Add (dimval);
                    }
                }
            }
            return true;
        } else {
            Dimensions = null;
            Type = STATE.TranslateTokenTypeToIdentityType(DataTypeNode.Children [0].Token.Type);
            return true;
        }
        Debug ("Exiting Data Type");
    }
Example #13
0
 void PushParseNode(ParseNodeType Type)
 {
     Debug ("Pushing " + Type + " Stack height " + parse_nodes.Count);
     YSParseNode n = new YSParseNode (Type, current);
     parse_nodes.Push (n);
 }
Example #14
0
    //TODO
    //1) Expression List Parsing
    /* programs		:= [ { header-line } ] { statement }
     *
     * header-line	:= import textdata;
     * 				| promise <planed feature>
     *
     * statement 	:= set identity "=" expression ;
     * 				| var-create ;
     *				| condition
     *				| loop
     *				| call identity
     *				| function
     *				| output expression
     *				| comment
     *
     *	var-create	:= primitive-type identity [ "=" expression ] { , identity [ "=" expression ] }
     *				| array of type identity "=" array "(" array-exp ")" ;
     *
     *	condition	:= "if" expression "then" block
     *
     *	loop		:= "while" expression "do" block
     *
     *	function	:= "function" ident "(" type ident { , type ident } ")" : type "{" { ( var-create| condition | loop | structure |
     *				| ( return expression ; ) ) } "}"
     *
     *	structure	:= "structure" identity [ "child" "of" identity ] "{" var-create ; { var-create ; } "}"
     *
     *	block 		:= "{" { statement } "}"
     *
     *
     *	-Expressions-
     *
     *	expression 	:= expr-list
     *				| expr-logic
     *
     *	expr-list 	:= "[" [ expression { , expression } ] "]"
     *
     *  expr-logic	:= [not] expr-bool { (and|or) [not] expr-bool }
     *
     *	expr-bool	:= expr-num { compopr expr-num }
     *
     *	expr-num	:= [addoppr] expr-term { addoppr expr-term }
     *
     *	expr-term 	:= expr-factor { ("*"|"/") expr-factor }
     *
     *	expr-factor := ident
     * 				| numberdata
     * 				| textdata
     * 				| "(" expression ")"
     *
     * 	ident		:= [ global .]identity | ident-arr | ident-str | ident-fun
     *
     * 	ident-arr	:= ident : structure { "[" expression "]" }
     *
     * 	ident-str	:= ident : structure { "." ident }
     *
     * 	ident-fun	:= ident : function "(" expression { , expression } ")"
     *
     *	-Operators-
     *
     *	addoppr 	:= "+" | "-"
     *	muloppr 	:= "*" | "/"
     *	compopr		:= "equals" | "<" | "<=" | ">" | ">="
     *
     *	primitive-type 		:= Number | Text | List | GameObject | Boolean #| "<" identity ">" allow users to create objects/their own datatypes
     */
    int Program()
    {
        YSParseNode n = new YSParseNode (ParseNodeType.Program, program_tokens[0]);
        parse_nodes.Push (n);

        //parse headers

        PushParseNode (ParseNodeType.Header);
        while (Header ())
            ;
        PopAndInsertParseNode ();

        //bool FATAL = false;

        Debug ("Beginning parsing of " + program_tokens.Count + " tokens");
        while (!EOF) {
            try {
                Statement ();
            } catch(ParseException) {
                Panic ();
                ERR_COUNT++;
            }
        }
        Debug ("End of parsing, Error Count: " + ERR_COUNT);
        return ERR_COUNT;
    }
Example #15
0
 IDPacket Identity(YSParseNode INode)
 {
     Debug ("Resolving basic identity");
     Current = INode;
     switch(INode.Type) {
     case NType.Identity:
         YSParseNode IdentityNode = INode;
         YSParseNode TerminalNode = IdentityNode.Children [0];
         IdentityType IdentityType = STATE.ResolveIdentityType (TerminalNode.Token);
         string IdentityName = TerminalNode.Token.Content;
         //get the IDPacket
         IDPacket ID = IDPacket.CreateIDPacket (STATE, IdentityName, IdentityType);
         ErrorIfUnknown ("Exit ExpressionFactor (Identity)", ID);
         return ID;
     case NType.IdentityArray:
         IDPacket AID = IdentityArray (INode);
         ErrorIfUnknown ("Exit ExpressionFactor (Array)", AID);
         return AID;
     case NType.IdentityFunction:
         IDPacket RID = IdentityFunction (INode);
         ErrorIfUnknown ("Exit ExpressionFactor (Function)", RID);
         return RID;
     case NType.IdentityStructure:
         //string StructureName = INode.Token.Content;
         //IDPacket SID = IDPacket.CreateIDPacket (STATE, StructureName, IdentityType.Structure);
         IDPacket SID = IdentityStructure (INode);
         ErrorIfUnknown ("Exit ExpressionFactor (Structure)", SID);
         return SID;
     default:
         Error ("Identity could not be resolved");
         return IDPacket.CreateSystemPacket ("", IdentityType.Unknown);
     }
 }
Example #16
0
 IDPacket ExpressionLogic(YSParseNode ExpressionLogicNode)
 {
     Debug ("ExpressionLogic Resolving...");
     Current = ExpressionLogicNode;
     int CCNT = 0;
     if (ExpressionLogicNode.Children [CCNT].Type == NType.Terminal) {
         CCNT++;
     }
     IDPacket LOG1 = ExpressionBoolean (ExpressionLogicNode.Children[CCNT]);
     if (CCNT == 1) {
         LOG1 = STATE.LOGICAL_NOT (LOG1);
     }
     CCNT++;
     while (CCNT < ExpressionLogicNode.Children.Count) {
         YSToken LogicalOperator = ExpressionLogicNode.Children [CCNT++].Token;
         IDPacket LOG2 = ExpressionBoolean (ExpressionLogicNode.Children[CCNT++]);
         LOG1 = STATE.LOGICAL_OP (LOG1, LOG2, LogicalOperator);
     }
     Debug ("Exit ExpressionLogic, final type: " + LOG1.Type);
     return LOG1;
 }
Example #17
0
    IDPacket IdentityArray(YSParseNode IdentityArrayNode)
    {
        string ArrayName = IdentityArrayNode.Children [0].Token.Content;
        IDPacket INDEX = Expression (IdentityArrayNode.Children [1]);
        if (INDEX.Type != IdentityType.Number) {
            Error ("An array/list index must be an integer");
        }
        IDPacket ArrayStructure = STATE.GET (ArrayName);
        if (ArrayStructure.Type != IdentityType.Structure) {
            Error (String.Format ("The identity {0} is expected to be an array, got type {1}",
                ArrayName, ArrayStructure.Type));
        } else if (ArrayStructure.Type == IdentityType.Structure && ArrayStructure.ArrayType == IdentityType.Unknown) {
            Error (String.Format ("The identity {0} is expected to be an array, got type Structure",
                ArrayName));
        }

        double dIndex;
        STATE.TryGetNumber (INDEX, out dIndex);
        int Index = (int)dIndex;

        if (!(Math.Abs (dIndex % 1) < Double.Epsilon)) {
            Debug (String.Format("Value of index ({0}) was not an integer, converted to ({1}).",
                dIndex, Index));
        }

        IDPacket ID = IDPacket.CreateIDPacket (STATE, Index + "", ArrayStructure.ArrayType);
        ID.Address += "s:" + ArrayStructure.Name;

        return ID;
    }
Example #18
0
    IDPacket ExpressionNumber(YSParseNode ExpressionNumberNode)
    {
        /*
        ExpressionTerm (ExpressionNumberNode.Children [0], ref id);
        int CCNT = 1;
        while (CCNT < ExpressionNumberNode.Children.Count) {
            YSToken NumOperator = ExpressionNumberNode.Children [CCNT++];
            ExpressionTerm (ExpressionNumberNode.Children [CCNT++]);
        */
        Debug ("ExpressionNumber Resolving...");
        Current = ExpressionNumberNode;
        int CCNT = 0;
        if (ExpressionNumberNode.Children [CCNT].Type == NType.Terminal) {
            CCNT++;
        }
        IDPacket TERM1 = ExpressionTerm (ExpressionNumberNode.Children [CCNT]);
        if (CCNT == 1) {
            IDPacket TEMP = IDPacket.CreateSystemPacket ("TEMP_ZERO", IdentityType.Number);
            STATE.PutNumber (TEMP, 0);
            TERM1 = STATE.MATH_MINUS (TEMP, TERM1);
        }
        CCNT++;

        while (CCNT < ExpressionNumberNode.Children.Count) {
            YSToken NumOperator = ExpressionNumberNode.Children [CCNT++].Token;
            IDPacket TERM2 = ExpressionTerm (ExpressionNumberNode.Children [CCNT++]);
            //TODO Plus Operation
            if (TERM1.Type == IdentityType.Text && TERM2.Type == IdentityType.Text && NumOperator.Type == YSToken.TokenType.Plus) {
                TERM1 = STATE.STR_CONCAT (TERM1, TERM2);
            } else {
                TERM1 = STATE.MATH_OP (TERM1, TERM2, NumOperator);
            }
        }
        Debug ("Exit ExpressionTerm, final type: " + TERM1.Type);
        return TERM1;
    }
Example #19
0
    IDPacket IdentityStructure(YSParseNode IStructureNode)
    {
        Debug ("Resolving structure identity");
        Current = IStructureNode;
        string StructureName = IStructureNode.Children [0].Token.Content;
        StructureFrame Frame;
        GenericFrame GFrame;
        Debug ("Attempting to find structure " + StructureName + " in " + STATE.current_scope.Name);
        IDPacket SID = IDPacket.CreateIDPacket (STATE, StructureName, IdentityType.Structure);
        STATE.TryGetGeneric (SID, out GFrame);
        Frame = (StructureFrame)GFrame;

        ScopeFrame SF = new ScopeFrame (STATE.current_scope, StructureName, ScopeFrame.FrameTypes.Structure);
        SF.MergeForScope (StructureName, Frame);
        STATE.PushScope (SF);

        IDPacket ReturnPacket = null;
        if (IStructureNode.Children.Count > 1) {
            //child Identity
            YSParseNode INode = IStructureNode.Children [1];
            if (INode.Type != NType.Identity
                && INode.Type != NType.IdentityStructure
                && INode.Type != NType.IdentityFunction)
                Error ("Structure child is not an Identity");
            Debug ("Attempting to find identity " + INode.Children [0].Token.Content + " in " + STATE.current_scope.Name);
            ReturnPacket = Identity (INode);
        } else {
            Error ("Structure chain has no children");
        }

        STATE.PopScopeNoSave ();

        if (ReturnPacket == null)
            Error ("Attempting to resolve a structure chain that ends improperly");

        return ReturnPacket;
    }
Example #20
0
 IDPacket ExpressionTerm(YSParseNode ExpressionTermNode)
 {
     Debug ("ExpressionTerm Resolving...");
     Current = ExpressionTermNode;
     IDPacket FAC1 = ExpressionFactor (ExpressionTermNode.Children [0]);
     int CCNT = 1;
     while (CCNT < ExpressionTermNode.Children.Count) {
         /*
         YSToken TermOperator = ExpressionTermNode.Children [CCNT++];
         ExpressionFactor (ExpressionTermNode.Children [CCNT++]);
         */
         YSToken FacOperator = ExpressionTermNode.Children [CCNT++].Token;
         IDPacket FAC2 = ExpressionFactor (ExpressionTermNode.Children [CCNT++]);
         FAC1 = STATE.MATH_OP (FAC1, FAC2, FacOperator);
         //Debug ("Address " + FAC1.Name);
     }
     //Debug ("Address " + FAC1.Name);
     if (FAC1.Type == IdentityType.Unknown)
         Error ("Expression Factor Type is unresolved");
     Debug ("Exit ExpressionBoolean, final type: " + FAC1.Type);
     return FAC1;
 }
Example #21
0
    bool Program(YSParseNode ProgramNode)
    {
        Current = ProgramNode;
        Debug(String.Format("Program Node with {0} children", ProgramNode.Children.Count));

        if (ProgramNode.Children.Count < 1)
            return true;
        int SCNT = 0;
        Header (ProgramNode.Children [SCNT++]);
        while (SCNT < ProgramNode.Children.Count) {
            try{
                Statement (ProgramNode.Children[SCNT++]);
            }catch(InterpreterException){
                if (ERR_ACCEPT-- > 0) {
                    Debug ("Interpreter Error triggered Panic Status");
                    continue;
                } else {
                    Debug ("Maximum error leniency reached. Exiting interpretation");
                }
                return false;
            }catch(StateException){
                if (ERR_ACCEPT-- > 0) {
                    Debug ("State Error triggered Panic Status");
                    continue;
                } else {
                    Debug ("Maximum error leniency reached. Exiting interpretation");
                }
                return false;
            }
        }
        Debug ("Finished Interpretation");
        return true;
    }
Example #22
0
    void Function(YSParseNode FunctionNode)
    {
        Debug ("Beginning a function definition");
        Current = FunctionNode;
        string FunctionName = FunctionNode.Children [0].Token.Content;
        ExpectNonExistance (FunctionName);
        FunctionFrame FunctionFrame = new FunctionFrame ();
        FunctionParamList (FunctionNode.Children [1], ref FunctionFrame);
        IdentityType IType;
        List<int> Dimens;
        DataType (FunctionNode.Children [2], out IType, out Dimens);
        FunctionFrame.Returns = IType;
        FunctionFrame.ReturnDimensions = (Dimens != null) ? Dimens.ToArray () : null;
        //STATE.TranslateTokenTypeToIdentityType (FunctionNode.Children [2].Token.Type);
        FunctionFrame.Block = FunctionNode.Children [3];

        IDPacket newFunction = IDPacket.CreateIDPacket (STATE, FunctionName, IdentityType.Function);
        STATE.PutFunction (newFunction, FunctionFrame);

        Debug ("Finished function definition");
    }
Example #23
0
    //identity
    void Structure(YSParseNode StructureNode)
    {
        Debug ("Initializing Structure..");
        Current = StructureNode;
        string StructureName = StructureNode.Children [0].Token.Content;
        ExpectNonExistance (StructureName);
        StructureFrame structure = new StructureFrame ();

        int CINDEX = 0;
        //find parent
        string ParentName = "";
        if (StructureNode.Children.Count > 1) {
            if (StructureNode.Children [++CINDEX].Type == NType.Terminal) {
                ParentName = StructureNode.Children [++CINDEX].Token.Content;
            }
            //TODO register as child of parent
            IDPacket SID = IDPacket.CreateIDPacket (STATE, StructureName, IdentityType.Structure);

            STATE.PutGeneric (SID, structure);

            STATE.PushScope (new ScopeFrame(structure, StructureName, ScopeFrame.FrameTypes.Structure));
            while (CINDEX < StructureNode.Children.Count) {
                //Debug ("CINDEX " + CINDEX);
                VarCreate (StructureNode.Children[CINDEX++]);
            }
            STATE.PopScopeNoSave ();
            IDPacket newStructure = IDPacket.CreateIDPacket (STATE, StructureName, IdentityType.Structure);
            STATE.PutGeneric (newStructure, structure);
        }

        Debug ("Exit Structure");
    }
Example #24
0
 void FunctionParamList(YSParseNode FunctionParamListNode, ref FunctionFrame Frame)
 {
     Debug ("Reading param list..");
     Current = FunctionParamListNode;
     if (FunctionParamListNode.Children.Count > 0) {
         int FPC = 0;
         while (FPC < FunctionParamListNode.Children.Count) {
             FunctionParamater fp = new FunctionParamater ();
             //fp.Type = STATE.TranslateTokenTypeToIdentityType (FunctionParamListNode.Children [FPC++].Token.Type);
             List<int> Dimens;
             DataType (FunctionParamListNode.Children [FPC++], out fp.Type, out Dimens);
             fp.TypeDimensions = (Dimens != null) ? Dimens.ToArray () : null;
             //Debug ("Type " + fp.Type + " Token " + FunctionParamListNode.Children [FPC].Token.Type);
             fp.Name = FunctionParamListNode.Children [FPC++].Token.Content;
             Frame.Parameters.Add (fp);
         }
     }
     Debug ("Read param list...");
 }
Example #25
0
    //type VarPrimitive(identity expression) { VarPrimitive(identity expression) }
    void VarCreate(YSParseNode VarCreateNode)
    {
        Current = VarCreateNode;
        List<int> Dimensions;
        IdentityType _DataType;
        DataType (VarCreateNode.Children [0], out _DataType, out Dimensions);
        if (Dimensions != null) {
            YSToken NameToken = VarCreateNode.Children [1].Token;
            if (VarCreateNode.Children [2].Type == NType.ExpressionList) {
                IdentityType ResolvedType = IdentityType.Unknown;
                List<int> ReversedDimensions = new List<int> ();
                IDPacket exp_list = ExpressionList (VarCreateNode.Children [2], ref ReversedDimensions, ref ResolvedType);
                IDPacket put = IDPacket.CreateIDPacket (STATE, NameToken.Content, IdentityType.Structure);
                put.ArrayType = ResolvedType;
                ReversedDimensions.Reverse ();
                ArrayFrame AF = new ArrayFrame (put.ArrayType, ReversedDimensions.ToArray());
                STATE.PutGeneric (put, AF);

                GenericFrame CastedGeneric;
                ArrayFrame AF_Casted;
                STATE.TryGetGeneric (put, out CastedGeneric);
                AF_Casted = (ArrayFrame)CastedGeneric;

                STATE.COPY (put, exp_list);
                Debug ("T");
            } else if(VarCreateNode.Children [2].Type == NType.ArrayInit) {
                //TODO array initializer
            } else {
                Error("Arrays must be initialized with an expression list or array initializer");
            }
        } else {
            for (int i = 1; i < VarCreateNode.Children.Count; i++) {
                VarPrimitive (VarCreateNode.Children [i], _DataType);
            }
        }
        Debug ("Exit VarCreate");
    }
Example #26
0
    void Header(YSParseNode HeaderNode)
    {
        List<string> Resource_Sources = new List<string> ();
        YSLinker Linker = new YSLinker ();
        foreach (YSParseNode HeaderItem in HeaderNode.Children) {
            if (HeaderItem.Type == NType.Import) {
                Resource_Sources.Add (HeaderItem.Children [0].Token.Content);
            } else {
                Error ("Unrecognized header type");
            }
        }
        foreach(YSLinker.Resource Resource in Linker.LoadResources (Resource_Sources.ToArray ())) {
            ScopeFrame ResourceScope = new ScopeFrame (Resource.Name, ScopeFrame.FrameTypes.Structure);
            STATE.PushScope (ResourceScope);
            Yumascript.LPIProcess (ref STATE, Resource.Content);
            StructureFrame SFrame = STATE.PopScopeNoSave ();

            IDPacket ResourceFrameID = IDPacket.CreateIDPacket (STATE, Resource.Name, IdentityType.Structure);
            STATE.PutGeneric (ResourceFrameID, SFrame);
        }
    }
Example #27
0
 void Condition(YSParseNode ConditionNode)
 {
     Current = ConditionNode;
     IDPacket EVAL_COND = Expression (ConditionNode.Children [0]);
     ExpectType (IdentityType.Boolean, EVAL_COND.Type);
     bool EVAL_VAL;
     STATE.TryGetBoolean (EVAL_COND, out EVAL_VAL);
     if (EVAL_VAL) {
         Block (ConditionNode.Children [1]);
     }
 }
Example #28
0
 public YSParseNode PopLast()
 {
     YSParseNode node = new YSParseNode();
     int c = 0;
     while (parse_nodes.Count > 0) {
         node = parse_nodes.Pop ();
         c++;
     }
     Debug ("Popped " + c + " nodes");
     Debug ("Last node type " + node.Type);
     return node;
 }