Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 2 package java_cup; 3 4 import java.util.Enumeration ; 5 6 16 public class parse_action_table { 17 18 19 20 21 22 26 public parse_action_table() 27 { 28 29 _num_states = lalr_state.number(); 30 31 32 under_state = new parse_action_row[_num_states]; 33 for (int i=0; i<_num_states; i++) 34 under_state[i] = new parse_action_row(); 35 } 36 37 38 39 40 41 42 protected int _num_states; 43 44 45 public int num_states() {return _num_states;} 46 47 48 49 50 public parse_action_row[] under_state; 51 52 53 54 55 56 60 public void check_reductions() 61 throws internal_error 62 { 63 parse_action act; 64 production prod; 65 66 67 for (int row = 0; row < num_states(); row++) 68 { 69 for (int col = 0; col < parse_action_row.size(); col++) 70 { 71 72 act = under_state[row].under_term[col]; 73 if (act != null && act.kind() == parse_action.REDUCE) 74 { 75 76 ((reduce_action)act).reduce_with().note_reduction_use(); 77 } 78 } 79 } 80 81 82 for (Enumeration p = production.all(); p.hasMoreElements(); ) 83 { 84 prod = (production)p.nextElement(); 85 86 87 if (prod.num_reductions() == 0) 88 { 89 93 if (!emit.nowarn) 94 { 95 96 ErrorManager.getManager().emit_warning("*** Production \"" + 97 prod.to_simple_string() + "\" never reduced"); 98 } 99 } 100 } 101 } 102 103 106 public String toString() 107 { 108 String result; 109 int cnt; 110 111 result = "-------- ACTION_TABLE --------\n"; 112 for (int row = 0; row < num_states(); row++) 113 { 114 result += "From state #" + row + "\n"; 115 cnt = 0; 116 for (int col = 0; col < parse_action_row.size(); col++) 117 { 118 119 if (under_state[row].under_term[col].kind() != parse_action.ERROR) 120 { 121 result += " [term " + col + ":" + under_state[row].under_term[col] + "]"; 122 123 124 cnt++; 125 if (cnt == 2) 126 { 127 result += "\n"; 128 cnt = 0; 129 } 130 } 131 } 132 133 if (cnt != 0) result += "\n"; 134 } 135 result += "------------------------------"; 136 137 return result; 138 } 139 140 141 142 } 143 144
| Popular Tags
|