nextuppreviouscontents
Next:Commands Up:Expressions, parsing and pretty Previous:Syntax   Contents

Expressions

Expressions are not parsed with a context free grammar ! So we will give partial BNF rules and explain ``infix'' and ``prefix'' expressions by hand.

Here are the BNF rules with infix-expr and prefix-expr left undefined.

sort-assignment:=:<sort 
alpha-idents-list:=alpha-ident 
 $\vert$alpha-ident,alpha-idents-list 
atom-expr:=alpha-ident 
 $\vert$$any-ident 
 $\vert$unif-var 
 $\vert$\alpha-idents-listsort-assignmentatom-expr 
 $\vert$(expr) 
 $\vert$prefix-expr 
app-expr:=atom-expr 
 $\vert$atom-exprapp-expr 
expr:=app-expr 
 $\vert$prefix-expr 
 $\vert$infix-expr 

This definition is clear except for two points:

To explain how infix-expr and prefix-expr works, we first give the following definition:

A syntax definition is a list of items and a priority. The priority is a floating point number between 0 and 10. Each item in the list is either:

Remark: this definition clearly follows the definition of a syntax.

Now we can explain how a syntax definition is parsed using the following principles. It is not very easy to understand, so we will give some examples:

  1. The first keyword in the definition is the ``name'' of the object described by this syntax. This name can be used directly with ``normal'' syntax prefixed by a $ sign.

    For instance, if the first keyword is the string "+", then + is the name of the object and if this object is defined, $+ is a valid expression.

  2. To define the way infix-expr and prefix-expr are parsed, we will explain how they are parsed and give the same expression without using this special syntax.

  3. The number of sub-expressions in the list is the ``arity'' of the object defined by the syntax.

  4. To parse a syntax defined by a list, examines each item in the list:

Examples:

Remark: there are some undocumented black magic in parser. For instance, to parse $\forall x,y:N \dots$ (meaning $\forall x (N x \rightarrow \forall y (N y \rightarrow \dots))$ or $\forall x,y < z \dots$ (meaning $\forall x (x < z \rightarrow \forall y (y < z \rightarrow \dots))$, there is an obscure extension for binders.

This is really specialized code for universal and existential quantifications ... but advanturous user, looking at the definition of the existential quantifier \/ in the library file prop.phx can try to understand it (though, I think it is not possible).


nextuppreviouscontents
Next:Commands Up:Expressions, parsing and pretty Previous:Syntax   Contents
Christophe Raffalli 2005-03-02