示例#1
0
        public CharacterSetBuild Evaluate()
        {
            switch (this.m_Type)
            {
            case SetType.Chars:
                return(this.m_Characters);

            case SetType.Name:
            {
                CharacterSetBuild characterSet = (CharacterSetBuild)BuilderApp.GetCharacterSet(this.m_Text);
                if (characterSet != null)
                {
                    return(new CharacterSetBuild(characterSet));
                }
                BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Character set is not defined", "The character set {" + this.m_Text + "} was not defined in the grammar.", "");
                return(new CharacterSetBuild());
            }
            }
            return(new CharacterSetBuild());
        }
示例#2
0
        private static AutomataType CreateAutomataItem(RegExpItem Item)
        {
            AutomataType type;
            int          head;
            int          num3;
            int          num4;
            int          tail;

            if (Item.Data is RegExp)
            {
                RegExpItem item2 = Item;
                RegExp     data  = (RegExp)item2.Data;
                item2.Data = data;
                AutomataType type3 = CreateSubAutomata(data);
                head = type3.Head;
                tail = type3.Tail;
                num3 = head;
                num4 = tail;
            }
            else if (!(Item.Data is SetItem))
            {
                BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid internal token at CreateAutomataItem(): " + Versioned.TypeName(RuntimeHelpers.GetObjectValue(Item.Data)));
            }
            else
            {
                CharacterSetBuild characters;
                SetItem           item = (SetItem)Item.Data;
                switch (item.Type)
                {
                case SetItem.SetType.Chars:
                    characters = (CharacterSetBuild)item.Characters;
                    head       = AddState();
                    tail       = AddState();
                    NFA[head].AddEdge(characters, tail);
                    num3 = head;
                    num4 = tail;
                    break;

                case SetItem.SetType.Name:
                    characters = (CharacterSetBuild)BuilderApp.GetCharacterSet(item.Text);
                    if (characters == null)
                    {
                        BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Unknown user-defined set: {" + item.Text + "}");
                        break;
                    }
                    tail = AddState();
                    head = AddState();
                    NFA[head].AddEdge(characters, tail);
                    num3 = head;
                    num4 = tail;
                    break;

                case SetItem.SetType.Sequence:
                {
                    int num6;
                    head = AddState();
                    tail = head;
                    string text = item.Text;
                    short  num7 = (short)(text.Length - 1);
                    for (short i = 0; i <= num7; i = (short)(i + 1))
                    {
                        num6 = tail;
                        tail = AddState();
                        NFA[num6].AddEdge(new CharacterSetBuild(Conversions.ToString(text[i])), tail);
                    }
                    num3 = num6;
                    num4 = tail;
                    break;
                }

                default:
                    BuilderApp.Log.Add(SysLogSection.Grammar, SysLogAlert.Critical, "Invalid internal token at CreateAutomataItem(): " + Versioned.TypeName(RuntimeHelpers.GetObjectValue(Item.Data)));
                    break;
                }
            }
            if ((num3 == 0) | (num4 == 0))
            {
                Debug.WriteLine("ERROR: BAD KLEENE DATA");
            }
            switch (Item.Kleene)
            {
            case "*":
                NFA[num3].AddLambdaEdge(num4);
                NFA[num4].AddLambdaEdge(num3);
                break;

            case "+":
                NFA[num4].AddLambdaEdge(num3);
                break;

            case "?":
                NFA[num3].AddLambdaEdge(num4);
                break;
            }
            type.Head = (short)head;
            type.Tail = (short)tail;
            return(type);
        }