예제 #1
0
        public override IDerivation Visit(Terminal aSymbol, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aSymbol.Parent = context.Parent;
            return(null);
        }
예제 #2
0
 public CyclesDetectContext(CyclesDetectContext aCyclesDetectContext)
     : base(aCyclesDetectContext.Grammar)
 {
     NotTerminals = new Dictionary <string, NonTerminal>(aCyclesDetectContext.NotTerminals);
     Visitor      = aCyclesDetectContext.Visitor;
     //BuildingGraph = aCyclesDetectContext.BuildingGraph;
 }
예제 #3
0
        protected override DerivationContext NewContext(IPhrase aPhrase, DerivationContext aContext)
        {
            CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);

            newContext.Parent = aPhrase;
            return(newContext);
        }
예제 #4
0
        public override IDerivation Visit(IPhrase aPhr, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aPhr.Parent = context.Parent;
            CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);

            newContext.Parent = aPhr;
            return(base.Visit(aPhr, newContext));
        }
예제 #5
0
        public override IDerivation Visit(PlaceHolderPhrase aPlaceHolderPhrase, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aPlaceHolderPhrase.Parent = context.Parent;
            CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);

            newContext.Parent = aPlaceHolderPhrase;
            return(base.Visit(aPlaceHolderPhrase, newContext));
        }
예제 #6
0
        public override IDerivation Visit(TransCallPhrase aTransCallPhrase, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aTransCallPhrase.Parent = context.Parent;
            CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);

            newContext.Parent = aTransCallPhrase;
            return(base.Visit(aTransCallPhrase, newContext));
        }
예제 #7
0
        public override IDerivation Visit(QuantifiedPhrase aQuantifiedPhrase, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aQuantifiedPhrase.Parent = context.Parent;
            CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);

            newContext.Parent = aQuantifiedPhrase;
            return(base.Visit(aQuantifiedPhrase, newContext));
        }
예제 #8
0
        public override IDerivation Visit(ExprOp aExprOp, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aExprOp.Parent = context.Parent;
            CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);

            newContext.Parent = aExprOp;
            return(base.Visit(aExprOp, newContext));
        }
예제 #9
0
        public override IDerivation Visit(AccessArray aAccessArray, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aAccessArray.Parent = context.Parent;
            CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);

            newContext.Parent = aAccessArray;
            return(base.Visit(aAccessArray, newContext));
        }
예제 #10
0
        public override IDerivation Visit(NonTerminal aSymbol, DerivationContext aContext)
        {
            CyclesDetectContext context = aContext as CyclesDetectContext;

            aSymbol.Parent = context.Parent;
            if (context.NotTerminals.ContainsKey(aSymbol.Text))
            {
                aSymbol.CycicKind         = CycicKind.CyclicOrigin;
                aSymbol.CyclicToOccurence = context.NotTerminals[aSymbol.Text].CounterName;
                aSymbol.PropagateCycle();
                //aContext.Grammar.AllCyclicSymbolOccurs.Add(aSymbol);
            }
            else
            {
                bool isAlreadyUsed = mAlreadyUsedSymbols.Contains(aSymbol.Text);
                mAlreadyUsedSymbols.Add(aSymbol.Text);

                if (!isAlreadyUsed)
                {
                    // Add current symbol to derivation path so that we can track cycles
                    (aContext as CyclesDetectContext).NotTerminals.Add(aSymbol.Text, aSymbol);
                    //взали правило
                    Rule lRule = aSymbol.FindItsRule();

                    //Раскрываем правую часть правила
                    CyclesDetectContext newContext = new CyclesDetectContext(aContext as CyclesDetectContext);
                    newContext.Parent = aSymbol;
                    lRule.Expand(newContext);
                }
                else
                {
                    aSymbol.CycicKind |= CycicKind.SkippedAsSeen;
                }
            }
            return(null);
        }