NAME
Language::Basic::Statement - Module to handle parsing and implementing single BASIC statements.
STATEMENT OVERVIEW
See Language::Basic for the overview of how the Language::Basic module works. This pod page is more technical.
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.
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 subclass.
Each LBS subclass then has a parse routine, which is called with a ref to text, and an implement routine. The parse routine goes through the text and digests it (a ref is passed so that the next statement knows where to start parsing, e.g., in an IF/THEN), and sets various fields in the object. The implement routine uses the fields to implement the BASIC command.