NAME

Language::Basic::Expression - Package to handle string, numeric, and conditional expressions.

SYNOPSIS

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

Expressions are basically the building blocks of Statements, in that every BASIC statement is made up of keywords (like GOTO, TO, STEP) and expressions. So expressions includes not just the standard arithmetic expressions (like 1 + 2), but also lvalues (scalar variables or arrays), functions, and constants. See the Syntax file included with the Language::Basic distribution for details on the way expressions are built.

DESCRIPTION

Each subclass has (at least) three methods:

parse

takes a string ref and digests it (or returns undef if the string's syntax doesn't match that subclass)

evaluate

actually calculates the value of the expression. For a string or numeric constant or variable, that just means taking the stored value of that object. For other Expressions, you actually need to do math.

output_perl

Gives a string with the Perl equivalent to a BASIC expression. "1+2" is converted to "1+2", but "A" becomes "$a", "A$" becomes "$a_str", and function calls may be even more complicated.

The Expression subclasses closely follow the BASIC grammar. Most subclasses can have their own String and Numeric subclasses in turn. This allows us to make sure that you don't try to multiply strings together, etc.