The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Language::Basic::Statement - Package to handle parsing and implementing single BASIC statements.

SYNOPSIS

See Language::Basic for the overview of how the Language::Basic module works. This pod page is more technical.

A Statement is something like 'GOTO 20' or 'PRINT "HELLO"'. A line of BASIC code is made up of one or more Statements.

    # Create the statement from an LB::Token::Group and
    # bless it to an LBS::* subclass
    my $statement = new Language::Basic::Statement $token_group;
    $statement->parse; # Parse the statement
    $statement->implement; # Implement the statement

    # Return a string containing the Perl equivalent of the statement
    $str = $statement->output_perl; 

DESCRIPTION

Take a program like:

 5 LET A = 2

 10 IF A >= 3 THEN GOTO 20 ELSE PRINT "IT'S SMALLER"

Line 5 has just one statement. Line 10 actually contains three. The first is an IF statement, but the results of the THEN and the ELSE are entire statements in themselves.

Each type of statement in BASIC has an associated LB::Statement class. For example, there's LB::Statement::Let and LB::Statement::If. (But no LB::Statement::Then! Instead the "then" field of the LB::Statement::If object will point to another statement. In the above program, it would point to a LB::Statement::Goto.)

Parsing a line of BASIC starts with removing the line number and lexing the line, breaking it into Tokens which are held in an LB::Token::Group. LB::Statement::new, refine, and parse, are all called with a Token::Group argument. These methods gradually "eat" their way through the Tokens.

LBS::new simply creates an LBS object. However, it then calls LBS::refine, which looks at the first Token of the command and blesses the object to the correct LBS::* subclass.

Each LBS subclass then has (at least) the methods parse, implement, and output_perl.

The parse method goes through the text and digests it and sets various fields in the object, which are used by implement and output_perl. The implement method actually implements the BASIC command. The output_perl method returns a string (with ; but not \n at the end) of the Perl equivalent of the BASIC statement.