Scripting language

Introduction

In this chapter, we describe the scripting language which comes with ACGtk. This language, combined with the language of ACG grammars, is used to query ACGtk to perform operations on the grammars and terms, such as parsing or realisation. These queries are called commands.

Here is an example of a command:

"lambda z. John (seeks (a (unicorn z))) : string" | parse type=Sentence lex_syn | realize lex_sem;

There are three steps, called functions, executed by this command:

Environment

The environment of a scripting session contains ACG definitions (signatures and lexicons). It is empty at the beginning of a session and some commands can modify it.

Functions

Functions are the basic block of this scripting language. Some functions are predefined, and it is also possible to define new functions by composing existing functions.

As shown in the above example, most functions take as input a (possibly empty) list of λ-terms and output an other list, which is meant to be given as input to the next function. In addition, some functions take additional arguments, such as a signature or lexicon name.

Arguments

Syntax

All arguments have a name and a type. In the following sections, this syntax is used to describe the list of arguments of a function:

f arg1:t1 arg2:t2 arg3=val3:t3

This represents the example function f, which takes 3 arguments, named arg1, arg2 and arg3, in this order. Their types are respectively t1, t2 and t3, and the third argument (arg3) has a default value (val3).

The arguments must be given to a function separated by spaces, and in the right order, except if the name of the argument is explicitly written. Some arguments may have a default value, so they can be omitted, and all the others argument must be given.

For example, all these call to the function f are equivalents:

f arg1=val1 arg2=val2 arg3=val3
f val1 val2 val3
f val1 val2
f arg3=val3 arg1=val1 arg2=val2
f arg2=val2 val1

For boolean arguments, there is an alternative syntax with + or - signs. If arg_bool is a boolean argument of function f, the two following calls are equivalents and set the value of arg_bool to true:

f arg_bool=true
f +arg_bool

And these two calls are also equivalent, with the value of arg_bool set to false:

f arg_bool=false
f -arg_bool

Types

The arguments of a function can have the following types:

List of predefined functions

In this part, we list the predefined functions. When [terms] | is written before a function description, it means that this function expects a list of terms as input. When | [terms] is written after a function description, it means that this function outputs a list of terms, which can be used as input of an other function, with a |, or just printed as result of the whole command.

Commands

There are two types of commands:

In the interactive mode, a command may end with a ;, but it is not mandatory. In script mode, the ; is always mandatory at the end of commands.

Functions execution

A command can execute one or more functions. If there are multiple functions in a single command, they are composed by the pipe | operator, which gives the list of λ-terms for a function to the following function.

For example, in this command:

list-terms sig Sentence | realize lex

There are two function calls, the first one is list-terms sig Sentence, which will output terms. These terms will be given as input to the second function call, realize lex, which will also output other terms. Since it is the last function of the command, its output will be printed.

Term literal

A command may also start by a term literal. It will be given as input to the next function of the command. There are two possible syntaxes:

Function definition

It is possible to define custom functions by composing some other functions. The custom functions can have parameters, to give to the functions used in its definition.

Example of a function definition:

let parse_real lex1 t lex2 n=2 := parse lex1 t | limit n | realize lex2;

The parameters may have a default value, given with the operator "=" (in the example, the parameter n has the default value 2).

After the definition, it is possible to call it by its name (here parse_real):

"lambda z. mary (loves (john z) : str" | parse_real string_lex sem_lex t=Sentence;

Examples

In this section we give some examples of commands. These commands do not end with a ;, to they are only valid in interactive mode. To use them in scripts, a ; must be added at the end of each command.