<<

HCT::Language::Lexer

NAME

HCT::Language::Lexer - Base class of lexer used by HCT.

DESCRIPTION

CONSTRUCTOR

new ()

Creates a new HCT::Language::Lexer object.

METHODS

input ([FH])

Returns input object created by HCT::Std::IO. If FH set, creates a new input object.

skip_comment ()

Virtual method that provides skip from the comments. Returns true if current position should be skipped.

skip_whitespace ()

Skips whitespaces. Just removes leading white spaces.

skip_hook ()

Virtual method that provides skip the current positions. Returns true or false.

match (EXPR)

If EXPR passed successfully, returns matched value and sets new line position. Else, goes back to the previous position and returns undef.

linepos ([POS])

If POS set, changes current line position. Returns current line position.

Important: works not directly with current line position (pos), but with variable that store previous position value.

linelen ()

Returns current line length.

linenum ()

Returns current line number.

eof ()

Returns true if end of file (input), or false.

eol ()

Returns true if end of line, or false.

move ()

Moves to the next line. If line is ended (pos equal to len), gets a new line. If line is empty, moves once again. If file is finished returns EOF.

Returns true if we can move forward or false.

scan (PARSER)

The scanner has encoded within it information on the possible sequences of characters that can be contained within any of the tokens it handles. Returns token.

stop ()

Returns EMPTY_TOKEN to stop the parser. Could be rewritten if needed, see CDL lexer.

callback ()

Returns parser handler. Will be updated as soon, as scan called.

trace ()

Returns object of trace created by HCT::Language::Trace.

next_token ()

Tries to find corresponding token. Return true if token was found, or false as finish.

next_token_hook ()

Virtual method. Tries to get around main lexer method next_token. Will be called at the end of next_token, if will not found correspond token.

Returns true if token was found, or false.

match_lexemes ()
checkup_actions ()
checkup_actions_hook ()
reserve_tokens ()

Virtual method to provide reserve of tokens.

do_reserve ()

Makes reserve of tokens by calling reserve_tokens and fills lexemelist by sorting lexemetable.

reserve (PRIORITY, TOKENS)

Creates an objects of new tokens by using HCT::Language::Token and stores them into the objtable.

Each token name will be register in the table of names - nametable, and their lexemes in lexemetable. Each of them will be linked with position in objtable.

lookup_token (KEY, VALUE)

Returns token object, where KEY can be name or lexeme.

Example:

        $token_obj = $lexer->lookup_token (lexeme => 'if');
        $token_obj = $lexer->lookup_token (name => 'TOK_IF');
get_token (ID)

Gets token id and returns token object from objlist. Commonly this method using by lookup_token.

shift_token ()

Shifts and returns token from token stack.

push_token ()

Psuh new token to the stack and returns true.

PROBLEMS

Identifiers and keywords

The lexer state solution involves coordination between the lexer and the parser. In particular, the parser must tell the lexer whether in "this context" a keyword is expected or an identifier is expected. There are several problems with coordinating the lexer's state with the parser's context. One of the most frequently noted ones is that it makes (multiple token) lookahead more difficult. A related problem occurs if the context is miscommunicated between the parser and the lexer, the lexer may return a keyword when only identifers are expected or return the keyword as an identifier when the keyword was supposed to be treated as a keyword.

<<

This document is part of HCT, the Hardware Complexity Tool.

Generated: Fri Jul 17 10:38:47 2009