示例#1
0
        List <IndexNode> IndexedAccess()
        {
            List <IndexNode> indexes = new List <IndexNode>();

            while (Check(TokenType.LEFT_BRACKET) || Check(TokenType.DOT))
            {
                if (Match(TokenType.LEFT_BRACKET))
                {
                    IndexNode index = new IndexNode(
                        Expression(),
                        VarAccessType.BRACKET,
                        Previous().PositionData);
                    indexes.Add(index);

                    Consume(
                        TokenType.RIGHT_BRACKET,
                        "Expected ']' after 'compoundVar identifier'",
                        true
                        );
                }
                else if (Match(TokenType.DOT))
                {
                    Match(TokenType.IDENTIFIER);
                    string    this_name = (Previous() as TokenString).value;
                    IndexNode index     = new IndexNode(
                        this_name,
                        VarAccessType.DOT,
                        Previous().PositionData);
                    indexes.Add(index);
                }
            }
            return(indexes);
        }
示例#2
0
        private void ChunkFunctionDeclaration(FunctionDeclarationNode p_node)
        {
            //register name
            if (p_node.Variable.Indexes.Count == 0) // it is a regular function
            {
                if (globals.Contains(p_node.Variable.Name))
                {
                    Error("Local functions can not override global ones.", p_node.PositionData);
                }

                Nullable <Variable> maybe_name = SetVar(p_node.Variable.Name);

                if (maybe_name.HasValue)
                {
                    Variable this_function = maybe_name.Value;
                    if (this_function.type == ValueType.Global)
                    {
                        CompileFunction(this_function.name, p_node, true);
                    }
                    else
                    {
                        CompileFunction(this_function.name, p_node, false);
                    }
                }
                else
                {
                    Error("Function name has already been used!", p_node.PositionData);
                }
            }
            else
            {// it is a member function
                // assemble a name for it
                string name = p_node.Variable.Name;
                for (int i = 0; i < p_node.Variable.Indexes.Count; i++)
                {
                    if (p_node.Variable.Indexes[i].Type == NodeType.VARIABLE)
                    {
                        IndexNode this_index = p_node.Variable.Indexes[i];
                        if (this_index.AccessType == VarAccessType.COLON)
                        {
                            Error("Method Declaration is not supported yet!", p_node.PositionData);
                        }
                        if (this_index.IsAnonymous)
                        {
                            name += GetLambdaName(p_node);
                        }
                        else
                        {
                            name += "." + this_index.Name;
                        }
                    }
                }
                // Break it down
                MemberFunctionDeclarationNode extracted_function = new MemberFunctionDeclarationNode(name, p_node.Parameters, p_node.Body, p_node.PositionData);
                AssignmentNode new_assigment = new AssignmentNode(p_node.Variable, extracted_function, AssignmentOperatorType.ASSIGN, p_node.PositionData);
                StmtExprNode   new_stmt_expr = new StmtExprNode(new_assigment, p_node.PositionData);
                ChunkIt(new_stmt_expr);
            }
        }
示例#3
0
 private void LoadIndex(IndexNode p_node)
 {
     if (p_node.IsAnonymous)
     {
         ChunkIt(p_node.Expression);
     }
     else
     {
         Operand string_address = (Operand)AddData(p_node.Name);
         Add(OpCode.LOAD_DATA, string_address, p_node.PositionData);
     }
 }
示例#4
0
 private void PrintIndex(IndexNode p_node)
 {
     if (p_node.IsAnonymous)
     {
         if ((p_node.GetType() != typeof(VariableNode)) || p_node.AccessType == VarAccessType.BRACKET)
         {
             Console.Write("[");
             Print(p_node.Expression);
             Console.Write("]");
         }
         else if (p_node.AccessType == VarAccessType.COLON)
         {
             Console.Write(":");
             Print(p_node.Expression);
         }
         else if (p_node.AccessType == VarAccessType.DOT)
         {
             Console.Write(".");
             Print(p_node.Expression);
         }
     }
     else
     {
         if ((p_node.GetType() != typeof(VariableNode)) || p_node.AccessType == VarAccessType.BRACKET)
         {
             Console.Write("[" + p_node.Name + "]");
         }
         else if (p_node.AccessType == VarAccessType.COLON)
         {
             Console.Write(":" + p_node.Name);
         }
         else if (p_node.AccessType == VarAccessType.DOT)
         {
             Console.Write("." + p_node.Name);
         }
     }
 }