File: lexer.l

package info (click to toggle)
libtrace3 3.0.14-1
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 11,492 kB
  • sloc: ansic: 21,584; sh: 10,236; cpp: 1,765; makefile: 454; yacc: 96; lex: 50
file content (50 lines) | stat: -rw-r--r-- 968 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
DIGIT	    [0-9]
LETTER	    [a-zA-Z_: ]
HEXDIGIT    [0-9A-Fa-f]

%option noyywrap 
%option nounput 
%option noinput

%{
    #include <stdio.h>
    #include "grammar.h"
    #include "parser.h"

    int yylex(void);
    int yyerror(char *s);

    int lines = 1;
%}

%%

"#".*"\n"			{ /* ignore comments */ }		

"be"				{ return TOK_BIGENDIAN; }
"le"				{ return TOK_LITTLEENDIAN; }
"next"				{ return TOK_NEXT; }

"hex"				{ return TOK_OUTPUT_HEX;}
"integer"			{ return TOK_OUTPUT_INT;}
"ipv4"				{ return TOK_OUTPUT_IPV4;}
"mac"				{ return TOK_OUTPUT_MAC;}
"hidden"			{ return TOK_OUTPUT_NONE;}

"flag"				{ return TOK_OUTPUT_FLAG; }

{DIGIT}+	    		{ yylval.intval = atoi(yytext); 
				    return TOK_CONSTANT; }
\"[^\"]*\"			{ int i; 
				    for(i=0;yytext[i] != '\0'; i++)
					if(yytext[i] == '"')
					    yytext[i] = '\0';
				    yylval.textval = &yytext[1];
				    return TOK_IDENTIFIER;
				}

"\n"				{ lines++; }
.				{ /* ignore everything else */ }

%%