BaseScanner
[ TVI_Scanner | Source | Keywords | Summary | Ancestors | All Members | Descendants ]
| public: | |
| BaseScanner() ; | |
| ~BaseScanner() ; | |
| void | Reset(void) ; |
| const char* | Lexeme(void) const |
| TokenType | Lookahead(void) const ; |
| int | AsInt(void) const ; |
| float | AsFloat(void) const ; |
| void | Match(TokenType token); |
| protected: | |
| BaseScanner(const BaseScanner& s) ; | |
| void | FAdd(char ch) ; |
| void | FClearLexeme(void) ; |
| char | FGetChar(void) ; |
| void | FSkipWS(void); |
| void | FAdvance(void); |
| void | FCollectId(void); |
| void | FCollectNumber(void); |
| void | FCollectString(void); |
Back to the top of BaseScanner
|
The BaseScanner class can be used to recognize simple tokens in an input stream. The tokens recognized by the Scanner are: The BaseScanner class skips over comments in the source file. When a semi-colon is encountered the BaseScanner repeatedly calls FGetChar until a newline or eof is encounted.
|
Back to the top of BaseScanner
|
The BaseScanner's sole interaction with the input stream is through the protected virtual function FGetChar. By default FGetChar simply reads a character from the standard input. Derived classes can scan arbitrary input streams by overriding the FGetChar method. Derived classes must always call the Reset method before scanning an input stream. Reset causes the scanner to read the first character and advance to the next token in the input stream. Calling Reset at other times may cause the scanner to lose input. The protected member function FCollectId has also been declared as virtual to allow the scanner to interface easily with various symbol tables. See the class TVIScanner for an example. The BaseScanner class also provides the virtual observer function Line which can be used to return the line number for file based input streams.
|
Back to the top of BaseScanner
Back to the top of BaseScanner
BaseScanner(const BaseScanner& s) ;
Copy Constructor
Note that the copy constructor is protected and can not be instantiated directly.
BaseScanner(const BaseScanner& s) ;
Function is currently defined inline.
Back to the top of BaseScanner
void FAdd(char ch) ;
Add a character to the current lexeme.
Parameters
Postcoditions
void FAdd(char ch) ;
Function is currently defined inline.
Back to the top of BaseScanner
void FClearLexeme(void) ;
Clears the lexeme by setting fLexPos to zero and writing
a NULL character to the first element of the lexeme buffer
void FClearLexeme(void) ;
Function is currently defined inline.
Back to the top of BaseScanner
char FGetChar(void) ;
Fetches a single character from the input stream.
virtual char FGetChar(void) ;
Function is currently defined inline.
Back to the top of BaseScanner
void FSkipWS(void);
Skips over whitespace characters in the input buffer. Since the
newline character is a token in TVI code these are NOT skipped.
void FSkipWS(void);
Back to the top of BaseScanner
void FAdvance(void);
Fetch the next token from the input stream. Calls FCollectId or
FCollectNumber as appropriate.
Preconditions
Postconditions
Throws
void FAdvance(void);
Back to the top of BaseScanner
void FCollectId(void);
Fetches an identifier from the input stream.
Preconditions
Postconditions
virtual void FCollectId(void);
Back to the top of BaseScanner
void FCollectNumber(void);
Fetches an integer or floating point number from the input stream
Preconditions
Postconditions
Throws
void FCollectNumber(void);
Back to the top of BaseScanner
void FCollectString(void);
Collects all the text between a pair of double quote characters. Quoted
strings are not allowed to span lines.
A quoted string may contain \t, \n for tab and newline characters respectively. If a double quote character must appear inside the string then it must also be escaped with the backslash,
I.E.
STR = quote = " This is a \"quote\"..."
Preconditions
Postconditions
Throws
void FCollectString(void);
Back to the top of BaseScanner
BaseScanner() ;
Initialize all members to default values.
BaseScanner() ;
Function is currently defined inline.
Back to the top of BaseScanner
~BaseScanner() ;
The destructor closes the file if it is open.
virtual ~BaseScanner() ;
Function is currently defined inline.
Back to the top of BaseScanner
void Reset(void) ;
Resets the read pointer of the ifstream to the beginning of the file.
If the ifstream isn't open no actions are taken.
Postconditions
Throws
virtual void Reset(void) ;
Function is currently defined inline.
Back to the top of BaseScanner
const char* Lexeme(void) const
Returns the surface string of the next token in the input stream.
I.E. if the next token is the opcode move then the TokenType
will be T_opcode and the surface string with be the string "move".
const char* Lexeme(void) const { return fLexeme; }
Back to the top of BaseScanner
TokenType Lookahead(void) const ;
Returns the TokenType for the next token in the input stream. Returns
T_eof if there are no tokens remaining in the stream.
TokenType Lookahead(void) const ;
Function is currently defined inline.
Back to the top of BaseScanner
int AsInt(void) const ;
Converts the lexeme into an integer and returns the result.
Preconditions
int AsInt(void) const ;
Function is currently defined inline.
Back to the top of BaseScanner
float AsFloat(void) const ;
Converts the lexeme into a floating point value and returns the result.
Preconditions
float AsFloat(void) const ;
Function is currently defined inline.
Back to the top of BaseScanner
void Match(TokenType token);
Compares the paramters token witht the next token in the input
stream. If the tokens are the same the scanner advances to the next token
in the stream. Throws an exception if the tokens do not match.
Throws
void Match(TokenType token);
Back to the top of BaseScanner
| public: | ||
|---|---|---|
| void | Reset(void) ; | |
| const char* | Lexeme(void) const | |
| TokenType | Lookahead(void) const ; | |
| int | AsInt(void) const ; | |
| float | AsFloat(void) const ; | |
| void | Match(TokenType token); | |
| protected: | ||
| void | FAdd(char ch) ; | |
| void | FClearLexeme(void) ; | |
| char | FGetChar(void) ; | |
| void | FSkipWS(void); | |
| void | FAdvance(void); | |
| void | FCollectId(void); | |
| void | FCollectNumber(void); | |
| void | FCollectString(void); | |
Back to the top of BaseScanner
Back to the top of BaseScanner
Back to the top of BaseScanner
Generated from source by the Cocoon utilities on Mon Apr 9 01:38:29 2001 .
Report problems to jkotula@vitalimages.com