예제 #1
0
        public class RuleParams : RuleMultiple {   // NAME S (, S NAME S )*
            public RuleParams(Rule Parent)
                : base(Parent, 0)
            {
                RuleAlternative par = new RuleAlternative(m_Parent);

                par.AddNode(new RuleName(m_Parent));
                par.AddNode(new RuleNumber(m_Parent));
                par.AddNode(new RuleString(m_Parent));
                par.AddNode(new RuleBool(m_Parent));

                RuleSequence z = new RuleSequence(this);

                z.AddNode(par);
                RuleSequence x = new RuleSequence(this);

                x.AddNode(new RuleSeparator(this));
                x.AddNode(z);
                RuleMultiple y = new RuleMultiple(this, 0);

                y.AddNode(x);
                RuleSequence w = new RuleSequence(this);

                w.AddNode(z);
                w.AddNode(y);
                this.AddNode(w);
            }
예제 #2
0
        public class RuleRetDecl : RuleSequence {  //-> BASETYPE [S NAME ] (, BASETYPE [S NAME])*
            public RuleRetDecl(Rule Parent)
                : base(Parent)
            {
                RuleAlternative w = new RuleAlternative(this);
                RuleSequence    u = new RuleSequence(this);

                u.AddNode(new RuleBaseType(this));
                u.AddNode(new RuleSpace(this));
                u.AddNode(new RuleName(this));
                w.AddNode(u);
                u = new RuleSequence(this);
                u.AddNode(new RuleBaseType(this));
                w.AddNode(u);

                this.AddNode(new RuleRegex(this, "->" + s_ManyWhitespace, this));
                this.AddNode(w);
                RuleSequence x = new RuleSequence(this);

                x.AddNode(new RuleSeparator(this));
                x.AddNode(w);
                RuleMultiple y = new RuleMultiple(this, 0);

                y.AddNode(x);
                this.AddNode(y);
            }
예제 #3
0
        public class RuleFunctionCall : RuleSequence {   //NAME S*'(' PARAMS? ')' S* RETURNS? (COMMENT | EOL)
            public RuleFunctionCall(Rule Parent)
                : base(Parent)
            {
                m_Parent = this;
                this.AddNode(new RuleSpaceOptional(m_Parent));
                this.AddNode(new RuleName(m_Parent));
                this.AddNode(new RuleLPar(m_Parent));
                RuleOption y = new RuleOption(m_Parent);

                y.AddNode(new RuleParams(m_Parent));
                this.AddNode(y);
                this.AddNode(new RuleRPar(m_Parent));
                y = new RuleOption(m_Parent);
                y.AddNode(new RuleReturns(m_Parent));
                this.AddNode(y);
                this.AddNode(new RuleEOLComment(m_Parent));
                //Todo parse catch-exception statement
                RuleOption   cat = new RuleOption(m_Parent);
                RuleSequence z   = new RuleSequence(m_Parent);

                z.AddNode(new RuleRegex(m_Parent, s_ManyWhitespace + "catch", this));
                z.AddNode(new RuleLPar(m_Parent));
                z.AddNode(new RuleParams(m_Parent));
                z.AddNode(new RuleRPar(m_Parent));
                z.AddNode(new RuleEOLComment(m_Parent));
                z.AddNode(new RuleLCurlPar(m_Parent));
                z.AddNode(new RuleBody(m_Parent));
                z.AddNode(new RuleRCurlPar(m_Parent));
                cat.AddNode(z);
                this.AddNode(cat);
            }
예제 #4
0
파일: Day19.cs 프로젝트: nicozink/AOC2020
            /// <summary>
            /// Reads a specific rule from the input. The rule is given in the format:
            /// 80: 116 116 | 119 134
            /// Where the '|' character seperates alternative sub-rules.
            /// </summary>
            /// <param name="input">The input.</param>
            /// <returns>The list of sub-rules.</returns>
            private List <Rule> ReadRule(string input)
            {
                var subRules = input
                               .Split(new[] { " | " }, StringSplitOptions.None)
                               .Select(x => x.Split().ToList())
                               .ToList();

                var rules = new List <Rule>();

                foreach (var subRule in subRules)
                {
                    if (subRule.Count == 1 && subRule[0].Contains("\""))
                    {
                        var rule = new RuleToken()
                        {
                            Value = subRule[0][1]
                        };

                        rules.Add(rule);
                    }
                    else
                    {
                        var rule = new RuleSequence()
                        {
                            Nodes = subRule
                                    .Select(x => int.Parse(x))
                                    .ToList()
                        };

                        rules.Add(rule);
                    }
                }

                return(rules);
            }
예제 #5
0
            private Rule addRule(RuleAlternative Collection, Rule ToAdd)
            {
                RuleSequence y = new RuleSequence(ToAdd.GetParent());

                y.AddNode(ToAdd);
                Collection.AddNode(y);
                return(Collection);
            }
예제 #6
0
        public class RuleBoolExpr : RuleSequence {   //RuleBoolVarExpr (S ('||' / '&&') S RuleBoolVarExpr)*;
            public RuleBoolExpr(Rule Parent)
                : base(Parent)
            {
                this.AddNode(new RuleBoolVarExpr(Parent));
                RuleSequence x = new RuleSequence(Parent);

                x.AddNode(new RuleRegex(m_Parent, "(\\|\\||\\&\\&)", this));      //todo Number <= Number bool!=bool \\=\\=|\\>\\=|\\<\\=|\\>|\\<|\\!\\=
                x.AddNode(new RuleBoolVarExpr(Parent));
                RuleMultiple y = new RuleMultiple(Parent, 0);

                y.AddNode(x);
                this.AddNode(y);
            }
예제 #7
0
        public class RuleMultExpr : RuleSequence {   //power_expression (S ('*' / '/') S power_expression)*;
            public RuleMultExpr(Rule Parent)
                : base(Parent)
            {
                this.AddNode(new RulePlusExpr(Parent));
                RuleSequence x = new RuleSequence(Parent);

                x.AddNode(new RuleRegex(m_Parent, "(\\*|/)", this));
                x.AddNode(new RulePlusExpr(Parent));
                RuleMultiple y = new RuleMultiple(Parent, 0);

                y.AddNode(x);
                this.AddNode(y);
            }
예제 #8
0
        public class RuleExpr : RuleSequence {  //multiplicative_expression (S ('+' / '-') S multiplicative_expression)*
            public RuleExpr(Rule Parent)
                : base(Parent)
            {
                m_Parent = this;
                this.AddNode(new RuleSpaceOptional(m_Parent));
                this.AddNode(new RuleMultExpr(m_Parent));
                RuleSequence x = new RuleSequence(m_Parent);

                x.AddNode(new RuleRegex(m_Parent, "(\\+|\\-)", this));
                x.AddNode(new RuleMultExpr(m_Parent));
                RuleMultiple y = new RuleMultiple(m_Parent, 0);

                y.AddNode(x);
                this.AddNode(y);
            }
예제 #9
0
        public class RuleReturn : RuleAlternative {    //  return or return(55,false)
            public RuleReturn(Rule Parent) : base(Parent)
            {
                RuleSequence x = new RuleSequence(m_Parent);

                x.AddNode(new RuleRegex(m_Parent, s_ManyWhitespace + "return" + s_ManyWhitespace, this));
                x.AddNode(new RuleEOLComment(m_Parent));
                this.AddNode(x);
                x = new RuleSequence(m_Parent);
                x.AddNode(new RuleRegex(m_Parent, s_ManyWhitespace + "return" + s_ManyWhitespace, this));
                x.AddNode(new RuleLPar(m_Parent));
                x.AddNode(new RuleParams(m_Parent));
                x.AddNode(new RuleRPar(m_Parent));
                x.AddNode(new RuleEOLComment(m_Parent));
                this.AddNode(x);
            }
예제 #10
0
        public class RuleUsing : RuleSequence {   //using STRING as NAME  or using STRING
            public RuleUsing(Rule Parent)
                : base(Parent)
            {
                m_Parent = this;
                this.AddNode(new RuleRegex(m_Parent, s_ManyWhitespace + "using" + s_ManyWhitespace, this));
                this.AddNode(new RuleString(m_Parent));

                RuleSequence x = new RuleSequence(m_Parent);

                x.AddNode(new RuleRegex(m_Parent, s_ManyWhitespace + "as" + s_ManyWhitespace, this));
                x.AddNode(new RuleName(m_Parent));

                RuleOption y = new RuleOption(m_Parent);

                y.AddNode(x);
                this.AddNode(y);
                this.AddNode(new RuleEOLComment(m_Parent));
            }
예제 #11
0
        public class RuleReturns : RuleSequence {   //-> NAME (, NAME)*
            public RuleReturns(Rule Parent)
                : base(Parent)
            {
                RuleSequence u = new RuleSequence(this);

                u.AddNode(new RuleName(this));

                this.AddNode(new RuleRegex(this, "->" + s_ManyWhitespace, this));
                this.AddNode(u);
                RuleSequence x = new RuleSequence(this);

                x.AddNode(new RuleSeparator(this));
                x.AddNode(u);
                RuleMultiple y = new RuleMultiple(this, 0);

                y.AddNode(x);
                this.AddNode(y);
            }
예제 #12
0
        public class RuleParamDecl : RuleMultiple {  // BASETYPE S NAME S (, BASETYPE S NAME S )*
            public RuleParamDecl(Rule Parent)
                : base(Parent, 0)
            {
                RuleSequence z = new RuleSequence(this);

                z.AddNode(new RuleBaseType(this));
                z.AddNode(new RuleSpace(this));
                z.AddNode(new RuleName(this));
                RuleSequence x = new RuleSequence(this);

                x.AddNode(new RuleSeparator(this));
                x.AddNode(z);
                RuleMultiple y = new RuleMultiple(this, 0);

                y.AddNode(x);
                RuleSequence w = new RuleSequence(this);

                w.AddNode(z);
                w.AddNode(y);
                this.AddNode(w);
            }
예제 #13
0
파일: Day19.cs 프로젝트: nicozink/AOC2020
            /// <summary>
            /// Consumes a sequence of rules. This is done recursively, so
            /// that we get all combinations of rules.
            /// </summary>
            /// <param name="message">The message.</param>
            /// <param name="rule">The rule.</param>
            /// <param name="ruleIndex">The index of the current rule to ckeck.</param>
            /// <param name="position">The current position in the message.</param>
            /// <returns>The new positions.</returns>
            private IEnumerable <int> ConsumeRule(string message, RuleSequence rule, int ruleIndex, int position)
            {
                // We exit if we've read each part of the rule.
                if (ruleIndex == rule.Nodes.Count)
                {
                    yield return(position);

                    yield break;
                }

                // We read the first token, and get all valid positions once the first token has
                // been read.
                foreach (var firstPosition in ConsumeRule(message, rule.Nodes[ruleIndex], position))
                {
                    // We then call this function recursively, to read the next token.
                    foreach (var secondPosition in ConsumeRule(message, rule, ruleIndex + 1, firstPosition))
                    {
                        yield return(secondPosition);
                    }
                }
            }
예제 #14
0
        public class RuleIf : RuleSequence { //'if' S* '(' EXPRESSION ')' (COMMENT | EOL) BODY ('else' (COMMENT | EOL) BODY)?
            public RuleIf(Rule Parent)
                : base(Parent)
            {
                m_Parent = this;
                this.AddNode(new RuleRegex(m_Parent, s_ManyWhitespace + "\\bif\\b" + s_ManyWhitespace, this));
                this.AddNode(new RuleLPar(m_Parent));
                this.AddNode(new RuleBoolExpr(m_Parent));
                this.AddNode(new RuleRPar(m_Parent));
                this.AddNode(new RuleEOLComment(m_Parent));
                this.AddNode(new RuleLCurlPar(m_Parent));
                this.AddNode(new RuleBody(m_Parent));
                this.AddNode(new RuleRCurlPar(m_Parent));
                RuleOption   y = new RuleOption(m_Parent);
                RuleSequence x = new RuleSequence(m_Parent);

                x.AddNode(new RuleRegex(m_Parent, s_ManyWhitespace + "\\belse\\b" + s_ManyWhitespace, this));
                x.AddNode(new RuleEOLComment(m_Parent));
                x.AddNode(new RuleLCurlPar(m_Parent));
                x.AddNode(new RuleBody(m_Parent));
                x.AddNode(new RuleRCurlPar(m_Parent));
                y.AddNode(x);
                this.AddNode(y);
            }
예제 #15
0
            public RuleDecl(Rule Parent) : base(Parent)
            {
                m_Parent = this;
                this.AddNode(new RuleSpaceOptional(m_Parent));
                this.AddNode(new RuleBaseType(m_Parent));
                this.AddNode(new RuleSpace(m_Parent));
                this.AddNode(new RuleName(m_Parent));
                RuleSequence z = new RuleSequence(m_Parent);

                z.AddNode(new RuleRegex(m_Parent, s_ManyWhitespace + "=" + s_ManyWhitespace, this));
                RuleAlternative x = new RuleAlternative(m_Parent);

                x.AddNode(new RuleString(m_Parent));
                x.AddNode(new RuleBool(m_Parent));
                x.AddNode(new RuleName(m_Parent));
                x.AddNode(new RuleExpr(m_Parent));
                z.AddNode(x);
                RuleOption y = new RuleOption(m_Parent);

                y.AddNode(z);
                this.AddNode(y);
                this.AddNode(new RuleEOLComment(m_Parent));
            }
예제 #16
0
        public class RuleNameInstance : RuleAlternative {     // Station. but also Station[X].   Station["5"].  Station[5].
            public RuleNameInstance(Rule Parent) : base(Parent)
            {
                RuleAlternative x = new RuleAlternative(m_Parent);

                x.AddNode(new RuleName(m_Parent));
                x.AddNode(new RuleNumber(m_Parent));
                x.AddNode(new RuleString(m_Parent));

                RuleSequence y = new RuleSequence(m_Parent);

                y.AddNode(new RuleSpaceOptional(m_Parent));
                y.AddNode(new RuleName(m_Parent));
                y.AddNode(new RuleRegex(m_Parent, "\\[", this));
                y.AddNode(x);
                y.AddNode(new RuleRegex(m_Parent, "\\]", this));
                y.AddNode(new RuleRegex(m_Parent, "\\.", this));
                this.AddNode(y);

                y = new RuleSequence(m_Parent);
                y.AddNode(new RuleSpaceOptional(m_Parent));
                y.AddNode(new RuleName(m_Parent));
                y.AddNode(new RuleRegex(m_Parent, "\\.", this));
                this.AddNode(y);
            }