The Gallina specification language¶
Source: | https://coq.inria.fr/distrib/current/refman/gallina.html |
---|---|
Converted by: | Clément Pit-Claudel |
This chapter describes Gallina, the specification language of Coq. It allows developing mathematical theories and to prove specifications of programs. The theories are built from axioms, hypotheses, parameters, lemmas, theorems and definitions of constants, functions, predicates and sets. The syntax of logical objects involved in theories is described in Section 1.2. The language of commands, called The Vernacular is described in section1.3.
In Coq, logical objects are typed to ensure their logical correctness. The rules implemented by the typing algorithm are described in Chapter 4.
About the grammars in the manual¶
Grammars are presented in Backus-Naur form (BNF). Terminal symbols are
set in black typewriter font
. In addition, there are special notations for
regular expressions.
An expression enclosed in square brackets […]
means at most one
occurrence of this expression (this corresponds to an optional
component).
The notation “entry sep … sep entry
” stands for a non empty sequence
of expressions parsed by entry and separated by the literal “sep
”.
Similarly, the notation “entry … entry
” stands for a non empty
sequence of expressions parsed by the “entry
” entry, without any
separator between.
At the end, the notation “[entry sep … sep entry]
” stands for a
possibly empty sequence of expressions parsed by the “entry
” entry,
separated by the literal “sep
”.
Lexical conventions¶
- Blanks
- Space, newline and horizontal tabulation are considered as blanks. Blanks are ignored but they separate tokens.
- Comments
- Comments in Coq are enclosed between
(*
and*)
, and can be nested. They can contain any character. However, string literals must be correctly closed. Comments are treated as blanks. - Identifiers and access identifiers
Identifiers, written ident, are sequences of letters, digits,
_
and'
, that do not start with a digit or'
. That is, they are recognized by the following lexical class:first_letter ::= a..z ∣ A..Z ∣ _ ∣ unicode-letter subsequent_letter ::= a..z ∣ A..Z ∣ 0..9 ∣ _ ∣ ' ∣ unicode-letter ∣ unicode-id-part ident ::=
first_letter
[subsequent_letter
…subsequent_letter
] access_ident ::= .ident
All characters are meaningful. In particular, identifiers are case- sensitive. The entry
unicode-letter
non-exhaustively includes Latin, Greek, Gothic, Cyrillic, Arabic, Hebrew, Georgian, Hangul, Hiragana and Katakana characters, CJK ideographs, mathematical letter-like symbols, hyphens, non-breaking space, … The entryunicode-id-part
non- exhaustively includes symbols for prime letters and subscripts.Access identifiers, written
access_ident
, are identifiers prefixed by . (dot) without blank. They are used in the syntax of qualified identifiers.- Natural numbers and integers
Numerals are sequences of digits. Integers are numerals optionally preceded by a minus sign.
digit ::= 0..9 num ::=
digit
…digit
integer ::= [-]num
- Strings
- Strings are delimited by
"
(double quote), and enclose a sequence of any characters different from"
or the sequence""
to denote the double quote character. In grammars, the entry for quoted strings isstring
. - Keywords
The following identifiers are reserved keywords, and cannot be employed otherwise:
_ as at cofix else end exists exists2 fix for forall fun if IF in let match mod Prop return Set then Type using where with
- Special tokens
The following sequences of characters are special tokens:
! % & && ( () ) * + ++ , - -> . .( .. / /\ : :: :< := :> ; < <- <-> <: <= <> = => =_D > >-> >= ? ?= @ [ \/ ] ^ { | |- || } ~
Lexical ambiguities are resolved according to the “longest match” rule: when a sequence of non alphanumerical characters can be decomposed into several different ways, then the first token is the longest possible one (among all tokens defined at this moment), and so on.
Terms¶
Syntax of terms¶
The following grammars describe the basic syntax of the terms of the Calculus of Inductive Constructions (also called Cic). The formal presentation of Cic is given in Chapter 4. Extensions of this syntax are given in chapter 2. How to customize the syntax is described in Chapter 12.
term ::= forallbinders
,term
| funbinders
=>term
| fixfix_bodies
| cofixcofix_bodies
| letident
[binders
] [:term
] :=term
interm
| let fixfix_body
interm
| let cofixcofix_body
interm
| let ( [name
, … ,name
] ) [dep_ret_type
] :=term
interm
| let 'pattern
[interm
] :=term
[return_type
] interm
| ifterm
[dep_ret_type
] thenterm
elseterm
|term
:term
|term
<:term
|term
:> |term
->term
|term
arg … arg | @qualid
[term
…term
] |term
%ident
| matchmatch_item
, … ,match_item
[return_type
] with [[|]equation
| … |equation
] end |qualid
|sort
| num | _ | (term
) arg ::=term
| (ident
:=term
) binders ::=binder
…binder
binder ::=name
| (name
…name
:term
) | (name
[:term
] :=term
) name ::=ident
| _ qualid ::=ident
|qualid
access_ident
sort ::= Prop | Set | Type fix_bodies ::=fix_body
|fix_body
withfix_body
with … withfix_body
forident
cofix_bodies ::=cofix_body
|cofix_body
withcofix_body
with … withcofix_body
forident
fix_body ::=ident
binders
[annotation] [:term
] :=term
cofix_body ::=ident
[binders
] [:term
] :=term
annotation ::= { structident
} match_item ::=term
[asname
] [inqualid
[pattern
…pattern
]] dep_ret_type ::= [asname
]return_type
return_type ::= returnterm
equation ::=mult_pattern
| … |mult_pattern
=>term
mult_pattern ::=pattern
, … ,pattern
pattern ::=qualid
pattern
…pattern
| @qualid
pattern
…pattern
|pattern
asident
|pattern
%ident
|qualid
| _ | num | (or_pattern
, … ,or_pattern
) or_pattern ::=pattern
| … |pattern
(...)
The Vernacular¶
sentence ::=assumption
|definition
|inductive
|fixpoint
|assertion
proof
assumption ::=assumption_keyword
assums
. assumption_keyword ::= Axiom | Conjecture | Parameter | Parameters | Variable | Variables | Hypothesis | Hypotheses assums ::=ident
…ident
:term
| (ident
…ident
:term
) … (ident
…ident
:term
) definition ::= [Local] Definitionident
[binders
] [:term
] :=term
. | Letident
[binders
] [:term
] :=term
. inductive ::= Inductiveind_body
with … withind_body
. | CoInductiveind_body
with … withind_body
. ind_body ::=ident
[binders
] :term
:= [[|]ident
[binders
] [:term
] | … |ident
[binders
] [:term
]] fixpoint ::= Fixpointfix_body
with … withfix_body
. | CoFixpointcofix_body
with … withcofix_body
. assertion ::=assertion_keyword
ident
[binders
] :term
. assertion_keyword ::= Theorem | Lemma | Remark | Fact | Corollary | Proposition | Definition | Example proof ::= Proof . … Qed . | Proof . … Defined . | Proof . … Admitted .
This grammar describes The Vernacular which is the language of commands of Gallina. A sentence of the vernacular language, like in many natural languages, begins with a capital letter and ends with a dot.