docs: add todo's from Sibir's repo
[netsniff-ng.git] / src / trafgen_lexer.l
blob7d307e0ac2e6745ec1a4cee810900463559a3f2f
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 /* lex-func-prefix: yy */
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <string.h>
16 #include <ctype.h>
18 #include "trafgen_parser.tab.h"
19 #include "xmalloc.h"
21 extern void yyerror(const char *);
25 %option align
26 %option nounput
27 %option noyywrap
28 %option noreject
29 %option 8bit
30 %option caseless
31 %option noinput
32 %option nodefault
34 digit           [0-9]
35 digit_s         [1-9]
36 digit_n         [0]
37 bindigit        [0-1]
38 bindigit_b      [b]
39 hex             [a-fA-F0-9]
40 hex_x           [x]
42 number_dec      {digit_n}|{digit_s}{digit}*
43 number_oct      {digit_n}{digit}+
44 number_hex      {digit_n}{hex_x}{hex}+
45 number_bin      {digit_n}{bindigit_b}{bindigit}+
46 number_ascii    [a-zA-Z]
50 "fill"          { return K_FILL; }
51 "rnd"           { return K_RND; }
52 "drnd"          { return K_DRND; }
53 "dinc"          { return K_DINC; }
54 "ddec"          { return K_DDEC; }
55 "seqinc"        { return K_SEQINC; }
56 "seqdec"        { return K_SEQDEC; }
58 "{"             { return '{'; }
59 "}"             { return '}'; }
60 "("             { return '('; }
61 ")"             { return ')'; }
62 "["             { return '['; }
63 "]"             { return ']'; }
64 ","             { return ','; }
65 "\n"            { yylineno++; return K_NEWL; }
66 [ \t\r]+        { return K_WHITE; }
68 "/*"([^\*]|\*[^/])*"*/" { return K_COMMENT; }
70 {number_hex}    { yylval.number = strtoul(yytext, NULL, 16);
71                   return number_hex; }
73 {number_dec}    { yylval.number = strtol(yytext, NULL, 10);
74                   return number_dec; }
76 {number_oct}    { yylval.number = strtol(yytext, NULL, 8);
77                   return number_oct; }
79 {number_bin}    { yylval.number = strtol(yytext + 2, NULL, 2);
80                   return number_bin; }
82 {number_ascii}  { yylval.number = (uint8_t) (*yytext);
83                   return number_ascii; }
85 "'"."'"         { yylval.number = (uint8_t) (*(yytext + 1));
86                   return number_ascii; }
88 ";"[^\n]*       {/* NOP */}
89 "#"[^\n]*       {/* NOP */}
90 .               { printf("Unknown character '%s'", yytext);
91                   yyerror("lex Unknown character"); }