| |
» Back to overview
In the SUPPORT section you can write FULA functions for use in the TRANSFER section.
Also any SUPPORT function can be used when specifying information in the PROBLEM section.
The definition of a support function always consists of two steps:
- declaring the function (that is specifying its FULA type)
- implementing the function
The declaration of a support function with n arguments looks like this:
functionname ::
argtype1 * ... * argtypen ->
returntype
where argtypei is a type name
defined in the TYPE section or a built-in type.
The implementation should look like this:
functionname ( param1, ... , paramn )
= FULA-expression
In both cases, n may be any number >= 0;
even for n=0, the arrow -> and the parentheses are mandatory, e.g.
five :: -> snum
five() = 5
In the implementation you can use pattern matching to implement functions depending on the arguments.
For example
listlength :: ExpressionList -> snum |
//definition |
listlength ( [] ) = 0 |
// empty list has length 0 |
listlength ( head:tail ) = 1 + listlength (tail) |
// 1 + length of the restlist |
listlength ( _ ) = error("listlength called for non list") |
// error else |
defines and implements a function that calculates recursively the length
of a list of expressions. For each call the argument is matched first against [],
and then against head:tail, and the function is calculated according to
which pattern matched.
The third pattern (the anonymous variable "_") matches any expression, so this part
of the function definition is evaluated whenever none of the above patterns could be
matched. For the case of listlength we produce an error. On the other hand we could
just as well drop the third pattern altogether since the type checker would already
note an error if we tried to call listlength with an argument that is not a list.
Next step
Contents
- Overview
- Specifying datatypes in the TYPE section
- Specifying the framework of your analysis in the PROBLEM section
- The FULA language
- Global FULA variables
- Specifying the TRANSFER section
- The SUPPORT section
- Built-in PAG/WWW functions
- A formal description of the analysis specification syntax
Search
| |