Scanner
Object Hierarchy:
Description:
[ Compact ]
public class Scanner
The data structure representing a lexical scanner.
You should set input_name
after creating the scanner, since it is used by the default message handler when displaying
warnings and errors. If you are scanning a file, the filename would be a good choice.
The user_data
and max_parse_errors
fields are not used. If you need to associate extra data with the scanner
you can place them here.
If you want to use your own message handler you can set the msg_handler
field. The type of the message handler function is
declared by ScannerMsgFunc.
Content:
Creation methods:
Methods:
- public void input_file (int input_fd)
Prepares to scan a file.
- public void sync_file_offset ()
Rewinds the filedescriptor to the current buffer position and blows
the file read ahead buffer.
- public void input_text (string text, uint text_len)
Prepares to scan a text buffer.
- public TokenType peek_next_token ()
Parses the next token, without removing it from the input stream.
- public TokenType get_next_token ()
Parses the next token just like
peek_next_token and also removes it from the input stream.
- public bool eof ()
Returns true if the
scanner has reached the end of the file or text buffer.
- public int cur_line ()
Returns the current line in the input stream (counting from 1).
- public int cur_position ()
Returns the current position in the current line (counting from 0).
- public TokenType cur_token ()
Gets the current token type.
- public TokenValue cur_value ()
Gets the current token value.
- public uint set_scope (uint scope_id)
Sets the current scope.
- public void scope_add_symbol (uint scope_id, string symbol, void* value)
Adds a symbol to the given scope.
- public void scope_foreach_symbol (uint scope_id, HFunc func)
Calls the given function for each of the symbol/value pairs in the
given scope of the Scanner.
- public void* scope_lookup_symbol (uint scope_id, string symbol)
Looks up a symbol in a scope and return its value.
- public void scope_remove_symbol (uint scope_id, string symbol)
Removes a symbol from a scope.
- public void* lookup_symbol (string symbol)
Looks up a symbol in the current scope and return its value.
- public void warn (string format, ...)
Outputs a warning message, via the Scanner
message handler.
- public void error (string format, ...)
Outputs an error message, via the Scanner
message handler.
- public void unexp_token (TokenType expected_token, string? identifier_spec, string? symbol_spec, string? symbol_name, string? message, bool is_error)
Outputs a message through the scanner's msg_handler, resulting from an
unexpected token in the input stream.
Fields: