html: give a better description of available docs
[netsniff-ng.git] / src / trafgen_lexer.l
blob0b1d7922e22758c276126fdabb716b1c3ebb3090
1 /*
2  * netsniff-ng - the packet sniffing beast
3  * By Daniel Borkmann <daniel@netsniff-ng.org>
4  * Copyright 2012 Daniel Borkmann <dborkma@tik.ee.ethz.ch>,
5  * Swiss federal institute of technology (ETH Zurich)
6  * Subject to the GPL, version 2.
7  */
9 %{
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include <ctype.h>
16 #include "trafgen_parser.tab.h"
17 #include "xmalloc.h"
19 extern void yyerror(const char *);
23 %option align
24 %option nounput
25 %option noyywrap
26 %option noreject
27 %option 8bit
28 %option caseless
29 %option noinput
30 %option nodefault
32 digit           [0-9]
33 digit_s         [1-9]
34 digit_n         [0]
35 bindigit        [0-1]
36 bindigit_b      [b]
37 hex             [a-fA-F0-9]
38 hex_x           [x]
40 number_dec      {digit_n}|{digit_s}{digit}*
41 number_oct      {digit_n}{digit}+
42 number_hex      {digit_n}{hex_x}{hex}+
43 number_bin      {digit_n}{bindigit_b}{bindigit}+
44 number_ascii    [a-zA-Z]
48 "fill"          { return K_FILL; }
49 "rnd"           { return K_RND; }
50 "drnd"          { return K_DRND; }
51 "dinc"          { return K_DINC; }
52 "ddec"          { return K_DDEC; }
53 "seqinc"        { return K_SEQINC; }
54 "seqdec"        { return K_SEQDEC; }
56 "{"             { return '{'; }
57 "}"             { return '}'; }
58 "("             { return '('; }
59 ")"             { return ')'; }
60 "["             { return '['; }
61 "]"             { return ']'; }
62 ","             { return ','; }
63 "\n"            { yylineno++; return K_NEWL; }
64 [ \t\r]+        { return K_WHITE; }
66 "/*"([^\*]|\*[^/])*"*/" { return K_COMMENT; }
68 {number_hex}    { yylval.number = strtoul(yytext, NULL, 16);
69                   return number_hex; }
71 {number_dec}    { yylval.number = strtol(yytext, NULL, 10);
72                   return number_dec; }
74 {number_oct}    { yylval.number = strtol(yytext, NULL, 8);
75                   return number_oct; }
77 {number_bin}    { yylval.number = strtol(yytext + 2, NULL, 2);
78                   return number_bin; }
80 {number_ascii}  { yylval.number = (uint8_t) (*yytext);
81                   return number_ascii; }
83 "'"."'"         { yylval.number = (uint8_t) (*(yytext + 1));
84                   return number_ascii; }
86 ";"[^\n]*       {/* NOP */}
87 "#"[^\n]*       {/* NOP */}
88 .               { printf("Unknown character '%s'", yytext);
89                   yyerror("lex Unknown character"); }