KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > javacc > parser > RSequence


1 /*
2  * Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
3  * California 95054, U.S.A. All rights reserved. Sun Microsystems, Inc. has
4  * intellectual property rights relating to technology embodied in the product
5  * that is described in this document. In particular, and without limitation,
6  * these intellectual property rights may include one or more of the U.S.
7  * patents listed at http://www.sun.com/patents and one or more additional
8  * patents or pending patent applications in the U.S. and in other countries.
9  * U.S. Government Rights - Commercial software. Government users are subject
10  * to the Sun Microsystems, Inc. standard license agreement and applicable
11  * provisions of the FAR and its supplements. Use is subject to license terms.
12  * Sun, Sun Microsystems, the Sun logo and Java are trademarks or registered
13  * trademarks of Sun Microsystems, Inc. in the U.S. and other countries. This
14  * product is covered and controlled by U.S. Export Control laws and may be
15  * subject to the export or import laws in other countries. Nuclear, missile,
16  * chemical biological weapons or nuclear maritime end uses or end users,
17  * whether direct or indirect, are strictly prohibited. Export or reexport
18  * to countries subject to U.S. embargo or to entities identified on U.S.
19  * export exclusion lists, including, but not limited to, the denied persons
20  * and specially designated nationals lists is strictly prohibited.
21  */

22
23 package org.javacc.parser;
24
25 import java.util.*;
26
27 /**
28  * Describes regular expressions which are sequences of
29  * other regular expressions.
30  */

31
32 public class RSequence extends RegularExpression {
33
34   /**
35    * The list of units in this regular expression sequence. Each
36    * Vector component will narrow to RegularExpression.
37    */

38   public java.util.Vector JavaDoc units = new java.util.Vector JavaDoc();
39
40   public Nfa GenerateNfa(boolean ignoreCase)
41   {
42      if (units.size() == 1)
43         return ((RegularExpression)units.elementAt(0)).GenerateNfa(ignoreCase);
44
45      Nfa retVal = new Nfa();
46      NfaState startState = retVal.start;
47      NfaState finalState = retVal.end;
48      Nfa temp1;
49      Nfa temp2 = null;
50
51      RegularExpression curRE;
52
53      curRE = (RegularExpression)units.elementAt(0);
54      temp1 = curRE.GenerateNfa(ignoreCase);
55      startState.AddMove(temp1.start);
56
57      for (int i = 1; i < units.size(); i++)
58      {
59         curRE = (RegularExpression)units.elementAt(i);
60
61         temp2 = curRE.GenerateNfa(ignoreCase);
62         temp1.end.AddMove(temp2.start);
63         temp1 = temp2;
64      }
65
66      temp2.end.AddMove(finalState);
67
68      return retVal;
69   }
70
71   RSequence()
72   {
73   }
74
75   RSequence(Vector seq)
76   {
77      ordinal = Integer.MAX_VALUE;
78      units = seq;
79   }
80 }
81
Popular Tags