]>
git.saurik.com Git - apple/security.git/blob - OSX/libsecurity_codesigning/antlr2/src/TokenBuffer.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/TokenBuffer.cpp#2 $
8 #include "antlr/TokenBuffer.hpp"
10 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE
14 /**A Stream of Token objects fed to the parser from a TokenStream that can
15 * be rewound via mark()/rewind() methods.
17 * A dynamic array is used to buffer up all the input tokens. Normally,
18 * "k" tokens are stored in the buffer. More tokens may be stored during
19 * guess mode (testing syntactic predicate), or when LT(i>k) is referenced.
20 * Consumption of tokens is deferred. In other words, reading the next
21 * token is not done by conume(), but deferred until needed by LA or LT.
25 * @see antlr.TokenStream
26 * @see antlr.TokenQueue
29 /** Create a token buffer */
30 TokenBuffer::TokenBuffer( TokenStream
& inp
)
38 TokenBuffer::~TokenBuffer( void )
42 /** Ensure that the token buffer is sufficiently full */
43 void TokenBuffer::fill(unsigned int amount
)
46 // Fill the buffer sufficiently to hold needed tokens
47 while (queue
.entries() < (amount
+ markerOffset
))
49 // Append the next token
50 queue
.append(input
.nextToken());
54 /** Get a lookahead token value */
55 int TokenBuffer::LA(unsigned int i
)
58 return queue
.elementAt(markerOffset
+i
-1)->getType();
61 /** Get a lookahead token */
62 RefToken
TokenBuffer::LT(unsigned int i
)
65 return queue
.elementAt(markerOffset
+i
-1);
68 /** Return an integer marker that can be used to rewind the buffer to
71 unsigned int TokenBuffer::mark()
78 /**Rewind the token buffer to a marker.
79 * @param mark Marker returned previously from mark()
81 void TokenBuffer::rewind(unsigned int mark
)
88 /// Get number of non-consumed tokens
89 unsigned int TokenBuffer::entries() const
91 return (unsigned int)queue
.entries() - markerOffset
;
94 #ifdef ANTLR_CXX_SUPPORTS_NAMESPACE