FormCalc vs Javascript [PDF / XFA in HTML5]

XFA_icon

XFA files are complex

This is one of the articles in the XFA series index which investigates the important factors to be considered during the conversion from FormCalc script to Javascript (since none of the current browsers supports formcalc script, therefore the conversion to Javascript is a prerequisite in HTML5) please click here to learn some more interesting stuff about XFA manipulation.

Prior to diving into the conversion we should separate out the keywords, operators and separators used in the FormCalc script.

This separation would be helpful to allow for the replacing the tags with related Javascript supported tags.

Keywords

 [“and”, “else”, “elseif”, “endif”, “eq”, “ge”, “gt”, “if”, “infinity”,”le”, “lt”, “nan”, “ne”, “not”, “null”, “or”, “then”, “this”, “break”, “continue”,”do”, “downto”, “end”, “endfor”, “endfunc”, “endwhile”, “exit”, “for”, “foreach”,”func”, “in”, “return”, “step”, “throw”, “upto”, “var”, “while”];

Operators

[“+”, “{“, “}”, “-“, “%”, “*”, “/”, “;”, “{“, “}”];

Separators

[“(“, “)”, “[“, “]”, “,”, “.”, “..”, “.#”, “.*”];

Some example of replacement

Operational

FormCalcJavascript
 and&&
 or||
 not!
 eq==
 ne!=
 ge>=
 gt>
 le<=
 lt<

Logical

If Expression ::= ‘if’ ‘(‘ SimpleExpression ‘)’ ‘then’
ExpressionList ( ‘elseif’ ‘(‘ SimpleExpression ‘)’ ‘then’
ExpressionList )* ( ‘else’ ExpressionList )? ‘endif’

eg:

if ( totalMarks < minimum ) then
// fail the student
endif

 

for Expression ::=’for’ Assignment ‘upto’ Accessor (‘step’ SimpleExpression)?
‘do’ ExpressionList ‘endfor’ |
‘for’ Assignment ‘downto’ Accessor (‘step’ SimpleExpression)?
‘do’ ExpressionList ‘endfor’

eg:

var y = 1;
for var x = 1 upto power do
y = y * base
endfor

upto keyword denotes increment and downto denotes decrements in for loop. upto keyword performs increment one by one unless it is specified in step keyword

for x=2 upto 100 step 2 do
count = count + 1;
endfor

ForeachExpression ::=
‘foreach’ Identifier ‘in’ ‘(‘ ArgumentList ‘)’
‘do’ ExpressionList ‘endfor’

eg;

var total = 0.0
foreach expense in ( travel_exp[*], living_exp[*],parking_exp[*] ) do
total = total + expense
endfor

WhileExpression ::=
‘while’ ‘(‘ SimpleExpression ‘)’ ‘do’ ExpressionList ‘endwhile’

eg:

var count = 0;
while ( count gt 10 ) do
count = count +1;
endwhile

If you read the code examples above carefully you might have noticed that ecmascript357 type node access mechanism is used in several places of formcalc scirpt.

example amount[1] …. amount[*]

If you have encountered such kind of scenarios then you need to convert the formcalc script to resolveNode method like scripting in Javascript; please read this article to learn more details about resolveNode method in Javascript.

For further information on XFA, please read XFA 3.3 specification for more details.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (TwitterFacebook and Google+) or the Blog RSS.

 

Related Posts:

The following two tabs change content below.

suda

Java EE developer at IDRSolutions
Suda is the Senior Java EE Developer at IDR Solutions, and specialises in XFA, Fonts, True-Type Fonts, application servers and conversions. He is a keen science-fiction fan in his spare time.
suda

About suda

Suda is the Senior Java EE Developer at IDR Solutions, and specialises in XFA, Fonts, True-Type Fonts, application servers and conversions.
He is a keen science-fiction fan in his spare time.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>