Next: , Previous: , Up: silex   [Index]


53.5 Syntax of the specification

A specification for a lexical analyser contains two parts: the macro definitions part, or header, and the rules part. The two parts are separated by the mark %%. Example:

blanks          [ \9\10\13]+
decint          [0-9]+

%%

{blanks}        ;; skip blanks, tabs and newlines
{decint}        (string->number yytext)

The first part is used to define macros; that is, to give names to some regular expressions. The second part is used to indicate the regular expressions with which the input will have to match, and the actions associated with each expression.

Comments can be inserted any place where white space is allowed and is considered as white space itself. Line comments begin with a semicolon ‘;’ and extend up to the end of a line; the semicolon is a valid token in many languages, so we should take care not to comment out an entire line when writing a regular expression matching a semicolon. Nested comments begin with a ‘#|’ sequence and extend up to the corresponding ‘|#’ sequence.


Next: , Previous: , Up: silex   [Index]