1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
3 * Copyright (C) 1998-2004 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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
22 import java
.util
.Enumeration
;
23 import java
.util
.Vector
;
27 * Stores all rules of the specification for later access in RegExp -> NFA
29 * @author Gerwin Klein
30 * @version JFlex 1.4.1, $Revision: 2.4 $, $Date: 2004/11/06 23:03:31 $
32 public class RegExps
{
34 /** the spec line in which a regexp is used */
35 Vector
/* of Integer */ lines
;
37 /** the lexical states in wich the regexp is used */
38 Vector
/* of Vector of Integer */ states
;
41 Vector
/* of RegExp */ regExps
;
43 /** the action of a regexp */
44 Vector
/* of Action */ actions
;
46 /** flag if it is a BOL regexp */
47 Vector
/* of Boolean */ BOL
;
49 /** the lookahead expression */
50 Vector
/* of RegExp */ look
;
53 states
= new Vector();
54 regExps
= new Vector();
55 actions
= new Vector();
61 public int insert(int line
, Vector stateList
, RegExp regExp
, Action action
,
62 Boolean isBOL
, RegExp lookAhead
) {
64 Out
.debug("Inserting regular expression with statelist :"+Out
.NL
+stateList
); //$NON-NLS-1$
65 Out
.debug("and action code :"+Out
.NL
+action
.content
+Out
.NL
); //$NON-NLS-1$
66 Out
.debug("expression :"+Out
.NL
+regExp
); //$NON-NLS-1$
69 states
.addElement(stateList
);
70 regExps
.addElement(regExp
);
71 actions
.addElement(action
);
72 BOL
.addElement(isBOL
);
73 look
.addElement(lookAhead
);
74 lines
.addElement(new Integer(line
));
76 return states
.size()-1;
79 public int insert(Vector stateList
, Action action
) {
82 Out
.debug("Inserting eofrule with statelist :"+Out
.NL
+stateList
); //$NON-NLS-1$
83 Out
.debug("and action code :"+Out
.NL
+action
.content
+Out
.NL
); //$NON-NLS-1$
86 states
.addElement(stateList
);
87 regExps
.addElement(null);
88 actions
.addElement(action
);
90 look
.addElement(null);
91 lines
.addElement(null);
93 return states
.size()-1;
96 public void addStates(int regNum
, Vector newStates
) {
97 Enumeration s
= newStates
.elements();
99 while (s
.hasMoreElements())
100 ((Vector
)states
.elementAt(regNum
)).addElement(s
.nextElement());
103 public int getNum() {
104 return states
.size();
107 public boolean isBOL(int num
) {
108 return ((Boolean
) BOL
.elementAt(num
)).booleanValue();
111 public RegExp
getLookAhead(int num
) {
112 return (RegExp
) look
.elementAt(num
);
115 public boolean isEOF(int num
) {
116 return BOL
.elementAt(num
) == null;
119 public Vector
getStates(int num
) {
120 return (Vector
) states
.elementAt(num
);
123 public RegExp
getRegExp(int num
) {
124 return (RegExp
) regExps
.elementAt(num
);
127 public int getLine(int num
) {
128 return ((Integer
) lines
.elementAt(num
)).intValue();
131 public void checkActions() {
132 if ( actions
.elementAt(actions
.size()-1) == null ) {
133 Out
.error(ErrorMessages
.NO_LAST_ACTION
);
134 throw new GeneratorException();
138 public Action
getAction(int num
) {
139 while ( num
< actions
.size() && actions
.elementAt(num
) == null )
142 return (Action
) actions
.elementAt(num
);
145 public int NFASize(Macros macros
) {
147 Enumeration e
= regExps
.elements();
148 while (e
.hasMoreElements()) {
149 RegExp r
= (RegExp
) e
.nextElement();
150 if (r
!= null) size
+= r
.size(macros
);
153 while (e
.hasMoreElements()) {
154 RegExp r
= (RegExp
) e
.nextElement();
155 if (r
!= null) size
+= r
.size(macros
);