bottomUpParser

        This class implements a simple bottom up parser.
        This class may be used as base class for specialized parsers,
        i.e. to parse Tk commands of different flavours.

Syntax

        use bottomUpParser;
        my $p = bottomUpParser->new(<options>);
        $self->parse(<options>);
        $self->expected(<list of expected results>);

Programming notes

Base structure
        Constructor blesses a variable of type HASH.
Class member
        None
Data member
        -tokenList
        -tree
        -expected
        -result
Properties
        expected        ref to the expected token structure
        production  iterator to the production (reduce step)
        result      parsed token structure
        tree        ref to definition tree of the expected tokens
Constructor
        new (<options)
                        whereby options is
                                -tokenList, <ref to array>,
                                -tree , <ref to array>,
                                -production  <callback>
Destructor
        destroy
Methods
        import           import the constants to the caller' s package
        tokenList        list of the input stream (token)
        new              constructor
        init             instance initiator
        parse            parse process
        optlistMandatory process element of an optional token list (shift step)
        optlistOptional  process element of an mandatory token list (shift step)

Maintenance

        Author: Marco
        date:   18.04.2009
        History
                        18.04.2009 first draft
                        24.04.2009 version 1.02
                        30.12.2009 version 1.03
                        01.12.2009 version 1.04

import

        Import the constants in the client's name space
        Imported constants are
                NOTHING
                NEXTTOKEN
                SHIFT
                REDUCE
                TRYNEXTDEF
                TRYAGAIN
                RETURN
                DONE
                SHIFTANDREDUCE
                REDUCEANDSHIFT
                ALL
                OPTLISTOPTIONAL
                OPTLISTMANDATORY

BEGIN

        This sub is used to 'import' the constants
        in the class package itself.

tokenList

        This method copies the tokenlist into a local array
        and save a ref to it into the property tokenList.

new

        Instantiate a new parser object.

init

        This method initialize the data members of instance.
        Therefore, it takes the same arglist as the constructor.

parse

        This method parses recursively the tokenlist and
        returns the list of the parsed tokens which are saved
        while the shift steps.

optlistMandatory

        This is a minimal handler for a list element.
        It return true if the element is valid, and
        false when the end of list is encountered.
        TODO : check the existence of the list.

optlistOptional

        This is a minimal handler for a list element.
        It return true if the element is valid, and
        false when the end of list is encountered.

Back to index