Beispiel #1
0
        public GSTParser(String text)
        {
            _root = ParsingHelper.ParseToTree(text);
            GstNode member = new GstNode();

            _main = parseToGst(_root, member);
        }
Beispiel #2
0
        /// <summary>
        /// 현재 노드와 상위노드에서 검색하여 해당 이름을 가진 노드를 리턴한다. 없으면 null
        /// 변수를 미리 define했을 때에 그 변수가 해당 범위안에 있는지를 알아내는 함수이다.
        /// </summary>
        /// <param name="typeName">찾을 Name</param>
        /// <returns>해당 Name을 가진 노드</returns>
        public GstNode getActiveStruct(String typeName)
        {
            for (int i = 0; i < Children.Count; i++)
            {
                if (Children[i].TypeName.Equals(typeName) && Children[i].Kind == ContextKind.STRUCT)
                {
                    return(Children[i]);
                }
            }
            if (Parent != null)
            {
                GstNode m = Parent.getActiveStruct(typeName);

                if (m != null)
                {
                    return(m);
                }
                else
                {
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
 void addIotKey(GstNode aChild)
 {
     _iotKeyDic.Add(aChild.IOT.Key, aChild);
     if (Parent != null)
     {
         addIotKey(aChild);
     }
 }
Beispiel #4
0
 public GstNode()
 {
     this.TypeName = "";
     this.Name     = "GST";
     this.Kind     = ContextKind.GLOBAL_MAIN;
     this.Type     = DataType.NONE;
     _parent       = null;
 }
Beispiel #5
0
 void addGstKey(GstNode aChild)
 {
     if (aChild.Key.Length > 0)
     {
         _gstKeyDic.Add(aChild.Key, aChild);
     }
     if (Parent != null)
     {
         Parent.addGstKey(aChild);
     }
 }
Beispiel #6
0
 /// <summary>
 /// struct X 형을 가진 변수를 정의할 때 쓰임.
 /// </summary>
 /// <param name="structType"></param>
 /// <param name="name"></param>
 /// <param name="parent"></param>
 public GstNode(String structType, String name, GstNode parent = null)
 {
     this.Name     = name;
     this.Kind     = ContextKind.VARIABLE;
     this.Type     = DataType.STRUCT;
     this.TypeName = structType;
     if (parent != null)
     {
         _parent = parent;
     }
     Comment = "";
 }
Beispiel #7
0
 /// <summary>
 /// 최종 노드 만들때 쓰임.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="name"></param>
 /// <param name="Key"></param>
 /// <param name="parent"></param>
 public GstNode(String type, String name, String Key, GstNode parent = null)
 {
     this.Name     = name;
     this.Kind     = ContextKind.VARIABLE;
     this.Type     = (DataType)(DataTypeStr.ToList().IndexOf(type));
     this.TypeName = DataTypeStr2[(int)this.Type];// type;
     if (parent != null)
     {
         _parent = parent;
     }
     Comment = "";
 }
Beispiel #8
0
 /// <summary>
 /// struct 형이 아닌 일반형을 정의할 때 쓰임.
 /// </summary>
 /// <param name="type"></param>
 /// <param name="name"></param>
 /// <param name="parent"></param>
 public GstNode(DataType type, String name, GstNode parent = null)
 {
     this.Name     = name;
     this.Kind     = ContextKind.VARIABLE;
     this.Type     = type;
     this.TypeName = DataTypeStr2[(int)type];
     if (parent != null)
     {
         _parent = parent;
     }
     Comment = "";
 }
Beispiel #9
0
 public GstNode(String StructTypeName, GstNode parent = null)
 {
     this.TypeName = StructTypeName;
     String[] typeTokens = StructTypeName.Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
     this.Name = (typeTokens.Length == 2)? typeTokens[1] : typeTokens[0];
     this.Kind = ContextKind.STRUCT;
     this.Type = DataType.STRUCT;
     if (parent != null)
     {
         _parent = parent;
     }
     Comment = "";
 }
Beispiel #10
0
        public GstNode getFirstChildNode(String nodeName)
        {
            GstNode aChild = null;

            foreach (GstNode node in Children)
            {
                if (node.Name.Equals(nodeName))
                {
                    return(node);
                }

                if (node.Children.Count > 0 && (aChild = node.getFirstChildNode(nodeName)) != null)
                {
                    return(aChild);
                }
            }
            return(null);
        }
Beispiel #11
0
        /// <summary>
        /// 현재 노드와 상위노드에서 검색하여 해당 이름을 가진 노드를 리턴한다. 없으면 null
        /// 변수를 미리 define했을 때에 그 변수가 해당 범위안에 있는지를 알아내는 함수이다.
        /// </summary>
        /// <param name="name">찾을 Name</param>
        /// <returns>해당 Name을 가진 노드</returns>
        public GstNode getActiveMember(String name)
        {
            for (int i = 0; i < Children.Count; i++)
            {
                if (Children[i].Name.Equals(name))
                {
                    return(Children[i]);
                }
            }
            GstNode m = Parent.getActiveMember(name);

            if (m != null)
            {
                return(m);
            }
            else
            {
                return(null);
            }
        }
Beispiel #12
0
        GstNode parseToGst(ContextTree tree, GstNode member)
        {
            String  title;//
            String  type, name;
            int     size;
            GstNode aNode;

            if (tree.Children.Count == 0) //변수지정이나 할당. 한 줄에 끝나는 구문. GST파일에서는 GST가 유일하다.
            {
                title = tree.Header.Trim();
                name  = ParsingHelper.getAllocTokens(title, out type, out size);
                if (type.Contains("struct") && member.Kind == ContextKind.VARIABLE) //depth가 깊어짐.
                {
                    aNode = member.getActiveStruct(type);                           //같은 struct타입을 가져와서 넣어준다.
                    foreach (GstNode node in aNode.Children)
                    {
                        member.addChild(node);
                    }
                }
                return(null);
            }
            else if (tree.Header.Trim().Length == 0) //main
            {
                foreach (ContextTree aChild in tree.Children)
                {
                    title = aChild.Header.Trim();
                    if (title.Split(" ".ToCharArray()).Length == 2) //struct
                    {
                        aNode = new GstNode(aChild.Header.Trim(), member);
                        member.addChild(aNode);
                        parseToGst(aChild, aNode);
                    }
                    else //gst
                    {
                        name  = ParsingHelper.getAllocTokens(title, out type, out size);
                        aNode = new GstNode(type, name, member);
                        member.addChild(aNode);
                        parseToGst(aChild, aNode);
                    }
                }
            }
            else if (tree.Header.Contains("struct"))//struct
            {
                //for (int i = 0; i < tree.Child.Count; i++)
                foreach (ContextTree aChild in tree.Children)
                {
                    title = aChild.Header.Trim();

                    name = ParsingHelper.getAllocTokens(title, out type, out size);


                    if (type.Contains("struct")) //depth가 깊어짐.
                    {
                        aNode = new GstNode(type, name, member);
                        member.addChild(aNode);
                        parseToGst(aChild, aNode);
                    }
                    else //struct가 아닐 경우, 일반 변수나 배열
                    {
                        if (size > 0)//배열
                        {
                            for (int i = 0; i < size; i++)
                            {
                                aNode = new GstNode(member.TypeFromStr(type), name + "[" + i + "]", member);
                                member.addChild(aNode);
                            }
                        }
                        else //일반 변수
                        {
                            aNode = new GstNode(member.TypeFromStr(type), name, member);
                            member.addChild(aNode);
                        }
                    }
                }
            }
            else
            {
                throw new Exception("구문분석 오류..");
            }

            return(member);
        }
Beispiel #13
0
 public void addChild(GstNode aChild)
 {
     _child.Add(aChild);
     addGstKey(aChild);
     aChild._parent = this;
 }