Op is one of asignment operators: '=', '+=', '-=', '*=', '/=', '&=', '~=', '^=', '%=', '|=', '<<=', '>>='. The reduced modifier is used to avoid a memory leak. The reduced assignment[Reduced] ['&'] ['*'] Expr1 Op ['&' '*'] Expr2 ';'
meansreduced A = E;
if A is array and E is element of A. Otherwise it means:Dim temp = E; E = NULL; delete A; A = temp;
delete A; A = E;
The * operator at the left part of the assignment statement should be used only when Expr1 is alias and & operator is presented at the right part of the statement. (Because * Expr1 = Expr2 produces the same assignment as Expr1 = Expr2 in all another cases). When & operator is presented at the right part, the use of * operator in the left part allows you to assign alias of Expr2 to terminal of Expr1. For example:
It producesvariant A[10], B, C, P; B = 300; C = 500; P = & A[5]; * P = & B; println(P); println(A[5]); P = & C; println(A[5]); println(P);
The * at the left part of the assignment statement should be used only when Expr2 is an alias. In this case, the use of * allows you to assign Expr1 as alias of terminal of Expr2. For example300 300 300 500
This example illustrates how the search of most general unifier works (mechanical theorem proving). T1 and T2 represent terms, P1 and P2 are parameters of T1 and T2 accordingly. The last statementvariant P1 = "X"; variant P2 = "Y"; variant T1 = ["R", ["F", & P1]]; variant T2 = ["R", & P2]; variant Q1 = & T1[1]; variant Q2 = & T2[1]; * Q2 = & (* Q1);
changes parameters, not source terms.* Q2 = & (* Q1);
Executing the break statement exits from the current loop or statement, and begins script executionGrammar
BreakStmt -> break [Label] ';'Arguments
LabelExample
var i = 0; for (;;) { print i; i++; if (i == 5) break; }See Also
- Continue Statements
/ul>
Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class.Grammar
ClassStmt -> class Ident [':' Ancestor] '{' MemberStatement /... '}' MemberStatement -> VarStmt | FunctionStmt | PropertyStmt |Arguments
IdentName of the class.AncestorOptional. Name of the ancestor class.MemberStatementExample of classOne or more statements that define the variables, properties, and methods of the class.Example 1
namespace Shapes { class Point { private int x, y; function Point(int x, int y){ this.x = x; this.y = y; } } class Circle: Point { private int r; function Circle(int x, int y, int r): base(x, y) { this.r = r; } } } // namespace var P = new Shapes.Point(2, 3), C = new Shapes.Circle(3, 5, 7); print P, C;All constructors must have name which coincide with the name of the class. Each class must have at leat one constructor.Classes can have static (shared) members. The definition of a static member must begin with the reserved word static. For example,
Example 2
class Foo { static var X; void Foo(){}; static void F(){}; }Here X, F and P are static members of class TFoo.See Also
A compound statement is a sequence of other (simple or structured) statements to be executed in the order in which they are written.Grammar
CompoundStmt -> '{' Statements '}'Arguments
StatementsOne or more statements.Example
{ Z = X; X = Y; Y = Z; }
The continue statement stops the current iteration of a loop, and starts a new iteration.Grammar
ContuinueStmt -> continue [Label] ';'Arguments
LabelOptional. Specifies the statement to which continue applies. A local variable (declared in the block containing the for statement) without any qualifiersExample
for (var i = 0; i < 5; i++) { if (i == 3) continue; print i; }See Also
- Break Statements
/ul>
Destroys variable or its terminalGrammar
DeleteStmt -> Delete ['*'] Expression
Executes a statement block once, and then repeats execution of the loop until a condition expression evaluates to false.Grammar
DoStmt -> do Statement while '('Expression')' ';'Arguments
StatementOptional. The statement to be executed if expression is true. Can be a compound statement.ExpressionAn expression that can be coerced to Boolean true or false. If expression is true, the loop is executed again. If expression is false, the loop is terminated.See Also
Creates enumeration type.Grammar
EnumStmt -> enum '{' Ident {'=' Number} /','...'}'Example
enum E { A, B = 10, C } E x; print x.A; print x.B; print x.C;
Executes a block of statements for as long as a specified condition is true.Grammar
ForStmt -> for '(' [Init] ';' [Test] ';' [Incr] ')' StatementsArguments
InitRequired. An expression. This expression is executed only once, before the loop is executed.TestRequired. An expression. The increment expression is executed at the end of every pass through the loop.StatementsYou usually use a for loop when the loop is to be executed a specific number of times.Optional. One or more statements to be executed if test is true. Can be a compound statement.Example
for (i = 0; i < 10; i++) { myarray[i] = i; }i is set to 0 at start, and is incremented by 1 at the end of each iteration. Loop terminates when i is not less than 10 before a loop iteration.See Also
Declares the name, arguments, and code that form the body of a function.Grammar
FunctionStmt -> [static] [function] TypeName Ident ['(' FormalParam/','... ')'] '{' [Statements] '}' FormalParam -> [var] ParameterArguments
IdentThe name of the function.ParameterRepresents formal parameter of function. The var keyword indicates that the argument is passed by reference.StatementsOptional. One or more statementsStaticOptional. The class keyword specifies a static (shared) method of a class. Can be used only inside of a class body.Example 1
int Fact(N) { if (N == 1) return 1; else return N * Fact(N - 1); }You can use the function statement inside of a class body. In such case the statement declares a method of the class.Example 2
class MyClass: TObject { string Z = 'abc'; void MyClass(Z) {this.Z = Z} string DoubleZ() {return Z + Z;} static void Hello() {return 'Hello ' + ClassName}; }See Also
Transfers program execution to a labeled statement.Grammar
GotoStmt -> goto Label ';'Arguments
LabelA unique identifier used when referring to the labeled statement.Example
var i = 0; for (;;) { i++; if (i == Random(100)) goto L; } L: print i;See Also
- Labeled Statements
/ul>
Conditionally executes a group of statements, depending on the value of an expression.Grammar
IfStmt -> if '(' Condition ')' Statement1 [ else Statement2 ]Arguments
ConditionA Boolean expression. If condition is null or undefined, condition is treated as false.Statement1The statement to be executed if condition is true. Can be a compound statement.Statement2Optional. The statement to be executed if condition is false. Can be a compound statement.Example 1
if (y = 6) z = 17;Example 2
if (x > 0) s = 1; else s = -1;See Also
- Switch Statements
/ul>
Provides an identifier for a statement.Grammar
LabeledStmt -> Label ':' Statement ';'Arguments
LabelA unique identifier used when referring to the labeled statement.See Also
SnugPascal programs are organized using namespaces. You can consider the namespace as a class which contains only static (shared) members.Grammar
NamespaceStmt -> namespace '{' Statements '}'Arguments
StatementsOne or more statementsExample
namespace Shapes { class Point { private int x, y; function Point(int x, int y){ this.x = x; this.y = y; } } class Circle: Point { private int r; function Circle(int x, int y, int r): base(x, y) { this.r = r; } } } // namespace var P = new Shapes.Point(2, 3), C = new Shapes.Circle(3, 5, 7); print P, C;See Also
- Class Statements
/ul>
Prints value of an expression.Grammar
PrintStmt -> print Expression/','... ';'Example
print 4 * 100 / 7;
A property, like a field, defines an attribute of an object. But while a field is merely a storage location whose contents can be examined and changed, a property associates specific actions with reading or modifying its data. Properties provide control over access to an object’s attributes, and they allow attributes to be computed.Grammar
PropertyStmt -> property Ident [ParamList] '{' [ get '{' GetStatements '}' ] [ set '{' SetStatements '}' ] '}' ParamList -> '[' Param/','... ']'Arguments
IdentName of the property. If Ident is 'this', this is an indexed propertyParamParameter of indexed propertyGetStatementsAny group of statements to be executed within the body of the Property Get procedure.SetStatementsAny group of statements to be executed within the body of the Property Set procedure.Example
class MyClass { var fZ = [10, 20, 30, 40, 50]; function MyClass(){} property this[I] { get { return fZ[I]; } set { fZ[I] = Value; } } } var X = new MyClass(); X[1] = 90; print x;See Also
- Class Statements
/ul>
Exits from the current function and returns a value from that function.Grammar
ReturnStmt -> return [Expression] ';'Arguments
ExpressionOptional. The value to be returned from the function. If omitted, the function does not return a value.Example
function Fact(N) { if (N == 1) return 1; else return N * Fact(N - 1); }See Also
- Function Statements
/ul>
Declares the name of a structure, as well as a definition of the variables, properties, and methods that comprise the structure.Grammar
StructureStmt -> structure Ident [':' Ancestor] '{' MemberStatement /... '}' MemberStatement -> VarStmt | FunctionStmt | PropertyStmt |Arguments
IdentName of structureAncestorOptional. Name of ancestor structure type.MemberStatementOne or more statements that define the variables, properties, and methods of the structure.Example
structure RandomPoint { int X = random(0, 100); int y = random(0, 100); } structure RandomCircle: RandomPoint { int R = random (0, 100); } RandomCircle C; print C;
Enables the execution of one or more statements when a specified expression's value matches a label.Grammar
SwitchStmt -> switch '(' Expression ')' '{' case Label ':' StatementList /... [default ':' StatementList] '}'Arguments
ExpressionThe expression to be evaluated.LabelAn identifier to be matched against expression. If label equal to Expression, execution starts with the StatementList immediately after the colon, and continues until it encounters either a break statement, which is optional, or the end of the switch statement.StatementListOne or more statements to be executed.defaultOptional. Provides a statement to be executed if none of the label values matches expression. It can appear anywhere within the switch code block.Example
switch (P) { case 1: print 'one'; break; case 2: case 3: case 4: case 5: print 'two'; break; default: print 'three'; }See Also
- If Statements
/ul>
Generates an error condition that can be handled by a try...catch…finally statement.Grammar
ThrowStmt -> throw [Ident] ';'Arguments
IdentAny expression.Example
try { throw 100; } catch (e) { print 'catch'; print e; } finally { print 'finally'; } print 'here';See Also
- Try Statements
/ul>
Implements error handling.Grammar
TryStmt -> try '{' TryStatements '}' catch '(' E ')' '{' CatchStatements '}' finally '{' FinallyStatements '}'Arguments
TryStatementsRequired. Statements where an error can occur.CatchStatementsOptional. Statements to handle errors occurring in the associated TryStatements.FinallyStatementsThe TryStatements contain code where an error can occur, while CatchStatements contain the code to handle any error that does occur. If an error occurs in the TryStatements, program control is passed to CatchStatements for processing. The initial value of exception is the value of the error that occurred in TryStatements. If no error occurs, CatchStatements are never executed.Optional. Statements that are unconditionally executed after all other error processing has occurred.Example
try { throw 100; } catch (e) { print 'catch'; print e; } finally { print 'finally'; } print 'here';See Also
- Throw Statements
/ul>
Using statements are provided to facilitate the use of namespaces.Grammar
UsingStmt -> using NamespaceName, /','... ';'Example
using StdCtrls, Forms; var F = new TForm(NULL), B = new TButton(F); F.Show(); B.Parent = F; B.OnClick = & AHandler; B.Caption = 'Click Me'; function AHandler(Sender){ print 'You have clicked the button'; }See Also
- Namespace Statements
/ul>
Declares a variable.Grammar
VarStmt -> [static] [var] [TypeName] Variable ['['Subscripts']'] [ = Value ] /,... ';' Subscripts -> Upperbound /','...Arguments
VariableThe name of the variable being declared.ValueThe initial value assigned to the variablestaticOptional. The static keyword specifies a static (shared) field of a class. Can be used only inside of a class body.SubscriptsDimensions of an array variable.UpperboundUse the var statement to declare variables. These variables can be assigned values at declaration or later in your script.Upper bound. The lower bound of an array is always zero.Example 1
var A(30, 4); var X = [10, 20, 30]; var Y; var Z = new TObject();You can use the var statement inside of a class body. In such case the statement declares a field of a class instance or a static (shared) field of the class.Example 2
class MyClass var A(10, 2), X; var Y = [100, 200, 300]; static var Z = 5; function MyClass(){} end;See Also
- Class Statements
/ul>
The while statement executes its constituent statement repeatedly, testing Condition expression before each iteration. As long as Condition returns True, execution continues.Grammar
WhileStmt -> while '(' Condition ')' StatementArguments
ConditionA Boolean expression. If condition is null or undefined, condition is treated as false.StatementThe statement to be executed if Condition is true. Can be a compound statementExample
while (Data[I] <> X) ++I;See Also
The with statement is a shorthand for referencing the the fields, properties, and methods of an object.Grammar
WithStmt -> with '(' Obj/','... ')' StatementArguments
ObjA variable reference denoting an objectStatementAny simple or compound statement.Example
with (Form1) { Caption = 'My Form'; Height = 200; Width = 300; }See Also
- Class Statements
/ul>