lr_parser.html
来自「数据挖掘的最常用工具。由于开源」· HTML 代码 · 共 1,039 行 · 第 1/3 页
HTML
1,039 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><!--NewPage--><HTML><HEAD><!-- Generated by javadoc (build 1.5.0_13) on Tue Jul 15 15:48:48 NZST 2008 --><TITLE>lr_parser</TITLE><META NAME="keywords" CONTENT="weka.core.parser.java_cup.runtime.lr_parser class"><LINK REL ="stylesheet" TYPE="text/css" HREF="../../../../../stylesheet.css" TITLE="Style"><SCRIPT type="text/javascript">function windowTitle(){ parent.document.title="lr_parser";}</SCRIPT><NOSCRIPT></NOSCRIPT></HEAD><BODY BGCOLOR="white" onload="windowTitle();"><!-- ========= START OF TOP NAVBAR ======= --><A NAME="navbar_top"><!-- --></A><A HREF="#skip-navbar_top" title="Skip navigation links"></A><TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY=""><TR><TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1"><A NAME="navbar_top_firstrow"><!-- --></A><TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY=""> <TR ALIGN="center" VALIGN="top"> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD> <TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD> <TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="http://www.cs.waikato.ac.nz/ml/weka/" target="_blank"><FONT CLASS="NavBarFont1"><B>Weka's home</B></FONT></A> </TD> </TR></TABLE></TD><TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM></EM></TD></TR><TR><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../../weka/core/parser/java_cup/runtime/DefaultSymbolFactory.html" title="class in weka.core.parser.java_cup.runtime"><B>PREV CLASS</B></A> <A HREF="../../../../../weka/core/parser/java_cup/runtime/Scanner.html" title="interface in weka.core.parser.java_cup.runtime"><B>NEXT CLASS</B></A></FONT></TD><TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2"> <A HREF="../../../../../index.html?weka/core/parser/java_cup/runtime/lr_parser.html" target="_top"><B>FRAMES</B></A> <A HREF="lr_parser.html" target="_top"><B>NO FRAMES</B></A> <SCRIPT type="text/javascript"> <!-- if(window==top) { document.writeln('<A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A>'); } //--></SCRIPT><NOSCRIPT> <A HREF="../../../../../allclasses-noframe.html"><B>All Classes</B></A></NOSCRIPT></FONT></TD></TR><TR><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2"> SUMMARY: NESTED | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD><TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD></TR></TABLE><A NAME="skip-navbar_top"></A><!-- ========= END OF TOP NAVBAR ========= --><HR><!-- ======== START OF CLASS DATA ======== --><H2><FONT SIZE="-1">weka.core.parser.java_cup.runtime</FONT><BR>Class lr_parser</H2><PRE>java.lang.Object <IMG SRC="../../../../../resources/inherit.gif" ALT="extended by "><B>weka.core.parser.java_cup.runtime.lr_parser</B></PRE><DL><DT><B>Direct Known Subclasses:</B> <DD><A HREF="../../../../../weka/core/parser/JFlex/LexParse.html" title="class in weka.core.parser.JFlex">LexParse</A>, <A HREF="../../../../../weka/core/parser/java_cup/parser.html" title="class in weka.core.parser.java_cup">parser</A>, <A HREF="../../../../../weka/core/mathematicalexpression/Parser.html" title="class in weka.core.mathematicalexpression">Parser</A>, <A HREF="../../../../../weka/filters/unsupervised/instance/subsetbyexpression/Parser.html" title="class in weka.filters.unsupervised.instance.subsetbyexpression">Parser</A></DD></DL><HR><DL><DT><PRE>public abstract class <B>lr_parser</B><DT>extends java.lang.Object</DL></PRE><P>This class implements a skeleton table driven LR parser. In general, LR parsers are a form of bottom up shift-reduce parsers. Shift-reduce parsers act by shifting input onto a parse stack until the Symbols matching the right hand side of a production appear on the top of the stack. Once this occurs, a reduce is performed. This involves removing the Symbols corresponding to the right hand side of the production (the so called "handle") and replacing them with the non-terminal from the left hand side of the production. <p> To control the decision of whether to shift or reduce at any given point, the parser uses a state machine (the "viable prefix recognition machine" built by the parser generator). The current state of the machine is placed on top of the parse stack (stored as part of a Symbol object representing a terminal or non terminal). The parse action table is consulted (using the current state and the current lookahead Symbol as indexes) to determine whether to shift or to reduce. When the parser shifts, it changes to a new state by pushing a new Symbol (containing a new state) onto the stack. When the parser reduces, it pops the handle (right hand side of a production) off the stack. This leaves the parser in the state it was in before any of those Symbols were matched. Next the reduce-goto table is consulted (using the new state and current lookahead Symbol as indexes) to determine a new state to go to. The parser then shifts to this goto state by pushing the left hand side Symbol of the production (also containing the new state) onto the stack.<p> This class actually provides four LR parsers. The methods parse() and debug_parse() provide two versions of the main parser (the only difference being that debug_parse() emits debugging trace messages as it parses). In addition to these main parsers, the error recovery mechanism uses two more. One of these is used to simulate "parsing ahead" in the input without carrying out actions (to verify that a potential error recovery has worked), and the other is used to parse through buffered "parse ahead" input in order to execute all actions and re-synchronize the actual parser configuration.<p> This is an abstract class which is normally filled out by a subclass generated by the JavaCup parser generator. In addition to supplying the actual parse tables, generated code also supplies methods which invoke various pieces of user supplied code, provide access to certain special Symbols (e.g., EOF and error), etc. Specifically, the following abstract methods are normally supplied by generated code: <dl compact> <dt> short[][] production_table() <dd> Provides a reference to the production table (indicating the index of the left hand side non terminal and the length of the right hand side for each production in the grammar). <dt> short[][] action_table() <dd> Provides a reference to the parse action table. <dt> short[][] reduce_table() <dd> Provides a reference to the reduce-goto table. <dt> int start_state() <dd> Indicates the index of the start state. <dt> int start_production() <dd> Indicates the index of the starting production. <dt> int EOF_sym() <dd> Indicates the index of the EOF Symbol. <dt> int error_sym() <dd> Indicates the index of the error Symbol. <dt> Symbol do_action() <dd> Executes a piece of user supplied action code. This always comes at the point of a reduce in the parse, so this code also allocates and fills in the left hand side non terminal Symbol object that is to be pushed onto the stack for the reduce. <dt> void init_actions() <dd> Code to initialize a special object that encapsulates user supplied actions (this object is used by do_action() to actually carry out the actions). </dl> In addition to these routines that <i>must</i> be supplied by the generated subclass there are also a series of routines that <i>may</i> be supplied. These include: <dl> <dt> Symbol scan() <dd> Used to get the next input Symbol from the scanner. <dt> Scanner getScanner() <dd> Used to provide a scanner for the default implementation of scan(). <dt> int error_sync_size() <dd> This determines how many Symbols past the point of an error must be parsed without error in order to consider a recovery to be valid. This defaults to 3. Values less than 2 are not recommended. <dt> void report_error(String message, Object info) <dd> This method is called to report an error. The default implementation simply prints a message to System.err and where the error occurred. This method is often replaced in order to provide a more sophisticated error reporting mechanism. <dt> void report_fatal_error(String message, Object info) <dd> This method is called when a fatal error that cannot be recovered from is encountered. In the default implementation, it calls report_error() to emit a message, then throws an exception. <dt> void syntax_error(Symbol cur_token) <dd> This method is called as soon as syntax error is detected (but before recovery is attempted). In the default implementation it invokes: report_error("Syntax error", null); <dt> void unrecovered_syntax_error(Symbol cur_token) <dd> This method is called if syntax error recovery fails. In the default implementation it invokes:<br> report_fatal_error("Couldn't repair and continue parse", null); </dl><P><P><DL><DT><B>Version:</B></DT> <DD>last updated: 7/3/96</DD><DT><B>Author:</B></DT> <DD>Frank Flannery</DD><DT><B>See Also:</B><DD><CODE>java_cup.runtime.Symbol</CODE>, <CODE>java_cup.runtime.Symbol</CODE>, <CODE>java_cup.runtime.virtual_parse_stack</CODE></DL><HR><P><!-- =========== FIELD SUMMARY =========== --><A NAME="field_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>Field Summary</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../../../../weka/core/parser/java_cup/runtime/SymbolFactory.html" title="interface in weka.core.parser.java_cup.runtime">SymbolFactory</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#symbolFactory">symbolFactory</A></B></CODE><BR> </TD></TR></TABLE> <!-- ======== CONSTRUCTOR SUMMARY ======== --><A NAME="constructor_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>Constructor Summary</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#lr_parser()">lr_parser</A></B>()</CODE><BR> Simple constructor.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#lr_parser(weka.core.parser.java_cup.runtime.Scanner)">lr_parser</A></B>(<A HREF="../../../../../weka/core/parser/java_cup/runtime/Scanner.html" title="interface in weka.core.parser.java_cup.runtime">Scanner</A> s)</CODE><BR> Constructor that sets the default scanner.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#lr_parser(weka.core.parser.java_cup.runtime.Scanner, weka.core.parser.java_cup.runtime.SymbolFactory)">lr_parser</A></B>(<A HREF="../../../../../weka/core/parser/java_cup/runtime/Scanner.html" title="interface in weka.core.parser.java_cup.runtime">Scanner</A> s, <A HREF="../../../../../weka/core/parser/java_cup/runtime/SymbolFactory.html" title="interface in weka.core.parser.java_cup.runtime">SymbolFactory</A> symfac)</CODE><BR> Constructor that sets the default scanner and a SymbolFactory</TD></TR></TABLE> <!-- ========== METHOD SUMMARY =========== --><A NAME="method_summary"><!-- --></A><TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY=""><TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor"><TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2"><B>Method Summary</B></FONT></TH></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>abstract short[][]</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#action_table()">action_table</A></B>()</CODE><BR> The action table (supplied by generated subclass).</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#debug_message(java.lang.String)">debug_message</A></B>(java.lang.String mess)</CODE><BR> Write a debugging message to System.err for the debugging version of the parser.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> <A HREF="../../../../../weka/core/parser/java_cup/runtime/Symbol.html" title="class in weka.core.parser.java_cup.runtime">Symbol</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#debug_parse()">debug_parse</A></B>()</CODE><BR> Perform a parse with debugging output.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#debug_reduce(int, int, int)">debug_reduce</A></B>(int prod_num, int nt_num, int rhs_size)</CODE><BR> Do debug output for a reduce.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#debug_shift(weka.core.parser.java_cup.runtime.Symbol)">debug_shift</A></B>(<A HREF="../../../../../weka/core/parser/java_cup/runtime/Symbol.html" title="class in weka.core.parser.java_cup.runtime">Symbol</A> shift_tkn)</CODE><BR> Do debug output for shift.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#debug_stack()">debug_stack</A></B>()</CODE><BR> Do debug output for stack state.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE>abstract <A HREF="../../../../../weka/core/parser/java_cup/runtime/Symbol.html" title="class in weka.core.parser.java_cup.runtime">Symbol</A></CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#do_action(int, weka.core.parser.java_cup.runtime.lr_parser, java.util.Stack, int)">do_action</A></B>(int act_num, <A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html" title="class in weka.core.parser.java_cup.runtime">lr_parser</A> parser, java.util.Stack stack, int top)</CODE><BR> Perform a bit of user supplied action code (supplied by generated subclass).</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#done_parsing()">done_parsing</A></B>()</CODE><BR> This method is called to indicate that the parser should quit.</TD></TR><TR BGCOLOR="white" CLASS="TableRowColor"><TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1"><CODE> void</CODE></FONT></TD><TD><CODE><B><A HREF="../../../../../weka/core/parser/java_cup/runtime/lr_parser.html#dump_stack()">dump_stack</A></B>()</CODE>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?