]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/antlr2/src/Parser.cpp
1 /* ANTLR Translator Generator
2 * Project led by Terence Parr at http://www.jGuru.com
3 * Software rights: http://www.antlr.org/license.html
5 * $Id: //depot/code/org.antlr/release/antlr-2.7.7/lib/cpp/src/Parser.cpp#2 $
8 #include "antlr/Parser.hpp"
12 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
16 /** A generic ANTLR parser (LL(k) for k>=1) containing a bunch of
17 * utility routines useful at any lookahead depth. We distinguish between
18 * the LL(1) and LL(k) parsers because of efficiency. This may not be
19 * necessary in the near future.
21 * Each parser object contains the state of the parse including a lookahead
22 * cache (the form of which is determined by the subclass), whether or
23 * not the parser is in guess mode, where tokens come from, etc...
26 * During <b>guess</b> mode, the current lookahead token(s) and token type(s)
27 * cache must be saved because the token stream may not have been informed
28 * to save the token (via <tt>mark</tt>) before the <tt>try</tt> block.
29 * Guessing is started by:
31 * <li>saving the lookahead cache.
32 * <li>marking the current position in the TokenBuffer.
33 * <li>increasing the guessing level.
36 * After guessing, the parser state is restored by:
38 * <li>restoring the lookahead cache.
39 * <li>rewinding the TokenBuffer.
40 * <li>decreasing the guessing level.
44 * @see antlr.TokenBuffer
45 * @see antlr.TokenStream
46 * @see antlr.LL1Parser
47 * @see antlr.LLkParser
50 bool DEBUG_PARSER
= false;
52 /** Parser error-reporting function can be overridden in subclass */
53 void Parser::reportError(const RecognitionException
& ex
)
55 fprintf(stderr
, "%s", (ex
.toString() + "\n").c_str());
58 /** Parser error-reporting function can be overridden in subclass */
59 void Parser::reportError(const ANTLR_USE_NAMESPACE(std
)string
& s
)
61 if ( getFilename()=="" )
62 fprintf(stderr
, "%s", ("error: " + s
+ "\n").c_str());
64 fprintf(stderr
, "%s", (getFilename() + ": error: " + s
+ "\n").c_str());
67 /** Parser warning-reporting function can be overridden in subclass */
68 void Parser::reportWarning(const ANTLR_USE_NAMESPACE(std
)string
& s
)
70 if ( getFilename()=="" )
71 fprintf(stderr
, "%s", ("warning: " + s
+ "\n").c_str());
73 fprintf(stderr
, "%s", (getFilename() + ": warning: " + s
+ "\n").c_str());
76 /** Set or change the input token buffer */
77 // void setTokenBuffer(TokenBuffer<Token>* t);
79 void Parser::traceIndent()
81 for( int i
= 0; i
< traceDepth
; i
++ )
85 void Parser::traceIn(const char* rname
)
89 for( int i
= 0; i
< traceDepth
; i
++ )
92 printf("%s",((ANTLR_USE_NAMESPACE(std
)string
)"> " + rname
93 + "; LA(1)==" + LT(1)->getText()
94 + ((inputState
->guessing
>0)?" [guessing]":"")
98 void Parser::traceOut(const char* rname
)
100 for( int i
= 0; i
< traceDepth
; i
++ )
103 printf("%s",((ANTLR_USE_NAMESPACE(std
)string
)"< " + rname
104 + "; LA(1)==" + LT(1)->getText()
105 + ((inputState
->guessing
>0)?" [guessing]":"")
111 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE