The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

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 & bless it to an LBS::* subclass
    my $statement = new Language::Basic::Statement \("GOTO 20");
    $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. After that, LB::Statement::new is called with a ref to the text on the line.

LBS::new simply creates an LBS object. However, it then calls LBS::refine, which looks at the first word 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. The implement method uses the fields to implement 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.