NAME ^

Tcl Parser

DESCRIPTION ^

This is the parser that makes up the heart of Partcl. It follows the 11 rules that are found in the Tcl manpage, available online at <http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm>.

(int register_num, string pir_code) = compile(int register_num, string tcl_code)

Parses the Tcl code and returns generated PIR code.

Argument register_num is the first register number that is available for use by the generated PIR.

Return register_num is the register number that contains the result of this code.

(pmc invokable) = pir_compiler(int register_num, string PIR) =item (string code) = pir_compiler(int register_num, string PIR, 1)

A thin wrapper for the <compreg>'d PIR compiler. Given inline PIR code, wrap it in anonymous subroutine and return the fully qualified PIR.

If the third argument is present, don't compile the wrapper sub, just return the wrapped code.

Argument register_num is the first register number that is available for use by the generated PIR.

int pos = skip_comment(string tcl_code, int pos)

Checks for a comment and returns either the original pos or the position after the comment.

    Incoming: # comment\n
              ^
    Outgoing: # comment\n
                       ^^
(pmc command, int pos) = get_command(string tcl_code, pmc chars, int pos)

Tries to get a command from the Tcl code at pos, stopping at the first character that's ord value exists in the chars hash.

    Incoming: puts [lindex "a b c" 1]
                    ^
    Outgoing: puts [lindex "a b c" 1]
                                    ^
(pmc word, int pos) = get_word(string tcl_code, pmc chars, int pos)

Parses a word, starting at pos and ending at the first character that's ord value exists in the chars hash. Returns either a TclWord object or a TclConst, TclCommand, or TclVar object if the Tclword contains only one.

    Incoming: puts foo\n
              ^
    Outgoing: puts foo\n
                      ^^
(pmc word, int pos) = get_quote(string tcl_code, pmc chars, int pos)

Parses a quote and returns a TclWord object containing the separate parts (or, if there's only one, it's child).

    Incoming; puts [lindex "a b c" 1]
                           ^
    Outgoing: puts [lindex "a b c" 1]
                                 ^
(pmc const, int pos) = get_brace(string tcl_code, pmc chars, int pos)

Parses a {} quoted expression, returning a TclConst object.

    Incoming: puts {foo}
                   ^
    Outgoing: puts {foo}
                       ^
(pmc command, int pos) = get_subcommand(string tcl_code, int pos)

Parses a subcommand and returns a TclCommand or TclCommandList object.

    Incoming: puts [lindex "a b c" 1]
                   ^
    Outgoing: puts [lindex "a b c" 1]
                                     ^
(pmc var, int pos) = get_variable(string tcl_code, int pos)

If it's really a variable, returns a TclVar object. If it's something else, return a TclConst object.

    Incoming: puts $foo\n
                   ^
    Outgoing: puts $foo\n
                       ^^
(int register_num, str code) = compile_dispatch(pmc thing, int register_num)

Given an object, call its compile method, or, if it's constant, generate code on its behalf. Returns PIR code.

Argument register_num is the first register number that is available for use by the generated PIR.

Return register_num is the register number that contains the result of this code.

POD ERRORS ^

Hey! The above document had some coding errors, which are explained below:

Around line 12:

Unknown directive: =head


parrot