summaryrefslogtreecommitdiff
path: root/sdl-test/SDL_tuto/TestParserLemmingsLVL/parse_ini.lex
blob: b665ae3c91b6692e046972f554cc10e86977d390 (plain)
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
51
%{
	#include "y.tab.h"
	#include <string.h>
	#define MAX_STR_LEN 255

int string(int tok) {
	int lg = strlen(yytext);
	if ( lg > MAX_STR_LEN ) {
		return LEXERROR;
	} else {
		yylval.str = malloc(sizeof(char)*lg);
		strcpy(yylval.str, yytext);
		return tok;
	}
}
%}

%option nounput
%option noyywrap

BLANK [ \t]
NOT_BLANK [^ \t]
IDENT [a-zA-Z][a-zA-Z0-9_-]*


%x INI_VALUE 
	/*	%s : inclusive start condition (inclus aussi les règles sans <cond>)
		%x : exclusive start condition (règles sans <cond> inactives)
	*/
%%


"="{BLANK}*			BEGIN(INI_VALUE); return AFF;
<INI_VALUE>\n			yylineno++; BEGIN(INITIAL); return EOL;
<INI_VALUE>"-"?[0-9]+{BLANK}*	{
					yylval.num = atoi(yytext);
					return INT;
				}
<INI_VALUE>","{BLANK}*		return VIR;
<INI_VALUE>[^,\n-][^\n]*	return string(STR);

{IDENT}			return string(IDENT);

"#"[^\n]*\n		yylineno++; /* Single line Comment*/


\n			yylineno++; return EOL; /* printf("\n"); */

{BLANK}*		/* Ignore */
{NOT_BLANK}		fprintf(stderr, "LEX : ERROR : unknown char '%c'", yytext[0]); return LEXERROR; /* Pour tout ce qu'on a pas encore chopé */