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