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

« back to all changes in this revision

Viewing changes to src/java_cup/runtime/Symbol.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
package java_cup.runtime;
 
2
 
 
3
/**
 
4
 * Defines the Symbol class, which is used to represent all terminals
 
5
 * and nonterminals while parsing.  The lexer should pass CUP Symbols 
 
6
 * and CUP returns a Symbol.
 
7
 *
 
8
 * @version last updated: 7/3/96
 
9
 * @author  Frank Flannery
 
10
 */
 
11
 
 
12
/* ****************************************************************
 
13
  Class Symbol
 
14
  what the parser expects to receive from the lexer. 
 
15
  the token is identified as follows:
 
16
  sym:    the symbol type
 
17
  parse_state: the parse state.
 
18
  value:  is the lexical value of type Object
 
19
  left :  is the left position in the original input file
 
20
  right:  is the right position in the original input file
 
21
******************************************************************/
 
22
 
 
23
public class Symbol {
 
24
 
 
25
/*******************************
 
26
  Constructor for l,r values
 
27
 *******************************/
 
28
 
 
29
  public Symbol(int id, int l, int r, Object o) {
 
30
    this(id);
 
31
    left = l;
 
32
    right = r;
 
33
    value = o;
 
34
  }
 
35
 
 
36
/*******************************
 
37
  Constructor for no l,r values
 
38
********************************/
 
39
 
 
40
  public Symbol(int id, Object o) {
 
41
    this(id, -1, -1, o);
 
42
  }
 
43
 
 
44
/*****************************
 
45
  Constructor for no value
 
46
  ***************************/
 
47
 
 
48
  public Symbol(int id, int l, int r) {
 
49
    this(id, l, r, null);
 
50
  }
 
51
 
 
52
/***********************************
 
53
  Constructor for no value or l,r
 
54
***********************************/
 
55
 
 
56
  public Symbol(int sym_num) {
 
57
    this(sym_num, -1);
 
58
    left = -1;
 
59
    right = -1;
 
60
    value = null;
 
61
  }
 
62
 
 
63
/***********************************
 
64
  Constructor to give a start state
 
65
***********************************/
 
66
  Symbol(int sym_num, int state)
 
67
    {
 
68
      sym = sym_num;
 
69
      parse_state = state;
 
70
    }
 
71
 
 
72
/*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
 
73
 
 
74
  /** The symbol number of the terminal or non terminal being represented */
 
75
  public int sym;
 
76
 
 
77
  /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
 
78
 
 
79
  /** The parse state to be recorded on the parse stack with this symbol.
 
80
   *  This field is for the convenience of the parser and shouldn't be 
 
81
   *  modified except by the parser. 
 
82
   */
 
83
  public int parse_state;
 
84
  /** This allows us to catch some errors caused by scanners recycling
 
85
   *  symbols.  For the use of the parser only. [CSA, 23-Jul-1999] */
 
86
  boolean used_by_parser = false;
 
87
 
 
88
/*******************************
 
89
  The data passed to parser
 
90
 *******************************/
 
91
 
 
92
  public int left, right;
 
93
  public Object value;
 
94
 
 
95
  /*****************************
 
96
    Printing this token out. (Override for pretty-print).
 
97
    ****************************/
 
98
  public String toString() { return "#"+sym; }
 
99
}
 
100
 
 
101
 
 
102
 
 
103
 
 
104
 
 
105