KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > chaperon > process > LexicalAutomaton


1 /*
2  * Copyright (C) Chaperon. All rights reserved.
3  * -------------------------------------------------------------------------
4  * This software is published under the terms of the Apache Software License
5  * version 1.1, a copy of which has been included with this distribution in
6  * the LICENSE file.
7  */

8
9 package net.sourceforge.chaperon.process;
10
11 import java.io.Serializable JavaDoc;
12
13 /**
14  * The lexical automaton holds all automata for the the lexemes of a lexicon.
15  *
16  * @author <a HREF="mailto:stephan@apache.org">Stephan Michels</a>
17  * @version CVS $Id: LexicalAutomaton.java,v 1.3 2003/12/09 19:55:53 benedikta Exp $
18  */

19 public class LexicalAutomaton implements Serializable JavaDoc
20 {
21   private int lexemecount = 0;
22
23   // List of all symbols of the lexemes
24
private String JavaDoc[] symbols;
25
26   // Pattern automata for the recognition of the lexemes
27
private PatternAutomaton[] definitions;
28
29   /**
30    * Create a lexical automaton.
31    *
32    * @param lexemecount Count of lexemes.
33    */

34   public LexicalAutomaton(int lexemecount)
35   {
36     this.lexemecount = lexemecount;
37     symbols = new String JavaDoc[lexemecount];
38     definitions = new PatternAutomaton[lexemecount];
39   }
40
41   /**
42    * Sets the name of a terminal symbol.
43    *
44    * @param index Index of the lexeme.
45    * @param symbol Name of the symbol.
46    */

47   public void setLexemeSymbol(int index, String JavaDoc symbol)
48   {
49     if ((index<0) || (index>=lexemecount))
50       throw new IndexOutOfBoundsException JavaDoc();
51
52     symbols[index] = symbol;
53   }
54
55   /**
56    * Returns the name of a terminal symbol
57    *
58    * @param index Index of the lexeme.
59    *
60    * @return Name of the symbol.
61    */

62   public String JavaDoc getLexemeSymbol(int index)
63   {
64     if ((index<0) || (index>=lexemecount))
65       throw new IndexOutOfBoundsException JavaDoc();
66
67     return symbols[index];
68   }
69
70   /**
71    * Sets the pattern automaton for a lexeme
72    *
73    * @param index Index of the lexeme.
74    * @param definition Pattern automaton.
75    */

76   public void setLexemeDefinition(int index, PatternAutomaton definition)
77   {
78     if ((index<0) || (index>=lexemecount))
79       throw new IndexOutOfBoundsException JavaDoc();
80
81     definitions[index] = definition;
82   }
83
84   /**
85    * Returns the pattern automaton for a lexeme.
86    *
87    * @param index Index of the lexeme.
88    *
89    * @return Pattern automaton.
90    */

91   public PatternAutomaton getLexemeDefinition(int index)
92   {
93     if ((index<0) || (index>=lexemecount))
94       throw new IndexOutOfBoundsException JavaDoc();
95
96     return definitions[index];
97   }
98
99   /**
100    * Return the count of lexemes.
101    *
102    * @return Count of lexemes.
103    */

104   public int getLexemeCount()
105   {
106     return lexemecount;
107   }
108 }
109
Popular Tags