~ubuntu-branches/ubuntu/gutsy/jflex/gutsy

« back to all changes in this revision

Viewing changes to src/JFlex/RegExps.java

  • Committer: Bazaar Package Importer
  • Author(s): Takashi Okamoto
  • Date: 2002-02-16 13:38:21 UTC
  • Revision ID: james.westby@ubuntu.com-20020216133821-5wsdprpt9xl7ondr
Tags: upstream-1.3.5
ImportĀ upstreamĀ versionĀ 1.3.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 
2
 * JFlex 1.3.5                                                             *
 
3
 * Copyright (C) 1998-2001  Gerwin Klein <lsf@jflex.de>                    *
 
4
 * All rights reserved.                                                    *
 
5
 *                                                                         *
 
6
 * This program is free software; you can redistribute it and/or modify    *
 
7
 * it under the terms of the GNU General Public License. See the file      *
 
8
 * COPYRIGHT for more information.                                         *
 
9
 *                                                                         *
 
10
 * This program is distributed in the hope that it will be useful,         *
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of          *
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the           *
 
13
 * GNU General Public License for more details.                            *
 
14
 *                                                                         *
 
15
 * You should have received a copy of the GNU General Public License along *
 
16
 * with this program; if not, write to the Free Software Foundation, Inc., *
 
17
 * 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                 *
 
18
 *                                                                         *
 
19
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
 
20
package JFlex;
 
21
 
 
22
import java.util.*;
 
23
 
 
24
 
 
25
/**
 
26
 * Stores all rules of the specification for later access in RegExp -> NFA
 
27
 *
 
28
 * @author Gerwin Klein
 
29
 * @version JFlex 1.3.5, $Revision: 1.19 $, $Date: 2001/10/08 10:08:05 $
 
30
 */
 
31
public class RegExps {
 
32
  
 
33
  /** the spec line in which a regexp is used */
 
34
  Vector /* of Integer */ lines;
 
35
 
 
36
  /** the lexical states in wich the regexp is used */
 
37
  Vector /* of Vector of Integer */ states;
 
38
 
 
39
  /** the regexp */
 
40
  Vector /* of RegExp */ regExps;
 
41
 
 
42
  /** the action of a regexp */
 
43
  Vector /* of Action */ actions;
 
44
  
 
45
  /** flag if it is a BOL regexp */
 
46
  Vector /* of Boolean */ BOL;
 
47
 
 
48
  /** the lookahead expression */
 
49
  Vector /* of RegExp */ look;
 
50
 
 
51
  public RegExps() {
 
52
    states = new Vector();
 
53
    regExps = new Vector();
 
54
    actions = new Vector();
 
55
    BOL = new Vector();
 
56
    look = new Vector();
 
57
    lines = new Vector();
 
58
  }
 
59
 
 
60
  public int insert(int line, Vector stateList, RegExp regExp, Action action, 
 
61
                     Boolean isBOL, RegExp lookAhead) {      
 
62
    if (Out.DEBUG) {
 
63
      Out.debug("Inserting regular expression with statelist :"+Out.NL+stateList); 
 
64
      Out.debug("and action code :"+Out.NL+action.content+Out.NL);    
 
65
      Out.debug("expression :"+Out.NL+regExp); 
 
66
    }
 
67
 
 
68
    states.addElement(stateList);
 
69
    regExps.addElement(regExp);
 
70
    actions.addElement(action);
 
71
    BOL.addElement(isBOL);
 
72
    look.addElement(lookAhead);
 
73
    lines.addElement(new Integer(line));
 
74
    
 
75
    return states.size()-1;
 
76
  }
 
77
 
 
78
  public int insert(Vector stateList, Action action) {
 
79
 
 
80
    if (Out.DEBUG) {
 
81
      Out.debug("Inserting eofrule with statelist :"+Out.NL+stateList);  
 
82
      Out.debug("and action code :"+Out.NL+action.content+Out.NL);     
 
83
    }
 
84
 
 
85
    states.addElement(stateList);
 
86
    regExps.addElement(null);
 
87
    actions.addElement(action);
 
88
    BOL.addElement(null);
 
89
    look.addElement(null);
 
90
    lines.addElement(null);
 
91
    
 
92
    return states.size()-1;
 
93
  }
 
94
 
 
95
  public void addStates(int regNum, Vector newStates) {
 
96
    Enumeration s = newStates.elements();
 
97
    
 
98
    while (s.hasMoreElements()) 
 
99
      ((Vector)states.elementAt(regNum)).addElement(s.nextElement());      
 
100
  }
 
101
 
 
102
  public int getNum() {
 
103
    return states.size();
 
104
  }
 
105
 
 
106
  public boolean isBOL(int num) {
 
107
    return ((Boolean) BOL.elementAt(num)).booleanValue();
 
108
  }
 
109
  
 
110
  public RegExp getLookAhead(int num) {
 
111
    return (RegExp) look.elementAt(num);
 
112
  }
 
113
 
 
114
  public boolean isEOF(int num) {
 
115
    return BOL.elementAt(num) == null;
 
116
  }
 
117
 
 
118
  public Vector getStates(int num) {
 
119
    return (Vector) states.elementAt(num);
 
120
  }
 
121
 
 
122
  public RegExp getRegExp(int num) {
 
123
    return (RegExp) regExps.elementAt(num);
 
124
  }
 
125
 
 
126
  public int getLine(int num) {
 
127
    return ((Integer) lines.elementAt(num)).intValue();
 
128
  }
 
129
 
 
130
  public void checkActions() {
 
131
    if ( actions.elementAt(actions.size()-1) == null ) {
 
132
      Out.error(ErrorMessages.NO_LAST_ACTION);
 
133
      throw new GeneratorException();
 
134
    }
 
135
  }
 
136
 
 
137
  public Action getAction(int num) {
 
138
    while ( num < actions.size() && actions.elementAt(num) == null )
 
139
      num++;
 
140
 
 
141
    return (Action) actions.elementAt(num);
 
142
  }
 
143
}