protected ElementElement ParseElement()
        {
            GeneratorLexElement var1 = _Reader.PeekOrThrow("element", GeneratorLexType.OpenBrace, GeneratorLexType.OpenBracket, GeneratorLexType.OpenPar, GeneratorLexType.Terminal, GeneratorLexType.Nonterminal);

            if (var1.Type == GeneratorLexType.OpenBrace)
            {
                RepeatElement var2 = this.ParseRepeat();
                return(this.ReturnElement(var2));
            }
            else if (var1.Type == GeneratorLexType.OpenBracket)
            {
                OptionElement var3 = this.ParseOption();
                return(this.ReturnElement(var3));
            }
            else if (var1.Type == GeneratorLexType.OpenPar)
            {
                GroupElement var4 = this.ParseGroup();
                return(this.ReturnElement(var4));
            }
            else if (var1.Type == GeneratorLexType.Terminal || var1.Type == GeneratorLexType.Nonterminal)
            {
                LiteralElement var5 = this.ParseLiteral();
                return(this.ReturnElement(var5));
            }
            else
            {
                throw _Reader.Error("element", GeneratorLexType.OpenBrace, GeneratorLexType.OpenBracket, GeneratorLexType.OpenPar, GeneratorLexType.Terminal, GeneratorLexType.Nonterminal);
            }
        }
        void firstFollowing(ScriptParserGenerator gen, DefinitionElement root, TextWriter writer, DefinitionContent content)
        {
            writer.WriteLine(string.Format("   {0}: first:<{1}> following:<{2}>", content, joinStr(content.GetFirstTerminals(gen)), joinStr(content.GetFollowingTerminals(gen))));
            SelectionElement s = content as SelectionElement;

            if (s != null)
            {
                foreach (ElementsElement elems in s.Candidates)
                {
                    firstFollowing(gen, root, writer, elems);
                }
            }
            ExpressionsElement ex = content as ExpressionsElement;

            if (ex != null)
            {
                foreach (ElementsElement elems in ex.Selection.Candidates)
                {
                    firstFollowing(gen, root, writer, elems);
                }
            }
            ElementsElement es = content as ElementsElement;

            if (es != null)
            {
                foreach (ElementElement elem in es.Elements)
                {
                    firstFollowing(gen, root, writer, elem);
                }
            }
            RepeatElement r = content as RepeatElement;

            if (r != null)
            {
                firstFollowing(gen, root, writer, r.InnerExpression);
            }
            OptionElement o = content as OptionElement;

            if (o != null)
            {
                firstFollowing(gen, root, writer, o.InnerExpression);
            }
            GroupElement g = content as GroupElement;

            if (g != null)
            {
                firstFollowing(gen, root, writer, g.InnerExpression);
            }
            LiteralElement l = content as LiteralElement;
        }
        public int GetHashCode(DefinitionContent obj)
        {
            SelectionElement s = obj as SelectionElement;

            if (s != null)
            {
                // ハッシュ値計算できないので適当
                return(15773);
            }
            ExpressionsElement ex = obj as ExpressionsElement;

            if (ex != null)
            {
                return(this.GetHashCode(ex.Selection));
            }
            ElementsElement es = obj as ElementsElement;

            if (es != null)
            {
                return(es.Elements.Sum(e => this.GetHashCode(e)));
            }
            RepeatElement r = obj as RepeatElement;

            if (r != null)
            {
                return(1744579 + this.GetHashCode(r.InnerExpression));
            }
            OptionElement o = obj as OptionElement;

            if (o != null)
            {
                return(3234551 + this.GetHashCode(o.InnerExpression));
            }
            GroupElement g = obj as GroupElement;

            if (g != null)
            {
                return(this.GetHashCode(g.InnerExpression));
            }
            LiteralElement l = obj as LiteralElement;

            if (l != null)
            {
                return(l.InnerWord.GetHashCode() + l.Literal.Type.GetHashCode());
            }
            Debug.Assert(false);
            return(7);
        }
 /// <summary>
 /// element = repeat ;
 /// </summary>
 /// <param name="repeat">repeat</param>
 protected abstract ElementElement ReturnElement(RepeatElement repeat);
        public bool Equals(DefinitionContent x, DefinitionContent y)
        {
            GroupElement x1 = x as GroupElement;

            if (x1 != null)
            {
                return(this.Equals(x1.InnerExpression, y));
            }
            GroupElement y1 = y as GroupElement;

            if (y1 != null)
            {
                return(this.Equals(x, y1.InnerExpression));
            }
            ExpressionsElement x2 = x as ExpressionsElement;

            if (x2 != null)
            {
                return(this.Equals(x2.Selection, y));
            }
            ExpressionsElement y2 = y as ExpressionsElement;

            if (y2 != null)
            {
                return(this.Equals(x, y2.Selection));
            }
            SelectionElement x3 = x as SelectionElement;
            SelectionElement y3 = y as SelectionElement;

            if (x3 != null && y3 != null)
            {
                // ∀x0(∈ x) x0 ∈ y かつ ∀y0(∈ y) y0 ∈ x ならば x = y
                return(x3.Candidates.All(x0 => y3.Candidates.Any(y0 => this.Equals(x0, y0))) && y3.Candidates.All(y0 => x3.Candidates.Any(x0 => this.Equals(x0, y0))));
            }
            ElementsElement x4 = x as ElementsElement;
            ElementsElement y4 = y as ElementsElement;

            if (x4 != null && y4 != null)
            {
                if (x4.Elements.Count != y4.Elements.Count)
                {
                    return(false);
                }
                return(CollectionEx.Zip(x4.Elements, y4.Elements, (x0, y0) => this.Equals(x0, y0)).All(eq => eq));
            }
            RepeatElement x5 = x as RepeatElement;
            RepeatElement y5 = y as RepeatElement;

            if (x5 != null && y5 != null)
            {
                return(this.Equals(x5.InnerExpression, y5.InnerExpression));
            }
            OptionElement x6 = x as OptionElement;
            OptionElement y6 = y as OptionElement;

            if (x6 != null && y6 != null)
            {
                return(this.Equals(x6.InnerExpression, y6.InnerExpression));
            }
            LiteralElement x7 = x as LiteralElement;
            LiteralElement y7 = y as LiteralElement;

            if (x7 != null && y7 != null)
            {
                return(x7.Literal.Type == y7.Literal.Type && x7.InnerWord == y7.InnerWord);
            }
            if (x == null && y == null)
            {
                return(true);
            }
            if (x == null || y == null)
            {
                return(false);
            }
            return(false);
        }
Exemplo n.º 6
0
 /// <summary>
 /// element = repeat ;
 /// </summary>
 /// <param name="repeat">repeat</param>
 protected override ElementElement ReturnElement(RepeatElement repeat)
 {
     return(repeat);
 }