Previous: silex syntax regexp space, Up: silex syntax [Index]
Here is an example of a SILex specification file. The file is syntactically correct from the SILex point of view. However, many common mistakes are shown. The file is not a useful one.
; This is a syntactically correct but silly file.
partial hel
complete {partial}lo ; Backward macro ref. only
digit [0-9]
letter [a-zA-Z]
%%
-?{digit}+ (cons 'integer yytext) ; yytext
contains
; the lexeme
-?{digit}+\.{digit}+[eE][-+]?{digit}+
(cons ; An action
'float ; spanning multiple
yytext) ; lines
; (list 'semicolon) ; Probably a mistake
begin )list 'begin( ; No error detected here
end ; The action is optional
\73 (list 'bell-3) ; It does not match the
; char. # 7 followed by ‘3’
\0073 (list 'bell-3) ; Neither does it
(\7)3 (list 'bell-3) ; This does it
"*()+|{}[].? are ordinary but \" and \\ are special"
[^\n] (list 'char) ; Same thing as ‘.’
({letter}|_)({letter}|_|{digit})* ; A C identifier
[][] ; One of the square brackets
Repe(ti){2}on (list 'repetition)
^{letter}+: (cons 'label yytext) ; A label placed at the
; beginning of the line
$^ ; No special meaning
<<EOF>> (list 'eof) ; Detection of the end of file
<<ERROR>> (my-error) ; Error handling