c_stmt.htm

来自「Delphi脚本控件」· HTM 代码 · 共 1,345 行 · 第 1/3 页

HTM
1,345
字号
<html>
<head>
<link rel=stylesheet type="text/css" href="styles.css">
</head>
<body>
<H3>
paxC Statements
</H3>
<hr>
<ul>
<li><a href="#Assignment Statements">Assignment Statements</a></li>
<li><a href="#Break Statements">Break Statements</a></li>
<li><a href="#Class Statements">Class Statements</a></li>
<li><a href="#Compound Statements">Compound Statements</a></li>
<li><a href="#Continue Statements">Continue Statements</a></li>
<li><a href="#Delete Statements">Delete Statements</a></li>
<li><a href="#Do Statements">Do Statements</a></li>
<li><a href="#Enum Statements">Enum Statements</a></li>
<li><a href="#For Statements">For Statements</a></li>
<li><a href="#Function Statements">Function Statements</a></li>
<li><a href="#Goto Statements">Goto Statements</a></li>
<li><a href="#If Statements">If Statements</a></li>
<li><a href="#Labeled Statements">Labeled Statements</a></li>
<li><a href="#Namespace Statements">Namespace Statements</a></li>
<li><a href="#Print Statements">Print Statements</a></li>
<li><a href="#Property Statements">Property Statements</a></li>
<li><a href="#Return Statements">Return Statements</a></li>
<li><a href="#Structure Statements">Structure Statements</a></li>
<li><a href="#Switch Statements">Switch Statements</a></li>
<li><a href="#Throw Statements">Throw Statements</a></li>
<li><a href="#Try Statements">Try Statements</a></li>
<li><a href="#Using Statements">Using Statements</a></li>
<li><a href="#Var Statements">Var Statements</a></li>
<li><a href="#While Statements">While Statements</a></li>
<li><a href="#With Statements">With Statements</a></li>
<//ul>
<a name="Assignment Statements"><h3>Assignment Statements</h3></a>
<!-------------------------------------------------------------------->



<H4>
Grammar
</H4>

<blockquote>
<pre>
[<font color="blue"><b>Reduced</b></font>] ['&'] ['*'] Expr1 Op ['&' '*'] Expr2 ';'
</pre>
</blockquote>


Op is one of asignment operators: '=', '+=', '-=', '*=', '/=', '&=', '~=', '^=', '%=', '|=', '<<=', '>>='.

The reduced modifier is used to avoid a memory leak.


The reduced assignment 

<blockquote>
<pre>
<font color="blue"><b>reduced</b></font> A = E;
</pre>
</blockquote>

means

<blockquote>
<pre>
<font color="blue"><b>Dim</b></font> temp = E;
E = <font color="blue"><b>NULL</b></font>;
<font color="blue"><b>delete</b></font> A;
A = temp;
</pre>
</blockquote>


if A is array and E is element of A. Otherwise it means:

<blockquote>
<pre>
<font color="blue"><b>delete</b></font> A;
A = E;
</pre>
</blockquote>

<p>
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:


<blockquote>
<pre>
<font color="blue"><b>variant</b></font> 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);
</pre>
</blockquote>

It produces

<blockquote>
<pre>
300
300
300
500
</pre>
</blockquote>

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 example

<blockquote>
<pre>
<font color="blue"><b>variant</b></font> P1 = <font color="Red">"X"</font>;
<font color="blue"><b>variant</b></font> P2 = <font color="Red">"Y"</font>;
<font color="blue"><b>variant</b></font> T1 = [<font color="Red">"R"</font>, [<font color="Red">"F"</font>, & P1]];
<font color="blue"><b>variant</b></font> T2 = [<font color="Red">"R"</font>, & P2];
<font color="blue"><b>variant</b></font> Q1 = & T1[1];
<font color="blue"><b>variant</b></font> Q2 = & T2[1];
* Q2 = & (* Q1);
</pre>
</blockquote>


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 statement 

<blockquote>
<pre>
* Q2 = & (* Q1);
</pre>
</blockquote>

changes parameters, not source terms. 


</blockquote>
</blockquote>
<a name="Break Statements"><h3>Break Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Executing the break statement exits from the current loop or statement, and begins script execution
<H4>
Grammar
</H4>
<blockquote>
<pre>
BreakStmt -> <font color="blue"><b>break</b></font> [Label] <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Label</i>
<blockquote>

</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>var</b></font> i = 0;
<font color="blue"><b>for</b></font> (;;) {
  <font color="blue"><b>print</b></font> i;
  i++;
  <font color="blue"><b>if</b></font> (i == 5) <font color="blue"><b>break</b></font>;
}
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Continue Statements">Continue Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Class Statements"><h3>Class Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Declares the name of a class, as well as a definition of the variables, properties, and methods that comprise the class.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ClassStmt -> <font color="blue"><b>class</b></font> Ident [<font color="Red">':'</font> Ancestor] <font color="Red">'{'</font>
               MemberStatement /...
             <font color="Red">'}'</font>
		 
MemberStatement ->  VarStmt |
                    FunctionStmt |
                    PropertyStmt |
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Ident</i>
<blockquote>
Name of the class.
</blockquote>
</blockquote>
<blockquote>
<i>Ancestor</i>
<blockquote>
Optional. Name of the <font color="black"><i>ancestor</i></font> class.
</blockquote>
</blockquote>
<blockquote>
<i>MemberStatement</i>
<blockquote>
One or more statements that define the variables, properties, and methods of the class.
</blockquote>
</blockquote>
Example of class
<H4>
Example 1
</H4>
<pre>
<font color="blue"><b>namespace</b></font> Shapes {
  <font color="blue"><b>class</b></font> Point {
    <font color="blue"><b>private</b></font> <font color="blue"><b>int</b></font> x, y;
    <font color="blue"><b>function</b></font> Point(<font color="blue"><b>int</b></font> x, <font color="blue"><b>int</b></font> y){
      <font color="blue"><b>this</b></font>.x = x;
      <font color="blue"><b>this</b></font>.y = y;
    }
  }

  <font color="blue"><b>class</b></font> Circle: Point {
    <font color="blue"><b>private</b></font> <font color="blue"><b>int</b></font> r;
    <font color="blue"><b>function</b></font> Circle(<font color="blue"><b>int</b></font> x, <font color="blue"><b>int</b></font> y, <font color="blue"><b>int</b></font> r): <font color="blue"><b>base</b></font>(x, y) {
      <font color="blue"><b>this</b></font>.r = r;
    }
  }
} // <font color="blue"><b>namespace</b></font>

<font color="blue"><b>var</b></font>
  P = <font color="blue"><b>new</b></font> Shapes.Point(2, 3), C = <font color="blue"><b>new</b></font> Shapes.Circle(3, 5, 7);
<font color="blue"><b>print</b></font> P, C;
</pre>
All constructors must have name which coincide with the name of the class. Each class must have at leat one constructor.
<p> </p>
Classes can have static (shared) members. The definition of a static member must begin with the 
reserved word <b>static</b>. For example,
<H4>
Example 2
</H4>
<pre>
<font color="blue"><b>class</b></font> Foo {
  <font color="blue"><b>static</b></font> <font color="blue"><b>var</b></font> X;
  <font color="blue"><b>void</b></font> Foo(){};
  <font color="blue"><b>static</b></font> <font color="blue"><b>void</b></font> F(){};
}
</pre>
Here X, F and P are static members of class TFoo.
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Function Statements">Function Statements</a></li>
<li><a href="#Namespace Statements">Namespace Statements</a></li>
<li><a href="#Property Statements">Property Statements</a></li>
<li><a href="#Var Statements">Var Statements</a></li>
<//ul>
</blockquote>
</blockquote>
<a name="Compound Statements"><h3>Compound Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
A compound statement is a sequence of other (simple or structured) 
statements to be executed in the order in which they are written.
<H4>
Grammar
</H4>
<blockquote>
<pre>
CompoundStmt -> <font color="Red">'{'</font> Statements <font color="Red">'}'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Statements</i>
<blockquote>
One or more <font color="black"><i>statements</i></font>.
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
{
  Z = X;
  X = Y;
  Y = Z;
}
</pre>
</blockquote>
<a name="Continue Statements"><h3>Continue Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
The continue statement stops the current iteration of a loop, and starts 
a new iteration.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ContuinueStmt -> <font color="blue"><b>continue</b></font> [Label] <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Label</i>
<blockquote>
Optional. Specifies the statement to which continue applies. A local variable (declared in the block containing the for statement) without any qualifiers
</blockquote>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>for</b></font> (<font color="blue"><b>var</b></font> i = 0; i < 5; i++) {
  <font color="blue"><b>if</b></font> (i == 3) <font color="blue"><b>continue</b></font>;
  <font color="blue"><b>print</b></font> i;
}
</pre>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#Break Statements">Break Statements</a></li>
<//ul>
</blockquote>
</blockquote>


<a name="Delete Statements"><h3>Delete Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Destroys variable or its terminal
<H4>
Grammar
</H4>

<blockquote>
<pre>
DeleteStmt -> <font color="blue"><b>Delete</b></font> ['*'] Expression 
</pre>
</blockquote>
</blockquote>


<a name="Do Statements"><h3>Do Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Executes a statement block once, and then repeats execution of the loop until a condition expression evaluates to false.
<H4>
Grammar
</H4>
<blockquote>
<pre>
DoStmt -> <font color="blue"><b>do</b></font> Statement <font color="blue"><b>while</b></font> <font color="Red">'('</font>Expression<font color="Red">')'</font> <font color="Red">';'</font>
</pre>
</blockquote>
<H4>
Arguments
</H4>
<blockquote>
<i>Statement</i>
<blockquote>
Optional. The <font color="black"><i>statement</i></font> to be executed if <font color="black"><i>expression</i></font> is true. Can be a compound <font color="black"><i>statement</i></font>.
</blockquote>
</blockquote>
<blockquote>
<i>Expression</i>
<blockquote>
An <font color="black"><i>expression</i></font> that can be coerced to Boolean true or false. If <font color="black"><i>expression</i></font> is true, the loop is executed again. If <font color="black"><i>expression</i></font> is false, the loop is terminated.
</blockquote>
</blockquote>
<H4>
See Also
</H4>
<blockquote>
<ul>
<li><a href="#For Statements">For Statements</a></li>
<li><a href="#While Statements">While Statements</a></li>
<//ul>
</blockquote>
</blockquote>


<a name="Enum Statements"><h3>Enum Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Creates enumeration type.
<H4>
Grammar
</H4>
<blockquote>
<pre>
EnumStmt -> <font color="blue"><b>enum</b></font> <font color="Red">'{'</font> Ident {<font color="Red">'='</font> Number} /<font color="Red">','</font>...<font color="Red">'}'</font>
</pre>
</blockquote>
<H4>
Example
</H4>
<pre>
<font color="blue"><b>enum</b></font> E { A, B = 10, C }
E x;
<font color="blue"><b>print</b></font> x.A;
<font color="blue"><b>print</b></font> x.B;
<font color="blue"><b>print</b></font> x.C;
</pre>
</blockquote>
<a name="For Statements"><h3>For Statements</h3></a>
<!-------------------------------------------------------------------->
<blockquote>
Executes a block of statements for as long as a specified condition is true.
<H4>
Grammar
</H4>
<blockquote>
<pre>
ForStmt -> <font color="blue"><b>for</b></font> <font color="Red">'('</font> [Init] <font color="Red">';'</font> [Test] <font color="Red">';'</font> [Incr] <font color="Red">')'</font>
             Statements
</pre>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?