This section contains the definition of the GAP syntax in Backus-Naur form.
A BNF is a set of rules, whose left side is the name of a syntactical
construct. Those names are enclosed in angle brackets and written in
italics. The right side of each rule contains a possible form for that
syntactic construct. Each right side may contain names of other
syntactic constructs, again enclosed in angle brackets and written in
italics, or character sequences that must occur literally; they are
written in typewriter style
.
Furthermore each righthand side can contain the following metasymbols written in boldface. If the right hand side contains forms separated by a pipe symbol (|) this means that one of the possible forms can occur. If a part of a form is enclosed in square brackets ([ ]) this means that this part is optional, i.e. might be present or missing. If part of the form is enclosed in curly braces ({ }) this means that the part may occur arbitrarily often, or possibly be missing.
Permutation := Expr kill
Ident := a
|...|z
|A
|...|Z
|_
{a
|...|z
|A
|...|Z
|0
|...|9
|_
}
Var := Ident
| Var .
Ident
| Var .
(
Expr )
| Var [
Expr ]
| Var {
Expr }
| Var (
[ Expr { ,
Expr } ] )
List := [
[ Expr ] {,
[ Expr ] } ]
| [
Expr [, Expr ] ..
Expr ]
Record := rec(
[ Ident :=
Expr
{,
Ident :=
Expr } ] )
Permutation := (
Expr {,
Expr } )
{ (
Expr {,
Expr } )
}
Function := function (
[ Ident {,
Ident } ] )
[ local
Ident {,
Ident } ;
]
Statements
end
Char := '
any character '
String := "
{ any character } "
Int := 0
|1
|...|9
{ 0
|1
|...|9
}
Atom := Int
| Var
| (
Expr )
| Permutation
| Char
| String
| Function
| List
| Record
Factor := {+
|-
} Atom [ ^
{+
|-
} Atom ]
Term := Factor { *
|/
|mod
Factor }
Arith := Term { +
|-
Term }
Rel := { not
} Arith
{ =
|<>
|<
|>
|<=
|>=
|in
Arith }
And := Rel { and
Rel }
Log := And { or
And }
Expr := Log
| Var [ -
Log ]
Statement := Expr
| Var :=
Expr
| if
Expr then
Statements
{ elif
Expr then
Statements }
[ else
Statements ] fi
| for
Var in
Expr do
Statements od
| while
Expr do
Statements od
| repeat
Statements until
Expr
| return
[ Expr ]
| quit
Statements := { Statement ;
}
| ;
GAP 3.4.4