Logo AND Algorithmique Numérique Distribuée

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