⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 apiroutines.html

📁 This a JavaCC documentation.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<HTML><!--Copyright 漏 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,California 95054, U.S.A. All rights reserved.  Sun Microsystems, Inc. hasintellectual property rights relating to technology embodied in the productthat is described in this document. In particular, and without limitation,these intellectual property rights may include one or more of the U.S.patents listed at http://www.sun.com/patents and one or more additionalpatents or pending patent applications in the U.S. and in other countries.U.S. Government Rights - Commercial software. Government users are subjectto the Sun Microsystems, Inc. standard license agreement and applicableprovisions of the FAR and its supplements.  Use is subject to license terms.Sun,  Sun Microsystems,  the Sun logo and  Java are trademarks or registeredtrademarks of Sun Microsystems, Inc. in the U.S. and other countries.  Thisproduct is covered and controlled by U.S. Export Control laws and may besubject to the export or import laws in other countries.  Nuclear, missile,chemical biological weapons or nuclear maritime end uses or end users, whetherdirect or indirect, are strictly prohibited.  Export or reexport to countriessubject to U.S. embargo or to entities identified on U.S. export exclusionlists, including, but not limited to, the denied persons and speciallydesignated nationals lists is strictly prohibited.--><HEAD> <title>JavaCC API Documentation</title><!-- Changed by: Michael Van De Vanter, 14-Jan-2003 --></HEAD><BODY bgcolor="#FFFFFF" ><H1>JavaCC [tm]: API Routines</H1>This web page is a comprehensive list of all classes, methods,and variables available for use by a JavaCC [tm] user.  These classes,methods, and variables are typically used from the actions thatare embedded in a JavaCC grammar.  In the sample code used below,it is assumed that the name of the generated parser is "TheParser".<P><HR><P><CENTER><H3>Non-Terminals in the Input Grammar</H3></CENTER><P><HR><P>For each non-terminal NT in the input grammar file, the following methodis generated into the parser class:<P><UL><LI><STRONG><EM>returntype</EM> NT(<EM>parameters</EM>) throws ParseError;</STRONG></UL>Here, <EM>returntype</EM> and <EM>parameters</EM> are what were specifiedin the JavaCC input file in the definition of NT (where NT occurred on theleft-hand side).<P>When this method is called, the input stream is parsed to match this non-terminal.On a successful parse, this method returns normally.  On detection of a parseerror, an error message is displayed and the method returns by throwing theexception ParseError.<P><EM>Note that all non-terminals in a JavaCC input grammar have equal status;it is possible to parse to any non-terminal by calling the  non-terminal's method.</EM><P><HR><P><CENTER><H3>API for Parser Actions</H3></CENTER><P><HR><P><UL>  <LI><STRONG> Token token;</STRONG><BR>This variable holds the last token consumed by the parser and can be usedin parser actions. This is <EM>exactly</EM> the same as the token returned by<EM>getToken(0)</EM>.</UL>In addition, the two methods - <EM><A href="#getToken">getToken(int i)</A></EM> and<EM><A href="#getNextToken">getNextToken()</A></EM> can also be used inactions to traverse the token list.<P><HR><P><CENTER><H3>The Token Manager Interface</H3></CENTER><P><HR><P>Typically, the token manager interface is not to be used.  Instead all accessmust be made through the parser interface.  However, in certain situations -such as if you are not building a parser and building only the token manager -the token manager interface is useful.The token manager provides the following routine:<UL><LI><STRONG>Token getNextToken() throws ParseError;</STRONG></UL>Each call to this method returns the next token in the input stream. Thismethod throws a ParseError exception when there is a lexical error, i.e.,it could not find a match for any of the specified tokens from the inputstream.  The type Token is described later.<P><HR><P><CENTER><H3>Constructors and Other Initialization Routines</H3></CENTER><P><HR><P><UL><LI><STRONG>TheParser.TheParser(java.io.InputStream stream)</STRONG><BR>This creates a new parser object, which in turn creates a new token manager objectthat reads its tokens from "stream".  This constructor is available onlywhen both the options USER_TOKEN_MANAGER and USER_CHAR_STREAM are false.If the option STATIC is true, this constructor (along with other constructors)can be called exactly once to create a single parser object.<P><LI><STRONG>TheParser.TheParser(CharStream stream)</STRONG><BR>Similar to the previous constructor, except that this one is available onlywhen the option USER_TOKEN_MANAGER is false and USER_CHAR_STREAM is true.<P><LI><STRONG>void TheParser.ReInit(java.io.InputStream stream)</STRONG><BR>This reinitializes an existing parser object.  In addition, it also reinitializesthe existing token manager object that corresponds to this parser object.  The resultis a parser object with the exact same functionality as one that was createdwith the constructor above.  The only difference is that new objects are notcreated.  This method is available onlywhen both the options USER_TOKEN_MANAGER and USER_CHAR_STREAM are false.If the option STATIC is true, this (along with the other ReInit methods)is the only way to restart a parse operationfor there is only one parser and all one can do is reinitialize it.<P><LI><STRONG>void TheParser.ReInit(CharStream stream)</STRONG><BR>Similar to the previous method, except that this one is available onlywhen the option USER_TOKEN_MANAGER is false and USER_CHAR_STREAM is true.<P><LI><STRONG>TheParser(TheParserTokenManager tm)</STRONG>This creates a new parser object which uses an already created token manager object "tm" asits token manager.  This constructor is only available if option USER_TOKEN_MANAGER isfalse.  If the option STATIC is true, this constructor (along with other constructors)can be called exactly once to create a single parser object.<P><LI><STRONG>TheParser(TokenManager tm)</STRONG><BR>Similar to the previous constructor, except that this one is available onlywhen the option USER_TOKEN_MANAGER is true.<P><LI><STRONG>void TheParser.ReInit(TheParserTokenManager tm)</STRONG><BR>This reinitializes an existing parser object with the token manager object "tm" as itsnew token manager.  This method is only available if option USER_TOKEN_MANAGER isfalse.  If the option STATIC is true, this (along with the other ReInit methods)is the only way to restart a parse operationfor there is only one parser and all one can do is reinitialize it.<P><LI><STRONG>void TheParser.ReInit(TokenManager tm)</STRONG><BR>Similar to the previous method, except that this one is available onlywhen the option USER_TOKEN_MANAGER is true.<P><LI><STRONG>TheParserTokenManager.TheParserTokenManager(CharStream stream)</STRONG><BR>Creates a new token manager object initialized to read input from "stream".  Whenthe option STATIC is true, this constructor may be called only once.This is available only when USER_TOKEN_MANAGER is false and USER_CHAR_STREAMis true.  When USER_TOKEN_MANAGER is false and USER_CHAR_STREAM is false (the default situation),a constructor similar to the one above is available with the type CharStreamreplaced as follows:<UL><LI>When JAVA_UNICODE_ESCAPE is false and UNICODE_INPUT is false, CharStream isreplaced by ASCII_CharStream.<LI>When JAVA_UNICODE_ESCAPE is false and UNICODE_INPUT is true, CharStream isreplaced by UCode_CharStream.<LI>When JAVA_UNICODE_ESCAPE is true and UNICODE_INPUT is false, CharStream isreplaced by ASCII_UCodeESC_CharStream.<LI>When JAVA_UNICODE_ESCAPE is true and UNICODE_INPUT is true, CharStream isreplaced by UCode_UCodeESC_CharStream.</UL><P><LI><STRONG>void TheParserTokenManager.ReInit(CharStream stream)</STRONG><BR>Reinitializes the current token manager object to read input from "stream".  Whenthe option STATIC is true, this is the only way to restart a token manager operation.This is available only when USER_TOKEN_MANAGER is false and USER_CHAR_STREAMis true.  When USER_TOKEN_MANAGER is false and USER_CHAR_STREAM is false (the default situation),a constructor similar to the one above is available with the type CharStreamreplaced as follows:<UL><LI>When JAVA_UNICODE_ESCAPE is false and UNICODE_INPUT is false, CharStream isreplaced by ASCII_CharStream.<LI>When JAVA_UNICODE_ESCAPE is false and UNICODE_INPUT is true, CharStream isreplaced by UCode_CharStream.<LI>When JAVA_UNICODE_ESCAPE is true and UNICODE_INPUT is false, CharStream isreplaced by ASCII_UCodeESC_CharStream.<LI>When JAVA_UNICODE_ESCAPE is true and UNICODE_INPUT is true, CharStream isreplaced by UCode_UCodeESC_CharStream.</UL></UL><P><HR><P><CENTER><H3>The Token Class</H3></CENTER><P><HR><P>The Token class is the type of token objects that are created by the token managerafter a successful scanning of the token stream.  These token objects are thenpassed to the parser and are accessible to the actions in a JavaCC grammar usuallyby grabbing the return value of a token.  The methods getToken and getNextTokendescribed below also give access to objects of this type.<P>Each Token object has the following fields:<UL><LI><STRONG>int kind;</STRONG><BR>This is the index for this kind of token in the internal representation schemeof JavaCC.  When tokens in the JavaCC input file are given labels, these labelsare used to generate "int" constants that can be used in actions.The value 0 is always used to represent the predefined token &lt;EOF&gt;.  Aconstant "EOF" is generated for convenience in the ...Constants file.<P><LI><STRONG>int beginLine, beginColumn, endLine, endColumn;</STRONG><BR>These indicate the beginning and ending positions of the token as it appearedin the input stream.<P><LI><STRONG>String image;</STRONG><BR>This represents the image of the token as it appeared in the input stream.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -