Esempio n. 1
0
 private void VisitAlternativesWSequential(ParserNode.Alternatives alternatives)
 {
     if (_currState.PrevNode == alternatives.Parent)
     {
         _currState = _currState.EnterNode(alternatives.Childs[0]);
     }
     else if (_currState.PrevNode.Parent == alternatives)
     {
         if (_currState.LastTerminalFailed == false)
         {
             _currState = _currState.ExitNode();
         }
         else
         {
             var nextIndex = _currState.PrevNode.IndexInParentList + 1;
             if (nextIndex < alternatives.Childs.Count)
             {
                 _currState = _currState.EnterNode(alternatives.Childs[nextIndex]);
             }
             else
             {
                 _currState = _currState.ExitNode(true);
             }
         }
     }
     else
     {
         throw new InvalidOperationException();
     }
 }
Esempio n. 2
0
 void IParserNodeVisitor.VisitAlternatives(ParserNode.Alternatives alternatives)
 {
     if (_useDelayedStates)
     {
         this.VisitAlternativesWDelayed(alternatives);
     }
     else
     {
         this.VisitAlternativesWSequential(alternatives);
     }
 }
Esempio n. 3
0
        private void VisitAlternativesWDelayed(ParserNode.Alternatives alternatives)
        {
            if (_currState.PrevNode == alternatives.Parent)
            {
                for (int i = alternatives.Childs.Count - 1; i > 0; i--)
                {
                    _delayedStates.Push(_currState.Clone().EnterNode(alternatives.Childs[i]));
                }

                _currState = _currState.EnterNode(alternatives.Childs[0]);

                //for (int i = 0; i < alternatives.Childs.Count - 1; i++)
                //{
                //    _delayedStates.Push(_currState.Clone().EnterNode(alternatives.Childs[i]));
                //}

                //_currState = _currState.EnterNode(alternatives.Childs[alternatives.Childs.Count - 1]);
            }
            else if (_currState.PrevNode.Parent == alternatives)
            {
                if (_currState.LastTerminalFailed == true)
                {
                    if (_owner.EnableLog)
                    {
                        System.IO.File.WriteAllText(_fname + (_fcount++).ToString().PadLeft(4, '0') + ".txt", _currState.GetLogSnapshot());
                    }

                    if (_rrr == null)
                    {
                        _rrr = _currState;
                    }
                    else if (_rrr.Location < _currState.Location)
                    {
                        _rrr = _currState;
                    }

                    _currState = _delayedStates.Pop();
                }
                else
                {
                    _currState = _currState.ExitNode();
                }
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Esempio n. 4
0
        private void WrapChilds(RuleAlternativeInfo info)
        {
            var lst = new List <ParsingTreeNode.ParsedNode>();

            for (var n = _currChild; n != null; n = n.Next)
            {
                lst.Add(n);
            }

            var callExpressions    = info.AlternativesInfo.Alternatives.Select(a => new { alternative = a, expr = new RuleExpression.RuleUsage(a.Rule.Name) }).ToArray();
            var parentAlternatives = new ParserNode.Alternatives(
                info.RootRule,
                new RuleExpression.Or(callExpressions.Select(a => a.expr).ToArray()),
                callExpressions.Select(a => new ParserNode.RuleCall(a.alternative.Rule, a.expr, new ParserNode.FsmParserNode(null, null, null))).ToArray()
                );
            var parentCall = new ParserNode.RuleCall(_currChild.Rule, new RuleExpression.RuleUsage(info.RootRule.Name), parentAlternatives);

            ParsingTreeNode.ParsedNode next = null;
            for (int i = lst.Count - 1; i >= 0; i--)
            {
                var curr = lst[i];
                if (i % 2 != 0)
                {
                    next = new ParsingTreeNode.Group(curr.GrammarNode.Parent, curr.Location, next,
                                                     curr.UpdateNext(null)
                                                     );
                }
                else
                {
                    next = new ParsingTreeNode.Group(parentCall, curr.Location, next,
                                                     new ParsingTreeNode.Group(parentAlternatives, curr.Location, null,
                                                                               new ParsingTreeNode.Group(new ParserNode.RuleCall(parentAlternatives.Rule, new RuleExpression.RuleUsage(curr.Rule.Name), new ParserNode.FsmParserNode(null, null, null)), curr.Location, null,
                                                                                                         curr.UpdateNext(null)
                                                                                                         )
                                                                               )
                                                     );
                }
            }

            _currChild = next;
        }
Esempio n. 5
0
 public void VisitAlternatives(ParserNode.Alternatives alternatives)
 {
     this.LogLine("{0}", alternatives); _v.VisitAlternatives(alternatives);
 }
Esempio n. 6
0
 void IParserNodeVisitor.VisitAlternatives(ParserNode.Alternatives alternatives)
 {
     this.PrintNode(alternatives);
 }