Next: silex semantics, Previous: silex lexer, Up: silex [Index]
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.
• silex syntax macros: | Syntax of the macro definitions. | |
• silex syntax includes: | Including macro files. | |
• silex syntax rules: | Syntax of the rule–action pairs. | |
• silex syntax regexp atomic: | Atomic regular expressions. | |
• silex syntax regexp compose: | Composing regular expressions. | |
• silex syntax regexp marker: | Markers. | |
• silex syntax regexp space: | White spaces in regular expressions. | |
• silex syntax sample: | Show some frequent mistakes. |
Next: silex semantics, Previous: silex lexer, Up: silex [Index]