Source code: org/sablecc/sablecc/AcceptStates.java
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * This file is part of SableCC. *
3 * See the file "LICENSE" for copyright information and the *
4 * terms and conditions for copying, distribution and *
5 * modification of SableCC. *
6 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
7
8 package org.sablecc.sablecc;
9
10 import org.sablecc.sablecc.analysis.*;
11 import org.sablecc.sablecc.node.*;
12 import java.util.*;
13 import com.sun.java.util.collections.*;
14
15 public class AcceptStates extends DepthFirstAdapter
16 {
17 public DFA dfa;
18 public String stateName;
19 private ResolveIds ids;
20
21 public AcceptStates(DFA dfa, ResolveIds ids, String stateName)
22 {
23 this.dfa = dfa;
24 this.ids = ids;
25 this.stateName = stateName;
26 }
27
28 public void caseStart1(Start1 node)
29 {
30 for(int i = 0; i < dfa.states.size(); i++)
31 {
32 DFA.State state = (DFA.State) dfa.states.get(i);
33 state.accept = -1;
34
35 int accept = -1;
36
37 for(int k = 0; k < state.nfaStates.size(); k++)
38 {
39 if(state.nfaStates.get(k))
40 {
41 if(dfa.nfa.states[k].accept != null)
42 {
43 if(accept == -1)
44 {
45 accept = ids.tokenList.indexOf(dfa.nfa.states[k].accept);
46 }
47 else
48 {
49 accept = Math.min(
50 ids.tokenList.indexOf(dfa.nfa.states[k].accept),
51 accept);
52 }
53 }
54 }
55 }
56
57 state.accept = accept;
58 }
59 }
60 }