Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
mv gs/ DataDesc/
[simgrid.git] / src / gras / DataDesc / parse.yy.l
1 /**** MSG_LICENCE DO NOT REMOVE ****/
2
3 %option noyywrap
4 %{
5 #include"gs/gs_private.h"
6 #include"gs/parse.yy.h"
7 #include <string.h>
8   YY_BUFFER_STATE input_buffer;
9   FILE *file_to_parse;
10
11   int gs_parse_line_pos = 1;
12   int gs_parse_char_pos = 0;
13   int gs_parse_tok_num = 0;
14 %}
15
16 %x comment foo str
17 space           [ \t]
18 letter          [A-Za-z._-]
19 digit           [0-9]
20
21 %%
22         int comment_caller=0;
23
24         char string_buf[GS_PARSE_MAX_STR_CONST];
25         char *string_buf_ptr = NULL;
26
27 "//"[^\n]*
28 "/*"         {
29              comment_caller = INITIAL;
30              BEGIN(comment);
31              }
32
33 <foo>"/*"    {
34              comment_caller = foo;
35              BEGIN(comment);
36              }
37
38 <comment>[^*\n]*        /* eat anything that's not a '*' */
39 <comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
40 <comment>\n             {++gs_parse_line_pos;gs_parse_char_pos=0;}
41 <comment>"*"+"/"        BEGIN(comment_caller);
42
43 \"      string_buf_ptr = string_buf; gs_parse_char_pos++; BEGIN(str);
44
45 <str>\"        { /* saw closing quote - all done */
46         BEGIN(INITIAL);
47         *string_buf_ptr = '\0';
48         yytext=string_buf;
49         gs_parse_char_pos++;
50         return GS_PARSE_TOKEN_WORD;
51         /* return string constant token type and
52          * value to parser
53          */
54         }
55
56 <str>\n        {
57         /* error - unterminated string constant */
58         /* generate error message */
59         }
60
61 <str>\\[0-7]{1,3} {
62         /* octal escape sequence */
63         int result;
64
65         (void) sscanf( yytext + 1, "%o", &result );
66
67         if ( result > 0xff )
68                 /* error, constant is out-of-bounds */
69
70         *string_buf_ptr++ = result;
71         gs_parse_char_pos++;
72         }
73
74 <str>\\[0-9]+ {
75         /* generate error - bad escape sequence; something
76          * like '\48' or '\0777777'
77          */
78         }
79
80 <str>\\n  {*string_buf_ptr++ = '\n';    gs_parse_char_pos++;}
81 <str>\\t  {*string_buf_ptr++ = '\t';    gs_parse_char_pos++;}
82 <str>\\r  {*string_buf_ptr++ = '\r';    gs_parse_char_pos++;}
83 <str>\\b  {*string_buf_ptr++ = '\b';    gs_parse_char_pos++;}
84 <str>\\f  {*string_buf_ptr++ = '\f';    gs_parse_char_pos++;}
85
86 <str>\\(.|\n)  {*string_buf_ptr++ = yytext[1];  
87                 if(yytext[1]=='\n') {
88                   ++gs_parse_line_pos;gs_parse_char_pos=0;
89                 } else { gs_parse_char_pos++;}
90                }
91
92 <str>[^\\\n\"]+        {
93         char *yptr = yytext;
94
95         while ( *yptr )
96           *string_buf_ptr++ = *yptr++;
97           gs_parse_char_pos++;
98         }
99
100 ({letter}|{digit})*     { gs_parse_char_pos+= strlen(yytext); return(GS_PARSE_TOKEN_WORD);}
101 "{"                     { gs_parse_char_pos++; return(GS_PARSE_TOKEN_LP);}
102 "}"                     { gs_parse_char_pos++;return(GS_PARSE_TOKEN_RP);}
103 "*"                     { gs_parse_char_pos++;return(GS_PARSE_TOKEN_STAR);}
104 ";"                     { gs_parse_char_pos++;return(GS_PARSE_TOKEN_SEMI_COLON);}
105 ","                     { gs_parse_char_pos++;return(GS_PARSE_TOKEN_COLON);}
106 "\n"                    { gs_parse_line_pos++; gs_parse_char_pos=0;}
107 . { gs_parse_char_pos++;}
108 %%
109 /* {space}+                { return(TOKEN_SPACE);} */
110
111 void gs_parse_dump(void) {
112   switch(gs_parse_tok_num) {
113   case GS_PARSE_TOKEN_LP      : {printf("TOKEN_LP ");break;}
114   case GS_PARSE_TOKEN_RP      : {printf("TOKEN_RP ");break;}
115   case GS_PARSE_TOKEN_WORD    : {printf("TOKEN_WORD ");break;}
116     //  case GS_PARSE_TOKEN_SPACE   : {printf("TOKEN_SPACE ");break;}
117     //  case GS_PARSE_TOKEN_COMMENT : {printf("TOKEN_COMMENT ");break;}
118   case GS_PARSE_TOKEN_NEWLINE : {printf("TOKEN_NEWLINE\n");return;}
119   case GS_PARSE_TOKEN_EMPTY : {printf("TOKEN_EMPTY\n");return;}
120   default             : {printf("Unknown token %d\n", gs_parse_tok_num);return;}
121   }
122   printf("-->%s<-- [line %d, pos %d]\n",yytext,gs_parse_line_pos,gs_parse_char_pos);
123   return;
124 }
125
126 int gs_parse_lex_n_dump(void) {
127   gs_parse_tok_num = gs_parse_lex();
128   //  voir_val();
129   //  gs_parse_char_pos += strlen(yytext);
130   return(gs_parse_tok_num);
131 }
132
133 void  gs_parse_pointer_init(const char *file) {
134   file_to_parse = fopen(file,"r");
135   input_buffer = yy_create_buffer( file_to_parse, 10 );
136   yy_switch_to_buffer(input_buffer);
137
138   gs_parse_line_pos = 1;
139   gs_parse_char_pos = 0;
140   gs_parse_tok_num = 0;
141 }
142
143 void  gs_parse_pointer_close(void) {
144   yy_delete_buffer(input_buffer);
145   fclose(file_to_parse);
146
147   gs_parse_line_pos = 1;
148   gs_parse_char_pos = 0;
149   gs_parse_tok_num = 0;
150 }
151
152
153 void  gs_parse_pointer_string_init(const char *string_to_parse) {
154   input_buffer = yy_scan_string (string_to_parse);
155   yy_switch_to_buffer(input_buffer);
156
157   gs_parse_line_pos = 1;
158   gs_parse_char_pos = 0;
159   gs_parse_tok_num = 0;
160 }
161
162 void  gs_parse_pointer_string_close(void) {
163   yy_delete_buffer(input_buffer);
164
165   gs_parse_line_pos = 1;
166   gs_parse_char_pos = 0;
167   gs_parse_tok_num = 0;
168 }
169
170 // Local variables:
171 // mode: c
172 // End: