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.
9 /* lex-func-prefix: yy */
18 #include "trafgen_parser.tab.h"
21 extern void yyerror(const char *);
34 number_oct ([0][0-9]+)
35 number_hex ([0][x][a-fA-F0-9]+)
36 number_bin ([0][b][0-1]+)
37 number_dec (([0])|([-+]?[1-9][0-9]*))
38 number_ascii ([a-zA-Z])
42 "cpu" { return K_CPU; }
43 "fill" { return K_FILL; }
44 "rnd" { return K_RND; }
45 "csumip" { return K_CSUMIP; }
46 "csumip4" { return K_CSUMIP; }
47 "csumudp" { return K_CSUMUDP; }
48 "csumtcp" { return K_CSUMTCP; }
49 "drnd" { return K_DRND; }
50 "dinc" { return K_DINC; }
51 "ddec" { return K_DDEC; }
52 "seqinc" { return K_SEQINC; }
53 "seqdec" { return K_SEQDEC; }
54 "const8"|"c8" { return K_CONST8; }
55 "const16"|"c16" { return K_CONST16; }
56 "const32"|"c32" { return K_CONST32; }
57 "const64"|"c64" { return K_CONST64; }
59 [ ]*"-"[ ]* { return '-'; }
60 [ ]*"+"[ ]* { return '+'; }
61 [ ]*"*"[ ]* { return '*'; }
62 [ ]*"/"[ ]* { return '/'; }
63 [ ]*"%"[ ]* { return '%'; }
64 [ ]*"&"[ ]* { return '&'; }
65 [ ]*"|"[ ]* { return '|'; }
66 [ ]*"<"[ ]* { return '<'; }
67 [ ]*">"[ ]* { return '>'; }
68 [ ]*"^"[ ]* { return '^'; }
80 "\""[^\"]+"\"" { yylval.str = xstrdup(yytext);
83 ([ \t\r\n]+)? { return K_WHITE; }
85 "/*"([^\*]|\*[^/])*"*/" { return K_COMMENT; }
87 "#"[^\n]* { return K_COMMENT; }
89 {number_hex} { yylval.number = strtoul(yytext, NULL, 16);
92 {number_dec} { yylval.number = strtol(yytext, NULL, 10);
95 {number_oct} { yylval.number = strtol(yytext + 1, NULL, 8);
98 {number_bin} { yylval.number = strtol(yytext + 2, NULL, 2);
101 {number_ascii} { yylval.number = (uint8_t) (*yytext);
104 "'"."'" { yylval.number = (uint8_t) (*(yytext + 1));
107 ";"[^\n]* {/* NOP */}
108 . { printf("Unknown character '%s'", yytext);
109 yyerror("lex Unknown character"); }