示例#1
0
        public override void Init(ParsingContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);

            ExpectedTerms = new List <Terminal>(treeNode.State.ExpectedTerminals);

            TreeFuncs = UOSLBase.GetFuncs(context);

            TreeNode = treeNode;

            if (treeNode.Token != null && treeNode.Token.KeyTerm is Tokenizer)
            {
                m_UoTypeToken = ((Tokenizer)treeNode.Token.KeyTerm).TokenType;
            }
            else if (treeNode.ChildNodes.Count == 1 && treeNode.FirstChild.AstNode is ScopedNode)
            {
                SetUoToken(((ScopedNode)treeNode.FirstChild.AstNode).UoToken);
                SetUoTypeToken(((ScopedNode)treeNode.FirstChild.AstNode).UoTypeToken);
            }
        }
示例#2
0
        public static void AddStatementList(ScopedNode aststatementsroot, ParseTreeNode parsestatementsroot, ParsingContext context, bool adderrors = true)
        {
            foreach (ParseTreeNode node in parsestatementsroot.ChildNodes)
            {
                ParseTreeNode cnode = null;

                if (node.AstNode is DeclarationNode) // member
                {
                    cnode = node;
                }
                else if (node.ChildNodes.Count > 0)
                {
                    if (node.FirstChild.AstNode is DeclarationNode)
                    {
                        cnode = node.FirstChild;
                    }
                    else if (node.FirstChild.ChildNodes.Count > 0 && node.FirstChild.FirstChild.AstNode is DeclarationNode)
                    {
                        cnode = node.FirstChild.FirstChild;
                    }
                }

                if (cnode != null)
                {
                    if (cnode.AstNode is MemberDeclarationNode)
                    {
                        UOSLBase.AddMember(new Field((MemberDeclarationNode)cnode.AstNode, context), context);
                    }
                    //else if this is a regular variable declaration within a function, the function will add the var to scope when the function node is created
                }

                ScopedNode newnode = GetStatement(node, context, adderrors);
                if (newnode != null)
                {
                    aststatementsroot.ChildNodes.Add(newnode);
                    newnode.Parent = aststatementsroot;
                }
            }
        }
示例#3
0
        public override void Init(ParsingContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);

            LanguageOption Options = context.GetOptions();

            field = new Field(this, context, true);
            if (!Options.HasOption(LanguageOption.Constants))
            {
                context.AddParserMessage(ParserErrorLevel.Error, this.Span, "Constants are not valid for this source.");
            }
            else if (Assign == null || Assign.Expression.UoToken == null || !Assign.Expression.UoToken.IsLiteral)
            {
                if (Assign != null && Assign.Expression.AsString == "ExpressionList")
                {
                    foreach (ExpressionNode node in Assign.Expression.ChildNodes)
                    {
                        if (node.UoToken == null || !node.UoToken.IsLiteral)
                        {
                            context.AddParserMessage(ParserErrorLevel.Error, node.Span, "Constant list elements must be compile time constants.");
                        }
                    }

                    field.Value = Assign.Expression.ChildNodes.Select(node => new ConstantListElement(((ExpressionNode)node).UoToken, ((ExpressionNode)node).UoTypeToken));
                }
                else
                {
                    context.AddParserMessage(ParserErrorLevel.Error, Span, "Constants must be assigned a compile time constant value when declared.");
                    field.Value = "0";
                }
            }
            else
            {
                field.Value = Assign.Expression.UoToken.Value;
            }

            UOSLBase.AddMember(field, context);
        }
示例#4
0
        public virtual void CheckScope(ParsingContext context)
        {
            if (m_LocalVars != null)
            {
                List <Field> members = UOSLBase.GetMembers(context);
                foreach (Field field in m_LocalVars)
                {
                    Field found = null;
                    if (members != null && (found = members.FirstOrDefault(member => member.Name == field.Name)) != null && found.Node != field.Node && found.Node != null && !(field.Node is MemberDeclarationNode))
                    {
                        if (context.GetOptions() == LanguageOption.Extended)
                        {
                            context.AddParserMessage(ParserErrorLevel.Error, field.Node.Span, "Cannot declare a local variable {0}. Member field {0} is declared.", field.Name);
                        }
                        else if (found.UoTypeToken == field.UoTypeToken)
                        {
                            context.AddParserMessage(ParserErrorLevel.Info, field.Node.Span, "Member field {0} is also declared, this local variable is OK.", field.Name);
                        }
                        else
                        {
                            context.AddParserMessage(ParserErrorLevel.Info, field.Node.Span, "Member Field {0} is also declared as a different type, this local variable is OK.", field.Name);
                        }
                    }
                }
                if (TreeFuncs != null)
                {
                    Method found;

                    foreach (Field field in m_LocalVars)
                    {
                        if ((found = TreeFuncs.FirstOrDefault(func => func.Name == field.Name)) != null)
                        {
                            context.AddParserMessage(ParserErrorLevel.Error, field.Node.Span, "A function {0} is already declared with the same name.", field.Name);
                        }
                    }
                }
            }
        }
示例#5
0
        public override void Init(ParsingContext context, ParseTreeNode parseNode)
        {
            base.Init(context, parseNode);

            List <Method> ScopeFuncs = UOSLBase.GetFuncs(context);

            CoreCommands.LoadCoreCommands(context);

            LanguageOption Options = context.GetOptions();

            bool canLoadInherit = true;

            foreach (ParseTreeNode cnode in parseNode.ChildNodes)
            {
                ScopedNode toAdd = null;

                if (cnode.AstNode is InheritsNode)
                {
                    if (canLoadInherit)
                    {
                        toAdd = (ScopedNode)cnode.AstNode;
                        InheritsNode iNode = (InheritsNode)cnode.AstNode;
                        if (Depends.ContainsKey(iNode.Filename))
                        {
                            context.AddParserMessage(ParserErrorLevel.Error, cnode.Span, "File {0} is already loaded in this inheritance chain, cannot reload.", iNode.Filename);
                        }
                        else
                        {
                            m_grammar.LoadFile(iNode.Filename, this, context, Depends);
                        }
                    }
                    else
                    {
                        context.AddParserMessage(ParserErrorLevel.Error, cnode.Span, "Inherits declaration(s) must appear first in the file, may not be made after other declarations.");
                    }
                }
                else
                {
                    canLoadInherit = false;

                    if (cnode.AstNode is EventDefNode)
                    {
                        toAdd = (EventDefNode)cnode.AstNode;
                    }
                    else if (cnode.AstNode is UoCoreFunctionNode)
                    {
                        CoreCommands.Funcs.Add(new Method((FunctionProtoNode)cnode.AstNode, context));
                    }
                    else if (cnode.AstNode is FunctionDefNode)
                    {
                        toAdd = (FunctionDefNode)cnode.AstNode;

                        Method found;
                        string name = ((FunctionDefNode)toAdd).NameString;

                        if (ScopeFuncs != null && (found = ScopeFuncs.FirstOrDefault(func => func.Name == name)) != null && found.DefNode == null)
                        {
                            found.Define((FunctionDefNode)toAdd, context);
                        }
                        else
                        {
                            UOSLBase.AddFunc(new Method((FunctionDefNode)toAdd, context), context);
                        }
                    }
                    else if (cnode.AstNode is FunctionProtoNode)
                    {
                        toAdd = (FunctionProtoNode)cnode.AstNode;
                        UOSLBase.AddFunc(new Method((FunctionProtoNode)toAdd, context), context);
                    }
                    else if (cnode.AstNode is ConstantDeclarationNode)
                    {
                        ConstantDeclarationNode constnode = (ConstantDeclarationNode)cnode.AstNode;
                        toAdd = constnode;
                    }
                    else if (cnode.AstNode is MemberDeclarationNode)
                    {
                        toAdd = (ScopedNode)cnode.AstNode;
                        if (((MemberDeclarationNode)cnode.AstNode).Assign != null)
                        {
                            context.AddParserMessage(ParserErrorLevel.Warning, ((MemberDeclarationNode)cnode.AstNode).Assign.Span, "Member assignments in Declarations are not respected.", ((MemberDeclarationNode)cnode.AstNode).Declaration.Term.Name);
                        }
                        UOSLBase.AddMember(new Field((MemberDeclarationNode)cnode.AstNode, context), context); // global scope?
                    }
                    else if (cnode.AstNode is DeclarationNode)
                    {
                        toAdd = (DeclarationNode)cnode.AstNode;
                        AddVar(new Field((DeclarationNode)toAdd, context), context);
                    }
                }

                if (toAdd != null)
                {
                    ChildNodes.Add(toAdd);
                    toAdd.Parent = this;
                }
            }
        }
示例#6
0
 public DeclarationsNode(UOSLBase grammar)
 {
     m_grammar = grammar;
 }