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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
|
%{
#include <stdio.h>
#include <string.h>
#include "y.tab.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+1));
strcpy(yylval.str, yytext);
return tok;
}
}
%}
%option noinput
%option nounput
%option noyywrap
%option case-insensitive
BLANK [ \t]
NOT_BLANK [^ \t]
/* IDENT [a-z][a-z0-9_-]* */
STRCSV [a-z][a-z0-9._-]*
INTEGER "-"?[0-9]+
INTHEX 0x[0-9a-f]+
COMMENT "#"[^\n]*
/*
%s : inclusive start condition (includes also rules starting without <sc>)
%x : exclusive start condition
*/
%x TYPE_STR
%x TYPE_OTHER
%x VAL_STR
%x VAL_OTHER
%%
/* Wilcard state. Following rules are common to all states */
<*>\n { yylineno++; BEGIN(INITIAL); return EOL; }
<*>\r /* Ignore - http://fr.wikipedia.org/wiki/Fin_de_ligne : CRLF*/
/* Other rules for almost states (but VAL_STR) to ignore blanks and comments */
<INITIAL,TYPE_STR,TYPE_OTHER,VAL_OTHER>"#"[^\n]* /* Ignore Single line Comment*/
<INITIAL,TYPE_STR,TYPE_OTHER,VAL_OTHER>{BLANK}* /* Ignore blanks */
/* Initial state, start condition is 'INITIAL' (implicit), we catch only identifiers here */
"style" { BEGIN(TYPE_STR); return STYLE; }
"name" { BEGIN(TYPE_STR); return NAME; }
"superlemming" { BEGIN(TYPE_OTHER); return SLEM; }
"tiles" { BEGIN(TYPE_OTHER); return TILES; }
"frames_" { BEGIN(TYPE_OTHER); return FRAMES; }
"anim_" { BEGIN(TYPE_OTHER); return ANIM; }
"type_" { BEGIN(TYPE_OTHER); return TYPE; }
"sound_" { BEGIN(TYPE_OTHER); return SOUND; }
"bgcolor" { BEGIN(TYPE_OTHER); return BGCOLOR; }
"debriscolor" { BEGIN(TYPE_OTHER); return DEBRISCOLOR; }
"particlecolor" { BEGIN(TYPE_OTHER); return PARTICLECOLOR; }
"releaserate" { BEGIN(TYPE_OTHER); return RELEASERATE; }
"numlemmings" { BEGIN(TYPE_OTHER); return NUMLEMMINGS; }
"numtorescue" { BEGIN(TYPE_OTHER); return NUMTORESCUE; }
"timelimit" { BEGIN(TYPE_OTHER); return TIMELIMIT; }
"numclimbers" { BEGIN(TYPE_OTHER); return NUMCLIMBERS; }
"numfloaters" { BEGIN(TYPE_OTHER); return NUMFLOATERS; }
"numbombers" { BEGIN(TYPE_OTHER); return NUMBOMBERS; }
"numblockers" { BEGIN(TYPE_OTHER); return NUMBLOCKERS; }
"numbuilders" { BEGIN(TYPE_OTHER); return NUMBUILDERS; }
"numbashers" { BEGIN(TYPE_OTHER); return NUMBASHERS; }
"numminers" { BEGIN(TYPE_OTHER); return NUMMINERS; }
"numdiggers" { BEGIN(TYPE_OTHER); return NUMDIGGERS; }
"xpos" { BEGIN(TYPE_OTHER); return XPOS; }
"object_" { BEGIN(TYPE_OTHER); return OBJECT; }
"terrain_" { BEGIN(TYPE_OTHER); return TERRAIN; }
"steel_" { BEGIN(TYPE_OTHER); return STEEL; }
"maxFallDistance" { BEGIN(TYPE_OTHER); return MAXFALLDISTANCE; }
"codeSeed" { BEGIN(TYPE_OTHER); return CODESEED; }
"music_" { BEGIN(TYPE_STR); return MUSIC; }
"level_" { BEGIN(TYPE_OTHER); return LEVEL; }
"fun_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"tricky_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"taxing_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"mayhem_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"tame_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"wild_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"crazy_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"wicked_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"havoc_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
"pixels_" { BEGIN(TYPE_OTHER); return DIFFICULTY; }
/* TYPE_* states for catching the '=' token and go in the right state machine for catching values */
<TYPE_STR>"="{BLANK}* { BEGIN(VAL_STR); return AFF; }
<TYPE_OTHER>"=" { BEGIN(VAL_OTHER); return AFF; }
<TYPE_STR,TYPE_OTHER,VAL_OTHER>{INTEGER} { yylval.num = atoi(yytext); return INT; }
<VAL_OTHER>{INTHEX} { int res=sscanf(yytext, "0x%x", &yylval.uint32); if(res) return INTHEX; else return LEXERROR; }
<VAL_OTHER>{STRCSV} { return string(STR); }
<VAL_OTHER>"," { return VIR; }
<VAL_STR>[^\r\n]+ { return string(STR); }
|