XFA Specification
Chapter 23, FormCalc Specification
Grammar and Syntax
816
The value of the PrimaryExpression is the value of its constituent Literal
13
90
67
Declaration Expressions: Variables and User-Defined Functions
83 Expression ::= DeclarationExpression | ...
84 DeclarationExpression ::=
'var' Variable |
'var' Variable '=' SimpleExpression |
'Func'
Identifier '(' ParameterList ')' do ExpressionList 'EndFunc'
85 AssignmentExpression ::= Variable '=' Variable | SimpleExpression
Assignment Expressions are described on
page 817.
Variables and user-defined functions are objects that reside in
FormCalc
storage, as opposed to objects
that reside in the processing application's object model. Each variable or function has a
scope,
which is
that region of a FormCalculation where the variable is known. The scope of a variable begins at its
declaration and persists to the end of a block.
See “Block Expressions, Explicit and Implied” on page 824.
Variables
One kind of DeclarationExpression
83
FormCalc
variable identified by the
Variable
identifier
and assigns it the value of the SimpleExpression
67
SimpleExpression is omitted. The value of this kind of DeclarationExpression is the value assigned to the
variable.
In the following example, the variable comes into existence and is given the empty string value, before the
SimpleExpression is ever evaluated.
Declaration
var
Variable
= SimpleExpression
Is semantically equivalent to the expression list …
var
Variable Variable
= SimpleExpression
When used on the left-hand side of an AssignmentExpression
85
, the storage contents of the variable
identified are modified, and when used in a SimpleExpression
67
identified are retrieved.
The names of
FormCalc
variables are case sensitive. Thus, in the following valid example, variables A and a
coexist.
var A = 1;
var a = 2;
declare variable A and assign it the value 1.
declare variable a and assign it the value 2.
User-Defined Functions
Another kind of DeclarationExpression
83
FormCalc
user-defined function. Such a declaration is
identified by the
func
identifier. It also allocates memory for passing parameters to the function and for
the expressions bracketed by the
do
and
endfunc
expressions.
The value returned from the function is the last value calculated by the function. That is, there is not return
statement, as with C-language functions.
If FormCalc provides a built-in function with the same name as a user-defined function, FormCalc invokes
the built-in function.
The following example shows a function being declared and that same function being called.
func MyFunction(param1) do param1*param1 endfunc // Declares a function