Back to BPL Home

See:
          Description

Packages
edu.rit.bja8464.cc.bpl  
edu.rit.pal6640.cc.bpl
edu.rit.pal6640.cc.bpl.node  
edu.rit.pal6640.cc.bpl.value  

 

Back to BPL Home

BPL User Manaul

  1. Introduction
  2. Whitespace
  3. Statements and Blocks
  4. Expressions
  5. Variables
    1. Declaration
    2. Assignment
  6. Objects
  7. Functions
  8. Control structures
    1. Selection
    2. Iteration

Introduction

This is the user manual for BPL, a JavaScript-like language. It has first class functions and closures, objects, numeric types and string types. It has simple selection (if) and iteration (while) control structures. It also allows nested blocks of statements with local variables.

Whitespace

Whitespace including newlines is not significant and does not affect program execution, except where noted. Note that BPL keywords, identifiers and operators may not contain whitespace.

Statements and Blocks

A BPL program is made up of statements. Types of statements include variable declaration and assignment as well as control structures. Statements which are not control structures may span lines and are semicolon terminated. Statements may be enclosed in a block. A block is defined by a starting and ending braces as follows.
statement1; statement2; { blockStatement1; . . . blockStatementn; }

Expressions

BPL statements may contain expressions. Expressions are program elements which evaluate to integer, string, object, or function types. When expressions are being evaluated, the precedence will be used to determine in what order sub-expressions will be evaluated. The higher the precedence, the sooner the sub expression will be evaulated.
Expression Type Expression Description Precedence Associativity
Numeric Constant This evaluates to the given numeric constant - -
String Constant This evaluates to the given string constant - -
{ ident: expr, ... } This evaluates to the given object contant. This results in a new object containing string keys assciated with their respective values - -
ident This evaluates to value of the variable - -
lambda(ident, ... ) {
statement1;
...;
statementn;
}
This evaluates to a new function closure with the given formal arguments and body - -
expr1 && expr2 This evaluates to 1 if expr1 and expr2 both evaluate to non-zero values and to 0 otherwise. - -
expr1 || expr2 This evaluates to 0 if both expr1 and expr2 evaluate to 0, and 1 otherwise; 1 Left
expr1 > expr2 This evaluates to 1 if expr1 is numerically greater than expr2 and 0 otherwise; 2 Left
expr1 < expr2 This evaluates to 1 if expr1 is numerically less than expr2 and 0 otherwise; 2 Left
expr1 >= expr2 This evaluates to 1 if expr1 is numerically greater than or equal to expr2 and 0 otherwise; 2 Left
expr1 <= expr2 This evaluates to 1 if expr1 is numerically less than or equal to expr2 and 0 otherwise; 2 Left
expr1 == expr2 This evaluates to 1 if expr1 is numerically equal to expr2 and 0 otherwise; 2 Left
expr1 != expr2 This evaluates to 1 if expr1 is numerically NOT equal to expr2 and 0 otherwise; 2 Left
expr1 + expr2 This evaluates to the sum of expr1 and expr2 3 Left
expr1 - expr2 This evaluates to expr2 subtracted from expr1 3 Left
expr1 * expr2 This evaluates to the product of expr1 and expr2 4 Left
expr1 / expr2 This evaluates to the integer quotient of expr1 divided by expr2 4 Left
expr1 % expr2 This evaluates to the remainder of expr1 divided by expr2 4 Left
- expr This evaluates to the negation of expr 5 Right
+ expr This evaluates to expr 5 Right
( expr ) This evaluates to expr 6 None
expr . ident This looks up the key "ident" in expr. It is syntactic sugar for expr["ident"] (see below). 6 None
expr1[expr2] This looks up the value of expr2 in expr1. 6 None
exprf(expr1, ..., exprn) Evaluates exprf (which must be a function value) and invokes it with the arguments expr1 ,,, exprn. 6 None

Variables

BPL allows the definition of global and local variables. Global variables are those defined at the top level. Local variables are those defined in the scope of a block, including blocks in control statements.

Declaration

All BCL variables are of type integer. Valid variable values are natural numbers in the range (-231, 231-1) inclusive. Variables are declared using the keyword var. Variables must be named using a valid identifier. A valid identifier begins with a letter and may contain letters, nummbers and the underscore '_'. Variable names may not include whitespace. Variables may optionally be declared with an initial value. Variables may be initialized to an expression, which includes constant values. If a variable is not declared, it will be assigned the default value of 0.
var ValidIdentifier; var ValidIdentifier = <expression>;
Variables may be declared at any point in the program, not just at the beginning of the program or of blocks. Variables must be declared before they can be referenced.

Assignment

Variable assignment is similar to variable declaration with an initializing value, except that the var keyword is dropped. Variables must be declared before they can be assigned to.
ValidIdentifier = <expression>;

Objects

FIXME

Basically, hashtables whose keys are arbitrary objects. var h = {} makes a new one, h[expr] = val; puts val to the key that results from the evaluation of expr.

Functions

FIXME

Functions are first class values that close over their lexical scope. They can take any number of arguments. var incBy = lambda(x) { return lambda(y) { return x + y; }; }; var f = incBy(2); var x = f(5); // x is 7

Control Structures

BPL includes two flow control structres, one for selection, the other for iteration.

Selection

For selection BPL uses an if-else control structure of the form
if ( <expression> ) statementOrBlock [ else statementOrBlock ]
The if clause is controlled by an expression. If the expression evaluates to to a non-zero value, the code associated with the if the expression with be evaluated. An else clause may optionally be appended. If the if evaluates to 0, the code associated with the else will be executed.
Valid forms of the if-else
if ( <expression> ) statement; if ( <expression> ) { statement1; . . . statementn; } if ( <expression> ) statement; else statement; if ( <expression> ) { statement1; . . . statementn; } else statement; if ( <expression> ) statement; else { statement1; . . . statementn; } if ( <expression> ) { statement1; . . . statementn; } else { statement1; . . . statementn; }

Iteration

For iteration BPL uses a while construct of the form
while ( <expression> ) statementOrBlock
While the expression specified evaluates to a non-zero value, the statement or block following the while will execute. The while loop may take the following forms
while ( <expression> ) statement; while ( <expression> ) { statement1; . . . statementn; }