Keywords :

BAP Online Manuals : Compiler Reference Manual : Language Description: : Keywords :
Previous: Type Checking
Next: Operators

3.5.5. Keywords :

We start with a list of all available keywords:

  • MODULE module definition

  • INCLUDE specifies an include file

  • PREDICATE precedes a predicate definition

  • DOMAINS defines a new data type for optional type checking

  • DATABASE declares a database predicate (not implemented yet)

  • CONSTANTS defines symbolic names for constant data

  • IMPORT specifies a list of predicates to import

  • EXPORT specifies a list of predicates to export

Following the 'module' definition, any of the remaining keywords may appear.

The 'MODULE' Keyword

SYNTAX:

MODULE <module_name>.

EXAMPLE:

MODULE test_program.

OPERATION:

MODULE starts a module definition. It must appear as the first keyword in a module and may not appear twice within one file. It is followed by an atom describing the module name, which in this version of BAP must be the same as the filename without the '.BAP' ending (these restrictions may fall in future BAP releases).

The 'INCLUDE' Keyword:

SYNTAX:

INCLUDE '<FileName>'.

INCLUDE '<FileName>'.

EXAMPLE:

INCLUDE 'sample.inc'.

INCLUDE 'prolib.h'

OPERATION:

The BAP pre-processor removes this line from the source code and instead inserts the contents of the file <FileName>. The file is searched for in the current directory (in case of double quotes '') or the directory indicated by the environment variable BINC (in case of single quotes '').

The 'PREDICATE' Keyword:

SYNTAX:

PREDICATE <PredDeclaration>.

<PredClauses>

EXAMPLE:

PREDICATE member(void,void_list).

member(X,X| ).

member(X, |List):-

member(X,List).

OPERATION:

The PREDICATE keyword declares and defines a single predicate in 'PASCAL' like fashion (the declaration of a routine directly precedes the definition).

The clauses of the predicate directly follow the declaration.

A predicate declaration consists of the predicate name followed by a list of data types. It is terminated by a full stop.

The 'DOMAINS' Keyword:

SYNTAX:

DOMAINS <DomDeclList>

EXAMPLE:

DOMAINS

string_list = list of string.

term = int(integer);

var(string);

add(term,term);

mul(term,term);

comment(void).

term_list = list of term;

season = spring; summer; autumn; winter.

OPERATION:

The DOMAINS Keyword allows the user to define more complex data types from those already provided:

With these primitive data types , the user is free to build up his own ones. The effect of a type declaration is that a new predicate is built up (with the name of the domain type), that checks whether its single argument fits its type declaration or not. If it fits, the predicate succeeds. If not, it creates a runtime error and fails.

The construction of these checking predicates is implemented quite straight forward (by something like a preprocessor), allowing the user do create nested data types.

The 'DATABASE' Keyword:

SYNTAX:

DATABASE <PredDeclaration>.

EXAMPLE:

DATABASE xyz_position(integer,integer,integer).

OPERATION:

Declares a predicate as being member of the database, allowing database entries to be accessed like ordinary predicates. You don't need to declare a database predicate, instead you can access it via the database(void) built-in predicate, for example: database(xyz_position(X,Y,Z)).

This feature is not implemented yet.

The 'CONSTANTS' Keyword:

SYNTAX:

CONSTANTS

<constant declarations>

EXAMPLE:

CONSTANTS

left_corner = 20.

upper_corner = 10.

width = 50.

height = 20.

complex_0 = c(0,0).

title = 'Hey Guys, what's up?'.

OPERATION:

A constant declaration consists of a constant name, which must be an atom , and a value assigned to it. The value may be of any type. After declaring a constant, you may use it as synonym for its value. It will literally be replaced by its value.

The 'EXPORT' Keyword:

SYNTAX:

EXPORT <DeclarationList>.

EXAMPLE:

EXPORT member(void,void_list),

repeat.

OPERATION:

This statement declares that 'member()' and 'repeat()' are predicates defined in this module and that they may be called from outside.

The 'IMPORT' Keyword:

SYNTAX:

IMPORT <ModuleName> :- <DeclarationList>.

EXAMPLE:

IMPORT auxpreds :-

member(void,void_list),

repeat().

OPERATION:

This statement defines 'member()' and 'repeat()' as predicates defined outside the module. The module 'auxpreds' will be loaded and linked at runtime in the moment when 'member()' and 'repeat()' are called the first time.


BAP Online Manuals : Compiler Reference Manual : Language Description: : Keywords :
Previous: Type Checking
Next: Operators