예제 #1
0
파일: AST.cs 프로젝트: cubean/CG
 public POU(string name, int number, eBLOCK200_POUTYPES type)
 {
     Name = name;
     Number = number;
     BlockNumber = number.ToString();
     Type = type;
     Body = new NodeList();
 }
예제 #2
0
파일: AST.cs 프로젝트: cubean/CG
        public override void Init(ParsingContext context, ParseTreeNode treeNode)
        {
            base.Init(context, treeNode);
            Name = treeNode.ChildNodes[1].ChildNodes[0].Token.Text;
            BlockNumber = treeNode.ChildNodes[1].ChildNodes[1].Token.Text;

            string nr = string.Empty;
            if (BlockNumber.StartsWith("OB"))
            {
                nr = "0";
                Type = eBLOCK200_POUTYPES.eBLOCK200_POUTYPES_MAIN;
            }
            else if (BlockNumber.StartsWith("SBR"))
            {
                nr = BlockNumber.Substring(3);
                Type = eBLOCK200_POUTYPES.eBLOCK200_POUTYPES_SUBROUTINE;
            }
            else if (BlockNumber.StartsWith("INT"))
            {
                nr = BlockNumber.Substring(3);
                Type = eBLOCK200_POUTYPES.eBLOCK200_POUTYPES_INTERRUPT;
            }
            if (!int.TryParse(nr, out Number))
                Number = 0;
            int varIndex = 2;
            if (treeNode.FirstChild.Token.Text == "SUBROUTINE_BLOCK")
            {
                foreach (var io in treeNode.ChildNodes[2].ChildNodes)
                {
                    switch (io.FirstChild.Token.Text)
                    {
                        case "VAR_INPUT":
                            VarInput = AddChild(string.Empty, io);
                            Parameters.AddRange(VarInput.ChildNodes);
                            break;
                        case "VAR_OUTPUT":
                            VarOutput = AddChild(string.Empty, io);
                            Parameters.AddRange(VarOutput.ChildNodes);
                            break;
                        case "VAR_IN_OUT":
                            VarInOut = AddChild(string.Empty, io);
                            Parameters.AddRange(VarInOut.ChildNodes);
                            break;
                    }
                }
                varIndex = 3;
            }
            if (treeNode.ChildNodes[varIndex].ChildNodes.Count > 0)
            {
                Var = AddChild(string.Empty, treeNode.ChildNodes[varIndex].FirstChild);
                Parameters.AddRange(Var.ChildNodes);
            }

            Body = AddChild("Body", treeNode.ChildNodes[varIndex+1].ChildNodes[1]);
            AsString = Name + ":" + BlockNumber;
        }
예제 #3
0
파일: AST.cs 프로젝트: cubean/CG
 public void AddPOU(eBLOCK200_POUTYPES type, POU pou)
 {
     switch (type)
     {
         case eBLOCK200_POUTYPES.eBLOCK200_POUTYPES_MAIN:
             Main = pou;
             pou.SetParent(this);
             break;
         case eBLOCK200_POUTYPES.eBLOCK200_POUTYPES_SUBROUTINE:
             if (Subroutins == null) {
                 Subroutins = new NodeList();
                 Subroutins.SetParent(this);
             }
             (Subroutins as NodeList).AddNode(pou);
             break;
         case eBLOCK200_POUTYPES.eBLOCK200_POUTYPES_INTERRUPT:
             if (Interupts == null) {
                 Interupts = new NodeList();
                 Interupts.SetParent(this);
             }
             (Interupts as NodeList).AddNode(pou);
             break;
     }
 }