1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3
* Copyright (C) 1998-2001 Gerwin Klein <lsf@jflex.de> *
4
* All rights reserved. *
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. *
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. *
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 *
19
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
26
* Stores all rules of the specification for later access in RegExp -> NFA
28
* @author Gerwin Klein
29
* @version JFlex 1.3.5, $Revision: 1.19 $, $Date: 2001/10/08 10:08:05 $
31
public class RegExps {
33
/** the spec line in which a regexp is used */
34
Vector /* of Integer */ lines;
36
/** the lexical states in wich the regexp is used */
37
Vector /* of Vector of Integer */ states;
40
Vector /* of RegExp */ regExps;
42
/** the action of a regexp */
43
Vector /* of Action */ actions;
45
/** flag if it is a BOL regexp */
46
Vector /* of Boolean */ BOL;
48
/** the lookahead expression */
49
Vector /* of RegExp */ look;
52
states = new Vector();
53
regExps = new Vector();
54
actions = new Vector();
60
public int insert(int line, Vector stateList, RegExp regExp, Action action,
61
Boolean isBOL, RegExp lookAhead) {
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);
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));
75
return states.size()-1;
78
public int insert(Vector stateList, Action action) {
81
Out.debug("Inserting eofrule with statelist :"+Out.NL+stateList);
82
Out.debug("and action code :"+Out.NL+action.content+Out.NL);
85
states.addElement(stateList);
86
regExps.addElement(null);
87
actions.addElement(action);
89
look.addElement(null);
90
lines.addElement(null);
92
return states.size()-1;
95
public void addStates(int regNum, Vector newStates) {
96
Enumeration s = newStates.elements();
98
while (s.hasMoreElements())
99
((Vector)states.elementAt(regNum)).addElement(s.nextElement());
102
public int getNum() {
103
return states.size();
106
public boolean isBOL(int num) {
107
return ((Boolean) BOL.elementAt(num)).booleanValue();
110
public RegExp getLookAhead(int num) {
111
return (RegExp) look.elementAt(num);
114
public boolean isEOF(int num) {
115
return BOL.elementAt(num) == null;
118
public Vector getStates(int num) {
119
return (Vector) states.elementAt(num);
122
public RegExp getRegExp(int num) {
123
return (RegExp) regExps.elementAt(num);
126
public int getLine(int num) {
127
return ((Integer) lines.elementAt(num)).intValue();
130
public void checkActions() {
131
if ( actions.elementAt(actions.size()-1) == null ) {
132
Out.error(ErrorMessages.NO_LAST_ACTION);
133
throw new GeneratorException();
137
public Action getAction(int num) {
138
while ( num < actions.size() && actions.elementAt(num) == null )
141
return (Action) actions.elementAt(num);