Esempio n. 1
0
 public override ATNConfigSet Clone(bool @readonly)
 {
     Antlr4.Runtime.Atn.OrderedATNConfigSet copy = new Antlr4.Runtime.Atn.OrderedATNConfigSet(this, @readonly);
     if (!@readonly && this.IsReadOnly)
     {
         copy.AddAll(this);
     }
     return copy;
 }
Esempio n. 2
0
 public override ATNConfigSet Clone(bool @readonly)
 {
     Antlr4.Runtime.Atn.OrderedATNConfigSet copy = new Antlr4.Runtime.Atn.OrderedATNConfigSet(this, @readonly);
     if (!@readonly && this.IsReadOnly)
     {
         copy.AddAll(this);
     }
     return(copy);
 }
Esempio n. 3
0
        protected ATNConfigSet ComputeStartState(ICharStream input,
                                                 ATNState p)
        {
            PredictionContext initialContext = PredictionContext.EMPTY;
            ATNConfigSet      configs        = new OrderedATNConfigSet();

            for (int i = 0; i < p.NumberOfTransitions; i++)
            {
                ATNState       target = p.Transition(i).target;
                LexerATNConfig c      = new LexerATNConfig(target, i + 1, initialContext);
                Closure(input, c, configs, false, false, false);
            }
            return(configs);
        }
Esempio n. 4
0
        protected internal virtual ATNConfigSet ComputeStartState([NotNull] ICharStream input, [NotNull] ATNState p)
        {
            PredictionContext initialContext = PredictionContext.EmptyFull;

            ATNConfigSet configs = new OrderedATNConfigSet();

            for (int i = 0; i < p.NumberOfTransitions; i++)
            {
                ATNState  target = p.Transition(i).target;
                ATNConfig c      = ATNConfig.Create(target, i + 1, initialContext);
                Closure(input, c, configs, false, false, false);
            }
            return(configs);
        }
Esempio n. 5
0
        protected internal virtual DFAState ComputeTargetState(ICharStream input, DFAState
                                                               s, int t)
        {
            ATNConfigSet reach = new OrderedATNConfigSet();

            // if we don't find an existing DFA state
            // Fill reach starting from closure, following t transitions
            GetReachableConfigSet(input, s.configs, reach, t);
            if (reach.IsEmpty())
            {
                // we got nowhere on t from s
                // we got nowhere on t, don't throw out this knowledge; it'd
                // cause a failover from DFA later.
                AddDFAEdge(s, t, Error);
                // stop when we can't match any more char
                return(Error);
            }
            // Add an edge from s to target DFA found/created for reach
            return(AddDFAEdge(s, t, reach));
        }
Esempio n. 6
0
 protected internal virtual ATNConfigSet ComputeStartState(ICharStream input, ATNState
      p)
 {
     PredictionContext initialContext = PredictionContext.EmptyFull;
     ATNConfigSet configs = new OrderedATNConfigSet();
     for (int i = 0; i < p.NumberOfTransitions; i++)
     {
         ATNState target = p.Transition(i).target;
         ATNConfig c = ATNConfig.Create(target, i + 1, initialContext);
         Closure(input, c, configs, false);
     }
     return configs;
 }
Esempio n. 7
0
 protected internal virtual DFAState ComputeTargetState(ICharStream input, DFAState
      s, int t)
 {
     ATNConfigSet reach = new OrderedATNConfigSet();
     // if we don't find an existing DFA state
     // Fill reach starting from closure, following t transitions
     GetReachableConfigSet(input, s.configs, reach, t);
     if (reach.IsEmpty())
     {
         // we got nowhere on t from s
         // we got nowhere on t, don't throw out this knowledge; it'd
         // cause a failover from DFA later.
         AddDFAEdge(s, t, Error);
         // stop when we can't match any more char
         return Error;
     }
     // Add an edge from s to target DFA found/created for reach
     return AddDFAEdge(s, t, reach);
 }
Esempio n. 8
0
        protected ATNConfigSet ComputeStartState(ICharStream input,
												 ATNState p)
        {
            PredictionContext initialContext = PredictionContext.EMPTY;
            ATNConfigSet configs = new OrderedATNConfigSet();
            for (int i = 0; i < p.NumberOfTransitions; i++)
            {
                ATNState target = p.Transition(i).target;
                LexerATNConfig c = new LexerATNConfig(target, i + 1, initialContext);
                Closure(input, c, configs, false, false, false);
            }
            return configs;
        }
        protected internal virtual int ExecATN(ICharStream input, DFAState ds0)
        {
            //System.out.println("enter exec index "+input.index()+" from "+ds0.configs);
            int t = input.La(1);
            DFAState s = ds0;
            // s is current/from DFA state
            while (true)
            {
                // while more work
                // As we move src->trg, src->trg, we keep track of the previous trg to
                // avoid looking up the DFA state again, which is expensive.
                // If the previous target was already part of the DFA, we might
                // be able to avoid doing a reach operation upon t. If s!=null,
                // it means that semantic predicates didn't prevent us from
                // creating a DFA state. Once we know s!=null, we check to see if
                // the DFA state has an edge already for t. If so, we can just reuse
                // it's configuration set; there's no point in re-computing it.
                // This is kind of like doing DFA simulation within the ATN
                // simulation because DFA simulation is really just a way to avoid
                // computing reach/closure sets. Technically, once we know that
                // we have a previously added DFA state, we could jump over to
                // the DFA simulator. But, that would mean popping back and forth
                // a lot and making things more complicated algorithmically.
                // This optimization makes a lot of sense for loops within DFA.
                // A character will take us back to an existing DFA state
                // that already has lots of edges out of it. e.g., .* in comments.
                ATNConfigSet closure = s.configs;
                DFAState target = null;
                target = s.GetTarget(t);
                if (target == Error)
                {
                    break;
                }
#if !PORTABLE
                if (debug && target != null)
                {
                    System.Console.Out.WriteLine("reuse state " + s.stateNumber + " edge to " + target
                        .stateNumber);
                }
#endif
                if (target == null)
                {
                    ATNConfigSet reach = new OrderedATNConfigSet();
                    // if we don't find an existing DFA state
                    // Fill reach starting from closure, following t transitions
                    GetReachableConfigSet(input, closure, reach, t);
                    if (reach.Count == 0)
                    {
                        // we got nowhere on t from s
                        // we reached state associated with closure for sure, so
                        // make sure it's defined. worst case, we define s0 from
                        // start state configs.
                        DFAState from = s != null ? s : AddDFAState(closure);
                        // we got nowhere on t, don't throw out this knowledge; it'd
                        // cause a failover from DFA later.
                        AddDFAEdge(from, t, Error);
                        break;
                    }
                    // stop when we can't match any more char
                    // Add an edge from s to target DFA found/created for reach
                    target = AddDFAEdge(s, t, reach);
                }
                if (target.isAcceptState)
                {
                    CaptureSimState(prevAccept, input, target);
                    if (t == IntStreamConstants.Eof)
                    {
                        break;
                    }
                }
                if (t != IntStreamConstants.Eof)
                {
                    Consume(input);
                    t = input.La(1);
                }
                s = target;
            }
            // flip; current DFA target becomes new src/from state
            return FailOrAccept(prevAccept, input, s.configs, t);
        }