Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Regenerate with newest flex, so that new gcc paranoia get dealt with
[simgrid.git] / src / gras / DataDesc / ddt_parse.yy.l
1 /* $Id$ */
2
3 /* DataDesc/ddt_parse -- automatic parsing of data structures */
4
5 /* Copyright (c) 2004 Arnaud Legrand, Martin Quinson. All rights reserved.  */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 %option noyywrap
11 %{
12 #include "gras/DataDesc/datadesc_private.h"
13 #include "gras/DataDesc/ddt_parse.yy.h"
14 #include <string.h>
15   YY_BUFFER_STATE gras_ddt_input_buffer;
16   FILE *gras_ddt_file_to_parse;
17
18   int gras_ddt_parse_line_pos = 1;
19   int gras_ddt_parse_col_pos = 0;
20   int gras_ddt_parse_char_pos = 0;
21   int gras_ddt_parse_tok_num = 0;
22   const char *definition;
23   XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras_ddt_lexer,gras_ddt_parse,"The crude internals of the lexer used for type parsing");
24 #define SHOW_WHERE DEBUG4("%d:%d (char #%d): seen '%s'", gras_ddt_parse_line_pos,gras_ddt_parse_col_pos,gras_ddt_parse_char_pos,yytext)
25 %}
26
27 %x annotate comment foo
28 space           [ \t]
29 letter          [A-Za-z._-]
30 digit           [0-9]
31
32 %%
33    int comment_caller=0;
34    int annotate_caller=0;
35
36 "//"[^\n]*
37
38 "/*g"{space}* { /****************** ANNOTATION ************************/
39   DEBUG0("Begin annotation");
40   annotate_caller = INITIAL;
41   gras_ddt_parse_char_pos+= strlen(yytext);
42   gras_ddt_parse_col_pos+= strlen(yytext);
43   BEGIN(annotate);
44 }
45 <foo>"/*g"{space}* { /* trim annotation */
46   DEBUG0("Begin annotation");
47   annotate_caller = foo;
48   gras_ddt_parse_char_pos+= strlen(yytext);
49   gras_ddt_parse_col_pos+= strlen(yytext);
50   BEGIN(annotate);
51 }
52
53 <annotate>{space}*"g*/" {
54   DEBUG0("End annotation");
55   gras_ddt_parse_char_pos+= strlen(yytext);
56   gras_ddt_parse_col_pos+= strlen(yytext);
57   BEGIN(annotate_caller);
58 }
59
60 <annotate>"*/" {
61   PARSE_ERROR0("``/*g'' construct closed by a regular ``*/''");
62 }
63 <annotate>\n  {
64   PARSE_ERROR0("Type annotation cannot spread over several lines");
65 }
66
67 <annotate>.* { /* eat the rest */
68   gras_ddt_parse_char_pos+= strlen(yytext);
69   gras_ddt_parse_col_pos+= strlen(yytext);
70   return GRAS_DDT_PARSE_TOKEN_ANNOTATE;
71 }
72
73 "/*[^g]"   { /****************** COMMENTS ************************/
74   /* constructs like : */
75     /*g [string] g*/ 
76   /* are not comments but size annotations */
77   comment_caller = INITIAL;
78   BEGIN(comment);
79 }
80
81 <foo>"/*[^g]"    {
82   comment_caller = foo;
83   BEGIN(comment);
84 }
85
86 <comment>[^*\n]*      { /* eat anything that's not a '*' */
87 }
88 <comment>"*"+[^*/\n]* { /* eat up '*'s not followed by '/'s */
89 }
90 <comment>\n             {
91   ++gras_ddt_parse_line_pos;
92   gras_ddt_parse_col_pos=0;
93   gras_ddt_parse_char_pos++;
94 }
95 <comment>"*"+"/" {
96   gras_ddt_parse_char_pos+= strlen(yytext);
97   gras_ddt_parse_col_pos+= strlen(yytext);
98   BEGIN(comment_caller);
99 }
100
101 ({letter}|{digit})* {  /****************** STATEMENTS ************************/
102   gras_ddt_parse_char_pos += strlen(yytext);
103   gras_ddt_parse_col_pos += strlen(yytext);
104   SHOW_WHERE;
105   return(GRAS_DDT_PARSE_TOKEN_WORD);
106 }
107 "{"  { 
108   gras_ddt_parse_char_pos++; 
109   gras_ddt_parse_col_pos++; 
110   SHOW_WHERE;
111   return(GRAS_DDT_PARSE_TOKEN_LA);
112 }
113 "}" {
114   gras_ddt_parse_char_pos++;
115   gras_ddt_parse_col_pos++;
116   SHOW_WHERE;
117   return(GRAS_DDT_PARSE_TOKEN_RA);
118 }
119 "["  { 
120   gras_ddt_parse_char_pos++; 
121   gras_ddt_parse_col_pos++; 
122   SHOW_WHERE;
123   return(GRAS_DDT_PARSE_TOKEN_LB);
124 }
125 "]" {
126   gras_ddt_parse_char_pos++;
127   gras_ddt_parse_col_pos++;
128   SHOW_WHERE;
129   return(GRAS_DDT_PARSE_TOKEN_RB);
130 }
131 "("  { 
132   gras_ddt_parse_char_pos++; 
133   gras_ddt_parse_col_pos++; 
134   SHOW_WHERE;
135   return(GRAS_DDT_PARSE_TOKEN_LP);
136 }
137 ")" {
138   gras_ddt_parse_char_pos++;
139   gras_ddt_parse_col_pos++;
140   SHOW_WHERE;
141   return(GRAS_DDT_PARSE_TOKEN_RP);
142 }
143 "*" {
144   gras_ddt_parse_char_pos++;
145   gras_ddt_parse_col_pos++;
146   SHOW_WHERE;
147   return(GRAS_DDT_PARSE_TOKEN_STAR);
148 }
149 ";" {
150   gras_ddt_parse_char_pos++;
151   gras_ddt_parse_col_pos++;
152   SHOW_WHERE;
153   return(GRAS_DDT_PARSE_TOKEN_SEMI_COLON);
154 }
155 "," { 
156   gras_ddt_parse_char_pos++;
157   gras_ddt_parse_col_pos++;
158   SHOW_WHERE;
159   return(GRAS_DDT_PARSE_TOKEN_COLON);
160 }
161 "\n" {
162  gras_ddt_parse_line_pos++; 
163  gras_ddt_parse_char_pos++;
164  gras_ddt_parse_col_pos=0;
165   SHOW_WHERE;
166 }
167 . { 
168   gras_ddt_parse_char_pos++;
169   gras_ddt_parse_col_pos++;
170   SHOW_WHERE;
171 }
172 %%
173 /* {space}+                { return(TOKEN_SPACE);} */
174
175 void gras_ddt_parse_dump(void) {
176   switch(gras_ddt_parse_tok_num) {
177   case GRAS_DDT_PARSE_TOKEN_LA      : {printf("TOKEN_LA ");break;}
178   case GRAS_DDT_PARSE_TOKEN_RA      : {printf("TOKEN_RA ");break;}
179   case GRAS_DDT_PARSE_TOKEN_WORD    : {printf("TOKEN_WORD ");break;}
180     /*  case GRAS_DDT_PARSE_TOKEN_SPACE   : {printf("TOKEN_SPACE ");break;}*/
181     /*  case GRAS_DDT_PARSE_TOKEN_COMMENT : {printf("TOKEN_COMMENT ");break;}*/
182   case GRAS_DDT_PARSE_TOKEN_NEWLINE : {printf("TOKEN_NEWLINE\n");return;}
183   case GRAS_DDT_PARSE_TOKEN_EMPTY : {printf("TOKEN_EMPTY\n");return;}
184   default             : {printf("Unknown token %d\n", gras_ddt_parse_tok_num);return;}
185   }
186   printf("-->%s<-- [line %d, pos %d]\n",yytext,gras_ddt_parse_line_pos,gras_ddt_parse_char_pos);
187   return;
188 }
189
190 int gras_ddt_parse_lex_n_dump(void) {
191   gras_ddt_parse_tok_num = gras_ddt_parse_lex();
192   /*  gras_ddt_parse_char_pos += strlen(yytext);*/
193   return(gras_ddt_parse_tok_num);
194 }
195
196 void  gras_ddt_parse_pointer_init(const char *file) {
197   gras_ddt_file_to_parse = fopen(file,"r");
198   gras_ddt_input_buffer = yy_create_buffer( gras_ddt_file_to_parse, 10 );
199   yy_switch_to_buffer(gras_ddt_input_buffer);
200
201   gras_ddt_parse_line_pos = 1;
202   gras_ddt_parse_char_pos = 0;
203   gras_ddt_parse_col_pos = 0;
204   gras_ddt_parse_tok_num = 0;
205 }
206
207 void  gras_ddt_parse_pointer_close(void) {
208   yy_delete_buffer(gras_ddt_input_buffer);
209   fclose(gras_ddt_file_to_parse);
210
211   gras_ddt_parse_line_pos = 1;
212   gras_ddt_parse_char_pos = 0;
213   gras_ddt_parse_tok_num = 0;
214 }
215
216
217 void  gras_ddt_parse_pointer_string_init(const char *string_to_parse) {
218   gras_ddt_input_buffer = yy_scan_string (string_to_parse);
219   definition = string_to_parse;
220   yy_switch_to_buffer(gras_ddt_input_buffer);
221
222   gras_ddt_parse_line_pos = 1;
223   gras_ddt_parse_char_pos = 0;
224   gras_ddt_parse_tok_num = 0;
225 }
226
227 void  gras_ddt_parse_pointer_string_close(void) {
228   yy_delete_buffer(gras_ddt_input_buffer);
229
230   gras_ddt_parse_line_pos = 1;
231   gras_ddt_parse_char_pos = 0;
232   gras_ddt_parse_tok_num = 0;
233
234   if (0)
235     yyunput('\0',NULL); /* fake a use of this function to calm gcc down */
236 }
237
238 /* Local variables:*/
239 /* mode: c */
240 /* End: */