View Javadoc

1   //### This file created by BYACC 1.8(/Java extension  1.1)
2   //### Java capabilities added 7 Jan 97, Bob Jamison
3   //### Updated : 27 Nov 97  -- Bob Jamison, Joe Nieten
4   //###           01 Jan 98  -- Bob Jamison -- fixed generic semantic constructor
5   //###           01 Jun 99  -- Bob Jamison -- added Runnable support
6   //###           06 Aug 00  -- Bob Jamison -- made state variables class-global
7   //###           03 Jan 01  -- Bob Jamison -- improved flags, tracing
8   //###           16 May 01  -- Bob Jamison -- added custom stack sizing
9   //### Please send bug reports to rjamison@lincom-asg.com
10  //### static char yysccsid[] = "@(#)yaccpar	1.8 (Berkeley) 01/20/90";
11  
12  
13  
14  package hotsax.html.sax;
15  
16  
17  
18  //#line 13 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
19  
20  import java.io.*;
21  import java.util.*;
22  
23  
24  //#line 21 "HtmlParser.java"
25  
26  
27  
28  
29  /***
30   * Encapsulates yacc() parser functionality in a Java
31   *        class for quick code development
32   */
33  public class HtmlParser
34  {
35  
36  boolean yydebug;        //do I want debug output?
37  int yynerrs;            //number of errors so far
38  int yyerrflag;          //was there an error?
39  int yychar;             //the current working character
40  
41  //########## MESSAGES ##########
42  //###############################################################
43  // method: debug
44  //###############################################################
45  void debug(String msg)
46  {
47    if (yydebug)
48      System.out.println(msg);
49  }
50  
51  //########## STATE STACK ##########
52  final static int YYSTACKSIZE = 500;  //maximum stack size
53  int statestk[],stateptr;           //state stack
54  int stateptrmax;                     //highest index of stackptr
55  int statemax;                        //state when highest index reached
56  //###############################################################
57  // methods: state stack push,pop,drop,peek
58  //###############################################################
59  void state_push(int state)
60  {
61    if (stateptr>=YYSTACKSIZE)         //overflowed?
62      return;
63    statestk[++stateptr]=state;
64    if (stateptr>statemax)
65      {
66      statemax=state;
67      stateptrmax=stateptr;
68      }
69  }
70  int state_pop()
71  {
72    if (stateptr<0)                    //underflowed?
73      return -1;
74    return statestk[stateptr--];
75  }
76  void state_drop(int cnt)
77  {
78  int ptr;
79    ptr=stateptr-cnt;
80    if (ptr<0)
81      return;
82    stateptr = ptr;
83  }
84  int state_peek(int relative)
85  {
86  int ptr;
87    ptr=stateptr-relative;
88    if (ptr<0)
89      return -1;
90    return statestk[ptr];
91  }
92  //###############################################################
93  // method: init_stacks : allocate and prepare stacks
94  //###############################################################
95  boolean init_stacks()
96  {
97    statestk = new int[YYSTACKSIZE];
98    stateptr = -1;
99    statemax = -1;
100   stateptrmax = -1;
101   val_init();
102   return true;
103 }
104 //###############################################################
105 // method: dump_stacks : show n levels of the stacks
106 //###############################################################
107 void dump_stacks(int count)
108 {
109 int i;
110   System.out.println("=index==state====value=     s:"+stateptr+"  v:"+valptr);
111   for (i=0;i<count;i++)
112     System.out.println(" "+i+"    "+statestk[i]+"      "+valstk[i]);
113   System.out.println("======================");
114 }
115 
116 
117 //########## SEMANTIC VALUES ##########
118 //public class HtmlParserVal is defined in HtmlParserVal.java
119 
120 
121 String   yytext;//user variable to return contextual strings
122 HtmlParserVal yyval; //used to return semantic vals from action routines
123 HtmlParserVal yylval;//the 'lval' (result) I got from yylex()
124 HtmlParserVal valstk[];
125 int valptr;
126 //###############################################################
127 // methods: value stack push,pop,drop,peek.
128 //###############################################################
129 void val_init()
130 {
131   valstk=new HtmlParserVal[YYSTACKSIZE];
132   yyval=new HtmlParserVal(0);
133   yylval=new HtmlParserVal(0);
134   valptr=-1;
135 }
136 void val_push(HtmlParserVal val)
137 {
138   if (valptr>=YYSTACKSIZE)
139     return;
140   valstk[++valptr]=val;
141 }
142 HtmlParserVal val_pop()
143 {
144   if (valptr<0)
145     return new HtmlParserVal(-1);
146   return valstk[valptr--];
147 }
148 void val_drop(int cnt)
149 {
150 int ptr;
151   ptr=valptr-cnt;
152   if (ptr<0)
153     return;
154   valptr = ptr;
155 }
156 HtmlParserVal val_peek(int relative)
157 {
158 int ptr;
159   ptr=valptr-relative;
160   if (ptr<0)
161     return new HtmlParserVal(-1);
162   return valstk[ptr];
163 }
164 //#### end semantic value section ####
165 public final static short SOF=257;
166 public final static short ANGLE_OPEN=258;
167 public final static short ANGLE_CLOSE=259;
168 public final static short ANGLE_END_OPEN=260;
169 public final static short ANGLE_END_CLOSE=261;
170 public final static short ATTR=262;
171 public final static short EQUAL=263;
172 public final static short VALUE=264;
173 public final static short STRING=265;
174 public final static short TEXT=266;
175 public final static short COMMENT_START=267;
176 public final static short COMMENT_END=268;
177 public final static short NAME=269;
178 public final static short PI_OPEN=270;
179 public final static short PI_CLOSE=271;
180 public final static short DOCTYPE_START=272;
181 public final static short CDATA_START=273;
182 public final static short CDATA_END=274;
183 public final static short EOF=275;
184 public final static short YYERRCODE=256;
185 final static short yylhs[] = {                           -1,
186     0,    2,    0,    1,    1,    3,    4,    4,    4,    4,
187     4,    4,    4,   12,    7,   11,   11,   14,   16,    5,
188    15,   15,    6,   13,   13,   17,   17,   17,   17,    8,
189     8,   19,    9,   18,   18,   20,   10,
190 };
191 final static short yylen[] = {                            2,
192     0,    0,    2,    1,    2,    1,    1,    1,    1,    1,
193     1,    1,    1,    0,    4,    1,    2,    0,    0,    6,
194     1,    1,    3,    2,    0,    3,    3,    3,    1,    4,
195     3,    0,    4,    2,    0,    0,    4,
196 };
197 final static short yydefred[] = {                         0,
198     0,    0,    0,    0,   13,   14,    0,    0,   32,    0,
199     4,    6,    7,    8,    9,   10,   11,   12,   18,    0,
200     0,    0,   36,    0,    5,    0,   23,   16,    0,    0,
201    31,    0,    0,    0,    0,   19,    0,   17,   15,   30,
202    37,   34,   33,    0,    0,   24,   26,   28,   27,   21,
203    22,   20,
204 };
205 final static short yydgoto[] = {                          1,
206    10,    2,   11,   12,   13,   14,   15,   16,   17,   18,
207    29,   21,   36,   26,   52,   45,   37,   34,   24,   32,
208 };
209 final static short yysindex[] = {                         0,
210     0, -258, -265, -262,    0,    0, -259, -247,    0, -258,
211     0,    0,    0,    0,    0,    0,    0,    0,    0, -241,
212  -239, -260,    0, -238,    0, -240,    0,    0, -246, -237,
213     0, -229, -238, -243, -231,    0, -240,    0,    0,    0,
214     0,    0,    0, -248, -236,    0,    0,    0,    0,    0,
215     0,    0,
216 };
217 final static short yyrindex[] = {                         1,
218     0,    0,    0,    0,    0,    0,    0,    0,    0,   33,
219     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
220     0,    0,    0, -234,    0, -235,    0,    0,    0,    0,
221     0,    0, -234,    0, -256,    0, -235,    0,    0,    0,
222     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
223     0,    0,
224 };
225 final static short yygindex[] = {                         0,
226     0,    0,   25,    0,    0,    0,    0,    0,    0,    0,
227     0,    0,   -1,    0,    0,    0,    0,    4,    0,    0,
228 };
229 final static int YYTABLESIZE=274;
230 final static short yytable[] = {                          3,
231     1,    4,   29,   19,   29,   30,   20,    5,    6,   22,
232    31,    7,   29,    8,    9,   47,   48,   27,   23,   38,
233    49,   39,   50,   25,   51,   25,   28,   33,   35,   41,
234    43,   44,    3,   40,   25,   46,   42,    0,    0,   35,
235     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
236     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
237     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
238     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
239     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
240     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
241     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
242     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
243     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
244     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
245     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
246     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
247     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
248     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
249     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
250     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
251     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
252     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
253     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
254     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
255     0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
256     0,    0,    0,    0,    0,    0,    0,    0,    2,    0,
257     2,    0,    0,    0,    0,    0,    2,    2,    0,    0,
258     2,    0,    2,    2,
259 };
260 final static short yycheck[] = {                        258,
261     0,  260,  259,  269,  261,  266,  269,  266,  267,  269,
262   271,  270,  269,  272,  273,  264,  265,  259,  266,  266,
263   269,  268,  259,  259,  261,  261,  266,  266,  269,  259,
264   274,  263,    0,  271,   10,   37,   33,   -1,   -1,  274,
265    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
266    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
267    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
268    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
269    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
270    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
271    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
272    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
273    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
274    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
275    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
276    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
277    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
278    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
279    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
280    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
281    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
282    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
283    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
284    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
285    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
286    -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,  258,   -1,
287   260,   -1,   -1,   -1,   -1,   -1,  266,  267,   -1,   -1,
288   270,   -1,  272,  273,
289 };
290 final static short YYFINAL=1;
291 final static short YYMAXTOKEN=275;
292 final static String yyname[] = {
293 "end-of-file",null,null,null,null,null,null,null,null,null,null,null,null,null,
294 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
295 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
296 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
297 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
298 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
299 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
300 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
301 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
302 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
303 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
304 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
305 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
306 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
307 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
308 null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,null,
309 null,null,null,"SOF","ANGLE_OPEN","ANGLE_CLOSE","ANGLE_END_OPEN",
310 "ANGLE_END_CLOSE","ATTR","EQUAL","VALUE","STRING","TEXT","COMMENT_START",
311 "COMMENT_END","NAME","PI_OPEN","PI_CLOSE","DOCTYPE_START","CDATA_START",
312 "CDATA_END","EOF",
313 };
314 final static String yyrule[] = {
315 "$accept : document",
316 "document :",
317 "$$1 :",
318 "document : $$1 docstuff",
319 "docstuff : start",
320 "docstuff : docstuff start",
321 "start : element",
322 "element : element_start",
323 "element : element_end",
324 "element : comment",
325 "element : pi",
326 "element : cdata",
327 "element : doctype",
328 "element : TEXT",
329 "$$2 :",
330 "comment : COMMENT_START $$2 comment_text COMMENT_END",
331 "comment_text : TEXT",
332 "comment_text : comment_text TEXT",
333 "$$3 :",
334 "$$4 :",
335 "element_start : ANGLE_OPEN NAME $$3 attributes $$4 angle_end",
336 "angle_end : ANGLE_CLOSE",
337 "angle_end : ANGLE_END_CLOSE",
338 "element_end : ANGLE_END_OPEN NAME ANGLE_CLOSE",
339 "attributes : attribute attributes",
340 "attributes :",
341 "attribute : NAME EQUAL VALUE",
342 "attribute : NAME EQUAL NAME",
343 "attribute : NAME EQUAL STRING",
344 "attribute : NAME",
345 "pi : PI_OPEN NAME TEXT PI_CLOSE",
346 "pi : PI_OPEN NAME PI_CLOSE",
347 "$$5 :",
348 "cdata : CDATA_START $$5 text CDATA_END",
349 "text : TEXT text",
350 "text :",
351 "$$6 :",
352 "doctype : DOCTYPE_START TEXT $$6 ANGLE_CLOSE",
353 };
354 
355 //#line 136 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
356 
357   public final String DEFAULT_LEXER_NAME = "hotsax:default"; // name of the default lexer. distinguishes via namespace from some other "default" tag
358 
359   private SemanticLexer lexer;
360   private SemanticLexer savedLexer;   // hold it in while we switch to another lexer, see ScriptLexer
361 
362   private HashMap lexerHash;
363   private Reader reader;
364 
365   private boolean debug = false;
366 
367   private StringBuffer saved = new StringBuffer("");
368 
369   /* Helpers */
370   private ParserDelegate delegate;
371   public ParserDelegate getDelegate() { return delegate; }
372   private HtmlParserVal tagName; 
373 
374   private int yylex () {
375     int yyl_token = -1;
376     try {
377       yyl_token = lexer._yylex();
378 	
379 		if (yydebug)
380 			System.out.println("token: " + yyl_token + " " + yyname[yyl_token] + "  " + yylval.toString());
381     }
382     catch (IOException e) {
383       System.err.println("IO error :"+e);
384     }
385     return yyl_token;
386   }
387 
388   public void yyerror (String error) {
389     System.err.println ("Error: " + error);
390   }
391 
392 
393   /***
394    * Create new HtmlParser with specified reader 
395    */
396   public HtmlParser(Reader r) {
397     reader = r;
398     delegate = new SaxHandlerDelegate(this);
399 	lexerInit();  // setup the semantic lexers for this
400   }
401 
402   /***
403    * Create new HtmlParser with no reader. One must be set via setReader. 
404    * Calling setReader will also call lexerInit()
405    */
406   public HtmlParser() {
407 	reader = null;
408 	delegate = new SaxHandlerDelegate(this);
409   }
410 
411   /***
412    * Set the ParserDelegate. Can be a SaxHandlerDelegate or DebugDelegate. Could be used to write
413    * a DOM handler too.
414    * @param ParserDelegate to set
415    */
416    public void setParserDelegate(ParserDelegate delegate) {
417 		this.delegate = delegate;
418    }
419 
420   /***
421    * Get the current ParserDelegate
422    */
423    public ParserDelegate getParserDelegate() {
424 		return delegate;
425 	}
426 
427    /***
428     * Initialize the lexer hash. Setup the default lexer and any others. This is called by the 
429 	* constructor, so new lexers can be added at any time after the parser is built.
430     */
431    public void lexerInit() {
432 	lexerHash = new HashMap();
433 	addSemanticLexer(DEFAULT_LEXER_NAME, new HtmlLexer(reader, this));				// set the primary lexer
434 	addSemanticLexer("script", new ScriptLexer(reader, this));
435 	addSemanticLexer("style", new StyleLexer(reader, this));
436 	lexer = getSemanticLexer(DEFAULT_LEXER_NAME);
437    }
438 
439   /***
440    * Check the possibility of an alternate lexer for this semantic state.
441    *  E.g. script tags would invoke the ScriptLexer which creates a token stream different than X/HTML markup
442    */
443   public SemanticLexer getSemanticLexer(String name) {
444 	 return (SemanticLexer)lexerHash.get(name.toLowerCase());
445   }
446 
447  
448   /***
449    *  Change the lexer to the one specified in the name. If no lexer for this
450    *  token exists, the previous lexer remains in effect. 
451    *  The state of the current lexer is copied to the new lexer.
452    *  Note, by default "html" refers to  the HtmlLexer which is set when HtmlParser is initialized. 
453    *  However, no html tag is required to set it, it is the first lexe by default. The html tag has no effect.
454    *  Note: This may change in the future. The existance of a xml processing instruction
455    *  may switch the lexer from the  one.
456    */
457   public void setSemanticLexer(String name) {
458 	SemanticLexer newlexer = getSemanticLexer(name);
459 	if (newlexer != null) {		// possible establish a different lexer
460 		newlexer.setBuffer(lexer);
461 		lexer = newlexer;
462 		lexer.yybegin(HtmlLexer.YYINITIAL); // establish the initial state of the lexer
463 		if (debug) 
464 			System.out.println("lexer switched to " + lexer.getClass().getName());
465 	}
466   }
467 
468 
469   /***
470    * Revert the SemanticLexer to the default value. This is signified by the key "default". Under
471    * notmal circumstances, this would be HtmlLexer. But it might be different if the xml PI were seen
472    * and that specific processing instruction set the lexer to an XML lexer.
473    * @exception UnspecifiedSemanticLexerException thrown if the Default lexer disappeared.
474    */
475    public void revertSemanticLexer() 
476 	  throws UnspecifiedSemanticLexerException
477    {
478 	  if (getSemanticLexer(DEFAULT_LEXER_NAME) != null)
479 		  setSemanticLexer(DEFAULT_LEXER_NAME);
480 	  else
481 		  throw new UnspecifiedSemanticLexerException("No lexer defined to revert to");
482    }
483 
484   /***
485    *  Add a new Semantic Lexer to the hash of available lexers. Once set, 
486    *  the parser will switch lexers to to this one. The case is set to lower case before
487    *  it is stored as a key. The end tag will revert the lexer if set. This handles
488    *  cases like <script></SCRIPT>
489    *  The lexer must implement SemanticLexer and must be constructed with this parsers Reader (reader.)
490    *  <code>
491 		yyparser.addSemanyicLexer("style", new StyleLexer(yyparser.getReader(), yyparser));
492       </code>
493    *  @param name The lower case name of the tag or attribute this should key on.
494    *  @param lexer The SemanticLexer to use when this name token appears. 
495    *  @see setSemanticLexer
496    */
497   public void addSemanticLexer(String name, SemanticLexer lexer) {
498 	 lexerHash.put(name.toLowerCase(), lexer);	 
499   }
500 
501   /***
502    * Return the reader the parser is using.
503    */
504   public Reader getReader() {
505 	 return reader;
506   }
507 
508   /***
509    * Set the reader the parser is using.
510    * Also establishes any default and newly defined SemanticLexers
511    */
512   public void setReader(Reader r) {
513 	 reader = r;
514 	 lexerInit();
515   }
516 
517 	// testing -----------
518   static boolean interactive;
519 
520   public static void main(String args[]) throws IOException {
521     System.out.println("HotSAX Parser");
522 
523     HtmlParser yyparser;
524     if ( args.length > 0 ) {
525       // parse a file
526       yyparser = new HtmlParser(new FileReader(args[0]));
527     }
528     else {
529       // interactive mode
530       System.out.println("[Quit with CTRL-D]");
531       System.out.print("Expression: ");
532       interactive = true;
533       yyparser = new HtmlParser(new InputStreamReader(System.in));
534       yyparser.yydebug = true;
535     }
536 
537 	for (int i = 1; i < args.length; i++) {
538 		if (args[i].equalsIgnoreCase("debug")) {
539 			yyparser.setParserDelegate(new DebugParserDelegate(yyparser));
540 			yyparser.debug = true;
541 		}
542 		if (args[i].equalsIgnoreCase("verbose")) {
543 			yyparser.yydebug = true;
544 		}
545 	}
546 
547     yyparser.yyparse();
548     
549     if (interactive) {
550       System.out.println();
551       System.out.println("Have a nice day");
552     }
553   }
554 //#line 499 "HtmlParser.java"
555 //###############################################################
556 // method: yylexdebug : check lexer state
557 //###############################################################
558 void yylexdebug(int state,int ch)
559 {
560 String s=null;
561   if (ch < 0) ch=0;
562   if (ch <= YYMAXTOKEN) //check index bounds
563      s = yyname[ch];    //now get it
564   if (s==null)
565     s = "illegal-symbol";
566   debug("state "+state+", reading "+ch+" ("+s+")");
567 }
568 
569 
570 
571 
572 
573 //The following are now global, to aid in error reporting
574 int yyn;       //next next thing to do
575 int yym;       //
576 int yystate;   //current parsing state from state table
577 String yys;    //current token string
578 
579 
580 //###############################################################
581 // method: yyparse : parse input and execute indicated items
582 //###############################################################
583 int yyparse()
584 {
585 boolean doaction;
586   init_stacks();
587   yynerrs = 0;
588   yyerrflag = 0;
589   yychar = -1;          //impossible char forces a read
590   yystate=0;            //initial state
591   state_push(yystate);  //save it
592   while (true) //until parsing is done, either correctly, or w/error
593     {
594     doaction=true;
595     if (yydebug) debug("loop"); 
596     //#### NEXT ACTION (from reduction table)
597     for (yyn=yydefred[yystate];yyn==0;yyn=yydefred[yystate])
598       {
599       if (yydebug) debug("yyn:"+yyn+"  state:"+yystate+"  yychar:"+yychar);
600       if (yychar < 0)      //we want a char?
601         {
602         yychar = yylex();  //get next token
603         if (yydebug) debug(" next yychar:"+yychar);
604         //#### ERROR CHECK ####
605         if (yychar < 0)    //it it didn't work/error
606           {
607           yychar = 0;      //change it to default string (no -1!)
608           if (yydebug)
609             yylexdebug(yystate,yychar);
610           }
611         }//yychar<0
612       yyn = yysindex[yystate];  //get amount to shift by (shift index)
613       if ((yyn != 0) && (yyn += yychar) >= 0 &&
614           yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
615         {
616         if (yydebug)
617           debug("state "+yystate+", shifting to state "+yytable[yyn]);
618         //#### NEXT STATE ####
619         yystate = yytable[yyn];//we are in a new state
620         state_push(yystate);   //save it
621         val_push(yylval);      //push our lval as the input for next rule
622         yychar = -1;           //since we have 'eaten' a token, say we need another
623         if (yyerrflag > 0)     //have we recovered an error?
624            --yyerrflag;        //give ourselves credit
625         doaction=false;        //but don't process yet
626         break;   //quit the yyn=0 loop
627         }
628 
629     yyn = yyrindex[yystate];  //reduce
630     if ((yyn !=0 ) && (yyn += yychar) >= 0 &&
631             yyn <= YYTABLESIZE && yycheck[yyn] == yychar)
632       {   //we reduced!
633       if (yydebug) debug("reduce");
634       yyn = yytable[yyn];
635       doaction=true; //get ready to execute
636       break;         //drop down to actions
637       }
638     else //ERROR RECOVERY
639       {
640       if (yyerrflag==0)
641         {
642         yyerror("syntax error");
643         yynerrs++;
644         }
645       if (yyerrflag < 3) //low error count?
646         {
647         yyerrflag = 3;
648         while (true)   //do until break
649           {
650           if (stateptr<0)   //check for under & overflow here
651             {
652             yyerror("stack underflow. aborting...");  //note lower case 's'
653             return 1;
654             }
655           yyn = yysindex[state_peek(0)];
656           if ((yyn != 0) && (yyn += YYERRCODE) >= 0 &&
657                     yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE)
658             {
659             if (yydebug)
660               debug("state "+state_peek(0)+", error recovery shifting to state "+yytable[yyn]+" ");
661             yystate = yytable[yyn];
662             state_push(yystate);
663             val_push(yylval);
664             doaction=false;
665             break;
666             }
667           else
668             {
669             if (yydebug)
670               debug("error recovery discarding state "+state_peek(0)+" ");
671             if (stateptr<0)   //check for under & overflow here
672               {
673               yyerror("Stack underflow. aborting...");  //capital 'S'
674               return 1;
675               }
676             state_pop();
677             val_pop();
678             }
679           }
680         }
681       else            //discard this token
682         {
683         if (yychar == 0)
684           return 1; //yyabort
685         if (yydebug)
686           {
687           yys = null;
688           if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
689           if (yys == null) yys = "illegal-symbol";
690           debug("state "+yystate+", error recovery discards token "+yychar+" ("+yys+")");
691           }
692         yychar = -1;  //read another
693         }
694       }//end error recovery
695     }//yyn=0 loop
696     if (!doaction)   //any reason not to proceed?
697       continue;      //skip action
698     yym = yylen[yyn];          //get count of terminals on rhs
699     if (yydebug)
700       debug("state "+yystate+", reducing "+yym+" by rule "+yyn+" ("+yyrule[yyn]+")");
701     if (yym>0)                 //if count of rhs not 'nil'
702       yyval = val_peek(yym-1); //get current semantic value
703     switch(yyn)
704       {
705 //########## USER-SUPPLIED ACTIONS ##########
706 case 1:
707 //#line 29 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
708 {	
709 			delegate.startDocument();  
710 			delegate.endDocument();
711 		  }
712 break;
713 case 2:
714 //#line 33 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
715 { delegate.startDocument();  }
716 break;
717 case 3:
718 //#line 34 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
719 { delegate.endDocument(); }
720 break;
721 case 13:
722 //#line 50 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
723 { delegate.characters(yyval); }
724 break;
725 case 14:
726 //#line 54 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
727 { saved.setLength(0); }
728 break;
729 case 15:
730 //#line 55 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
731 { delegate.comment(new HtmlParserVal(saved.toString())); }
732 break;
733 case 16:
734 //#line 58 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
735 { saved.append(yyval); }
736 break;
737 case 17:
738 //#line 59 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
739 { saved.append(yyval); }
740 break;
741 case 18:
742 //#line 62 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
743 { delegate.startElement(); }
744 break;
745 case 19:
746 //#line 63 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
747 { 
748                     delegate.startElement(val_peek(2), delegate.getAttributes());
749                     tagName = val_peek(2);
750 					setSemanticLexer(tagName.toString());   /* see if script defines a new lexer*/
751                 }
752 break;
753 case 22:
754 //#line 73 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
755 { delegate.endElement(tagName); }
756 break;
757 case 23:
758 //#line 77 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
759 { 
760 			    try {
761 					tagName = val_peek(1);
762 					if (getSemanticLexer(tagName.toString()) != null)
763 						revertSemanticLexer();   /* if we were in ScriptLexer, maybe we are back*/
764 					delegate.endElement(val_peek(1)); 
765 				}
766 				catch(HtmlParserException ex) {
767 					yyerror(ex.getMessage());
768 				}
769 			  }
770 break;
771 case 26:
772 //#line 95 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
773 { delegate.addAttribute(val_peek(2).toString(), val_peek(0).toString()); }
774 break;
775 case 27:
776 //#line 96 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
777 { delegate.addAttribute(val_peek(2).toString(), val_peek(0).toString()); }
778 break;
779 case 28:
780 //#line 97 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
781 { delegate.addAttribute(val_peek(2).toString(), val_peek(0).toString()); }
782 break;
783 case 29:
784 //#line 98 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
785 { delegate.addAttribute(yyval.toString(), yyval.toString()); }
786 break;
787 case 30:
788 //#line 102 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
789 { delegate.processingInstruction(val_peek(2), val_peek(1)); }
790 break;
791 case 31:
792 //#line 103 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
793 { delegate.processingInstruction(val_peek(1), null); }
794 break;
795 case 32:
796 //#line 109 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
797 {
798 					delegate.startCDATA();
799 				}
800 break;
801 case 33:
802 //#line 112 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
803 {
804 					 delegate.endCDATA(); 
805 				}
806 break;
807 case 34:
808 //#line 117 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
809 {delegate.characters(val_peek(1)); }
810 break;
811 case 36:
812 //#line 123 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
813 { delegate.startDTD(yyval); }
814 break;
815 case 37:
816 //#line 124 "/home/edh/sourceforge/HotSAX/build/src/hotsax/html/sax/HtmlParser.y"
817 { delegate.endDTD(); }
818 break;
819 //#line 759 "HtmlParser.java"
820 //########## END OF USER-SUPPLIED ACTIONS ##########
821     }//switch
822     //#### Now let's reduce... ####
823     if (yydebug) debug("reduce");
824     state_drop(yym);             //we just reduced yylen states
825     yystate = state_peek(0);     //get new state
826     val_drop(yym);               //corresponding value drop
827     yym = yylhs[yyn];            //select next TERMINAL(on lhs)
828     if (yystate == 0 && yym == 0)//done? 'rest' state and at first TERMINAL
829       {
830       debug("After reduction, shifting from state 0 to state "+YYFINAL+"");
831       yystate = YYFINAL;         //explicitly say we're done
832       state_push(YYFINAL);       //and save it
833       val_push(yyval);           //also save the semantic value of parsing
834       if (yychar < 0)            //we want another character?
835         {
836         yychar = yylex();        //get next character
837         if (yychar<0) yychar=0;  //clean, if necessary
838         if (yydebug)
839           yylexdebug(yystate,yychar);
840         }
841       if (yychar == 0)          //Good exit (if lex returns 0 ;-)
842          break;                 //quit the loop--all DONE
843       }//if yystate
844     else                        //else not done yet
845       {                         //get next state and push, for next yydefred[]
846       yyn = yygindex[yym];      //find out where to go
847       if ((yyn != 0) && (yyn += yystate) >= 0 &&
848             yyn <= YYTABLESIZE && yycheck[yyn] == yystate)
849         yystate = yytable[yyn]; //get new state
850       else
851         yystate = yydgoto[yym]; //else go to new defred
852       debug("after reduction, shifting from state "+state_peek(0)+" to state "+yystate+"");
853       state_push(yystate);     //going again, so push state & val...
854       val_push(yyval);         //for next action
855       }
856     }//main loop
857   return 0;//yyaccept!!
858 }
859 //## end of method parse() ######################################
860 
861 
862 
863 //## run() --- for Thread #######################################
864 /***
865  * A default run method, used for operating this parser
866  * object in the background.  It is intended for extending Thread
867  * or implementing Runnable.  Turn off with -Jnorun .
868  */
869 public void run()
870 {
871   yyparse();
872 }
873 //## end of method run() ########################################
874 
875 
876 
877 //## Constructors ###############################################
878 //## The -Jnoconstruct option was used ##
879 //###############################################################
880 
881 
882 
883 }
884 //################### END OF CLASS ##############################