2.1.4) Simplified syntax

This description is not formally perfect nor is it exhaustive. It is intended for fast learning only.

a) Getting started
b) Comments
c) Annotations
d) Constant definition
e) Types definition
f) Command bodies
f.1) Select bodies
f.2) Data bodies
f.3) Unixdata bodies
g) Instructions
g.1) command instructions
g.2) param instructions
g.3) optparam instructions
g.4) option instructions
g.5) short option instructions
h) Case statements


a) Getting started

Any TL program is made of:

  1. the program definition; the reserved word Program followed by a string defining the program name
  2. a comment line; the reserved word Comment followed by a comment string
  3. definition of some constants (optional)
  4. definition of some new types (optional)
  5. a command body
Example:

Program "write"
Comment "Write In into Out"
Data t_write
 param arg1:string;
call writefnc:string;


b) Comments

Comments are made of the reserved word Comment followed by a string or sum of strings. Several comments are contatenated as if string + newline + string would be used.

They are used to document a type/command/parameter/option. The comments are used with the automatic documentation.

Examples:

Program "abc"
Comment "This is a test program."
Comment "Written by Pinco Pallino."
...

...
  param name:string
  comment "user name"
...

...
 option "format" format:string
 comment "printf-like format"+
         "see C documentation"
...


c) Annotations

At any point you can insert an annotation; simply write double slash (//) and the rest of the line is the annotation.

Annotations are used as internal comments as they are ignored by the compiler.

Examples:

Program "write"
Comment "Write In into Out"
        // This is a very simple program
...

...
  //param a:string
  param a:integer
...


d) Constant definition

TL supports five types of constants:

The type of a constant is automaticaly found. There is no syntax difference between them.

A constant definition is made of the reserved word Const, followed by an identifier, a = and a constant value.

Another possible definition is made of the reserved word Const, followed by an identifier. The value of such a constant is a unique natural value.

Do not mix the two definitions.

Example:

Program "Consts"

Const a1
      a2
      a3
      a4
      a5
      b1str = "b1"
      b2str = "b2"

      val1 = -200
      val2 = 400	

Const r1 = -1.23e2
      r2 = 2.456e2

Intype myset = set("a1":a1,"a2":a2,"a3":a3,"a4":a4,"a5":a5,b1str,b2str)

Intype myrange  = rrange(r1..r2)
       myrange1 = irange(val1..val2)	

data t_consts
 param a:myset
 param b:myrange
 param c:myrange1
call myfunc:string


e) Type definition

TL supports two types of types: intype and outtype.

There are several basic (in and out) types the user can immediately use. And it can create new types.

Any basic (in or out) type can be used directly, except set, iset and user types that can only be used to create new types.

To define a new type you have to insert the intype/outtype type definition in a type definition part of the program.
Type definition parts can be put immediately before the
command body of the program and/or a command.

A type definition if made of the reserved word Intype/Outtype followed by an identifier, a = , the types definition and an optional comment line.

See Types section for details about available types.

Example:

Program "Types"

Intype myset = set("a1":1,"a2":2,"a3":3,"a4":4,"a5":5,"b1","b2","b3")
       myrec = record
                a:myset
                b:integer
               end

Outtype myuser = user mydeffunc myfreefunc
        Comment "This is my very personal type."
        mycase = case a of
                     1 n1:myuser
                     2 n2:freal
                  else e1:string
                 end

data t_types
 param a:myrec
call myfunc:mycase


f) Command bodies

There are three types of command bodies:

  1. select bodies
  2. data bodies
  3. unixdata bodies


f.1) Select bodies

The select bodies are used to create subcommands.

They are made of the reserved word Select, two or more command instructions and the reserved word end.

Example:

...
Select
 Command "open"
 data t_open
 ...
 call openfunc:int

 Command "close"
 data t_close
 ...
 call closefunc:string
end


f.2) Data bodies

The data body is the most used command body. It is used to parse input, compute the data and create the output.

The data bodies are made of the reserved word data, a data identifier(*), some param, at most one optparam, and some option instructions, followed by the reserved word Call, a function identifier(**), a colon(:) and an output type(***).

The data identifier(*) is used to create the internal data structure. The param, optparam and option instructions are used to create the parsing code. The function identifier(**) is the name of a user supplied function. This function actually compute the data that is finally converted in the output string using the output type(***).

The parsers created by this command bodies do strong type checking. The resulting command will accept only the input specified in the data body. This can limit the use of the command, but can improve error detection.
If you need more flexibility, use the unixdata bodies.

Example:

...
data t_mydata
 param p1:integer
 param p2:real;
 option "format" format:string
 optparam op1:bool
call mydatafunc:integer
...


f.3) Unixdata bodies

The unixdata body is similar to the data body. It is used to parse input, compute the data and create the output.

The unixdata bodies are made of the reserved word unixdata, a data identifier(*), some option and some short option instructions, followed by the reserved word Call, a function identifier(**), a colon(:) and an output type(***).

The data identifier(*) is used to create the internal data structure. The option and short option instructions are used to create the parsing code. The function identifier(**) is the name of a user supplied function. This function actually compute the data that is finally converted in the output string using the output type(***).

The parsers created by this command bodies are very flexible. They do type checking only on option parameters, all the other data is passed unchanged to the user supplied function. This allows very flexible commands, but requires much more complicated user supplied functions. Moreover there is very little automatic error detection.
So it is better to use data bodies whenever possible.

Example:

...
unixdata t_myudata
 option "maxsize" format:integer
 option "docache" docache
call myudatafunc:freal
...


g) Instructions

There are five types of instructions:

  1. command instructions
  2. param instructions
  3. optparam instructions
  4. option instructions
  5. short option instructions


g.1) Command instructions

Command instructions are used in select bodies. They define a list of subcommands.

They are made of the reserved word Command, a string, an optional case statement, an optional comment, an optional constant definition part, an optional type definition part and a command body.

Example:

...
Command "open"
Comment "Open file"

Outtype id=integer

data t_open
 param name:string
call openfunc:id
...


g.2) Param instructions

Param instructions are used in data bodies. They define a list of parameters and their types. These parameters are the first input parameters. This is independent of the other instructions.

The param instructions are made of the reserved word Param, a data identifier, a colon(:) and an input type.
Should be followed by a comment.

Example:

...
data t_mydata
 param a:integer
 Comment "First parameter"
 param b:real        // do not comment
 param c:string
 Comment "Last parameter"
call
...
This command expects 3 parameters: an integer, a real and a generic string.


g.3) Optparam instructions

Optparam instructions are used in data bodies. There can be at most one optparam instruction per data body. If present it specify an optional parameter and his type. If the optparam instruction is present before any option instruction these parameter must be written before any option parameter, else it must be the last parameter (if present).

The optparam instructions are made of the reserved word Optparam, a data identifier, a colon(:) and an input type.
Should be followed by a comment.

Example:

...
data t_mydata
 option "format" format:string
 Comment "Some type of format"
 optparam a:integer
 Comment "Must be the last param, if present"
 option "size" size:integer
call fmyfunc:string
...
Some valid inputs:
-format abc
-format abc 12
12


g.4) Option instructions

Option instructions are used in data bodies and in unixdata bodies. They define a list of possible options, their names and their types. These options can be present as parameters in any order and any number of times. Only the last will be recorded and their presence is notified.

The option instructions are made of the reserved word Option, a string(*), a data identifier, a colon(:) and an input type.
Can be followed by a case statement.
Should be followed by a comment.

The string(*) is the name of the option. The option parameter must start with - followed by the string(*). The next parameter represents the option data.

Example:

...
data t_mydata
 option "format" format:string
 option "maxsize" size:integer
 comment "Max cache size"
 option "cancache" ccache:bool
call myfunc:string
...
Some valid inputs:
-format abc -cancache True -maxsize 12 -format "This is the true format!"
-maxsize 3
<empty>


g.5) Short option instructions

Short option instructions are used in unixdata bodies. They define a list of possible options and their names. These options can be present as parameters in any order and any number of times. Only their presence is notified.

The short option instructions are made of the reserved word Option, a string(*) and a data identifier.
Can be followed by a case statement.
Should be followed by a comment.

The string(*) is the name of the option. The option parameter must start with - followed by the string(*).

Example:

...
unixdata t_mydata
 option "format" format:string
 option "maxsize" size:integer
 option "cancache" cancache
 Comment "If present, enable cache"
call fmyfunc:string
...
Some valid inputs:
-format abc -cancache -maxsize 12 -format "This is the true format!"
-maxsize 3
-cancache


h) Case statements

Case statements can be one of:

They are used in:
Example:

...
Command "open"
case insensitive

unixdata t_open
 option "X11" X11
 case sensitive
 option "format" format:string
 case insensitive
call ud_open:integer
...


Back to main page.
Send comments to: Igor Sfiligoi