|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||
See:
Description
| Interface Summary | |
|---|---|
| Parser.yyInput | must be implemented by a scanner object to supply input to the parser. |
| Class Summary | |
|---|---|
| AbstractVisitor | Contains the base functionality for traversing ASTs build using the Node class. |
| BPL | Program driver. |
| Env<T> | Represents a stack of envorinment layers (frames). |
| EnvLayer<T> | Contains symbols names and values. |
| Interpreter | Interprets a BPL tree. |
| Parser | |
| TypeChecker | Tree visitor which does type checking. |
| ValueStack | A stack implementation based off of LinkedList. |
| Exception Summary | |
|---|---|
| Parser.yyException | thrown for irrecoverable syntax errors and stack overflow. |
| PositionException | Exception which has information about where in the input the error was that caused the exception |
| TypeException | A PositionException caused by a type error. |
;
statement2;
{
blockStatement1;
.
.
.
blockStatementn;
}
| Expression Type | Expression Description | Precedence | Associativity |
|---|---|---|---|
| Numeric Constant | This evaluates to the given numeric constant | - | - |
| Boolean Constant | This evaluates to the given boolean constant | - | - |
| String Constant | This evaluates to the given string constant | - | - |
| Variable | This evaluates to value of the variable | - | - |
expr1 && expr2
| This evaluates to true if expr1 and expr2 both evaluate
to true value and to false otherwise.
expr1 and expr2 must be boolean expressions | 1 | Left |
expr1 || expr2
| This evaluates to false if both expr1 and expr2
evaluate to false, and to true otherwise;
expr1 and expr2 must be boolean expressions. | 1 | Left |
expr1 > expr2
| This evaluates to true if expr1 is numerically greater than expr2
and false otherwise.
expr1 and expr2 must be integer expressions. | 2 | Left |
expr1 < expr2
| This evaluates to true if expr1 is numerically less than expr2
and false otherwise.
expr1 and expr2 must be integer expressions. | 2 | Left |
expr1 >= expr2
| This evaluates to true if expr1 is numerically greater than or equal to expr2
and false otherwise.
expr1 and expr2 must be integer expressions. | 2 | Left |
expr1 <= expr2
| This evaluates to true if expr1 is numerically less than or equal to expr2
and false otherwise.
expr1 and expr2 must be integer expressions. | 2 | Left |
expr1 == expr2
| This evaluates to true if expr1 is equal to expr2
and false otherwise. The expressions may be of any type.
Both expressions must be of the same type for the expression to evaluate to true.
Integers will be compared numerically. Booleans will be compared to see if they contain
the same truth value. String values will compared to each other lexographically to see if they
contain the same sequence of characters. Comparisons of objects and functions will only evaluate
to true if the object or function is compared to itself.
| 2 | Left |
expr1 != expr2
| This evaluates to true if expr1 is NOT equal to expr2
and false otherwise. Will return false where an equality test would return true and vice-versa.
| 2 | Left |
expr1 + expr2
| This evaluates to the sum of expr1 and expr2 | 3 | Left |
expr1 - expr2
| This evaluates to expr2 subtracted from expr1.
expr1 and expr2 must be integer expressions. | 3 | Left |
expr1 * expr2
| This evaluates to the product of expr1 and expr2. expr1 and expr2 must be integer expressions. | 4 | Left |
expr1 / expr2
| This evaluates to the integer quotient of expr1 divided by expr2. expr1 and expr2 must be integer expressions. | 4 | Left |
expr1 % expr2
| This evaluates to the remainder of expr1 divided by expr2. expr1 and expr2 must be integer expressions. | 4 | Left |
| - expr | This evaluates to the negation of expr
expr must be be an integer expression. | 5 | Right |
| + expr | This evaluates to expr
expr must be be an integer expression. | 5 | Right |
| ( expr ) | This evaluates to expr | 6 | None |
true and false keywords.
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>;
var keyword is dropped. Variables must be declared before they can be assigned to.
if ( <expression> ) statementOrBlock [ else statementOrBlock ]
if clause is controlled by an expression. If the expression evaluates to to a boolean true
the code associated with the if the expression with be evaluated. An else clause may
optionally be appended. If the if evaluates to boolean false, the code associated with the else
will be executed.
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;
}
while ( <expression> ) statementOrBlock
while ( <expression> ) statement;
while ( <expression> )
{
statement1;
.
.
.
statementn;
}
function keyword. Functions may take 0 or more arguments
and return a value, or may choose to return nothing. Method return may be effected using the return keyword. A
return statement is not required at the end of a function definition. However, if the last statement in a function
is not a return, then the compiler/interpreter will insert a void return. Since all returns from a function
must return values of the same type, this may cause problems if you are returning a value from elsewhere in the function.
Functions are generally declared as anonymous, then assigned to a variable.
var functionName = function ( arg1, arg2, ..., argn ) {
.
.
// function code goes here
.
.
}
var sum = function( num1, num2 ) {
return num1 + num2;
};
function sum ( num1, num2 ) {
return num1 + num2;
}
Given a function stored in a variable f, it can be invoked
( arg1, arg2, ..., argn );
var a = 1;
var b = 2;
var c = function()
{
var b = 4;
print a + " " + b;
};
c();
1 4 being outputted.
var ValidIdentifier = {
ValidIdentifier1 : expression1,
ValidIdentifier2 : expression2,
.
.
.
ValidIdentifiern : expressionn
};
var employee1 = {
first : "John",
second : "Smith",
empId : nextId(),
age : 30,
currentlyEmployed : true,
rightSize : function() {
currentlyEmployed = false;
}
};
|
|||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | ||||||||