~ubuntu-branches/ubuntu/raring/simgrid/raring

« back to all changes in this revision

Viewing changes to src/xbt/datadesc/ddt_parse.yy.l

  • Committer: Package Import Robot
  • Author(s): Lucas Nussbaum
  • Date: 2012-05-24 16:08:59 UTC
  • mfrom: (10.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20120524160859-vhdlh05p313l5662
Tags: 3.7-1
* New upstream release.
* Bump Standards-Version to 3.9.3. No changes needed.
* debian/rules: Enable the SMPI library in the package. Closes: #656102.
* Build with -O2 on ia64. Closes: #640538.
* Use dpkg-buildflags to generate CFLAGS and LDFLAGS. Enable hardening.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 "xbt/datadesc/datadesc_private.h"
 
11
#include "xbt/datadesc/ddt_parse.yy.h"
 
12
#include <string.h>
 
13
  YY_BUFFER_STATE xbt_ddt_input_buffer;
 
14
  FILE *xbt_ddt_file_to_parse;
 
15
 
 
16
  int xbt_ddt_parse_line_pos = 1;
 
17
  int xbt_ddt_parse_col_pos = 0;
 
18
  int xbt_ddt_parse_char_pos = 0;
 
19
  int xbt_ddt_parse_tok_num = 0;
 
20
  const char *definition;
 
21
  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(xbt_ddt_lexer,xbt_ddt_parse,"The crude internals of the lexer used for type parsing");
 
22
#define SHOW_WHERE XBT_DEBUG("%d:%d (char #%d): seen '%s'", xbt_ddt_parse_line_pos,xbt_ddt_parse_col_pos,xbt_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
  XBT_DEBUG("Begin annotation");
 
38
  annotate_caller = INITIAL;
 
39
  xbt_ddt_parse_char_pos+= strlen(yytext);
 
40
  xbt_ddt_parse_col_pos+= strlen(yytext);
 
41
  BEGIN(annotate);
 
42
}
 
43
<foo>"/*g"{space}* { /* trim annotation */
 
44
  XBT_DEBUG("Begin annotation");
 
45
  annotate_caller = foo;
 
46
  xbt_ddt_parse_char_pos+= strlen(yytext);
 
47
  xbt_ddt_parse_col_pos+= strlen(yytext);
 
48
  BEGIN(annotate);
 
49
}
 
50
 
 
51
<annotate>{space}*"g*/" {
 
52
  XBT_DEBUG("End annotation");
 
53
  xbt_ddt_parse_char_pos+= strlen(yytext);
 
54
  xbt_ddt_parse_col_pos+= strlen(yytext);
 
55
  BEGIN(annotate_caller);
 
56
}
 
57
 
 
58
<annotate>"*/" {
 
59
  PARSE_ERROR("``/*g'' construct closed by a regular ``*/''");
 
60
}
 
61
<annotate>\n  {
 
62
  PARSE_ERROR("Type annotation cannot spread over several lines");
 
63
}
 
64
 
 
65
<annotate>.* { /* eat the rest */
 
66
  xbt_ddt_parse_char_pos+= strlen(yytext);
 
67
  xbt_ddt_parse_col_pos+= strlen(yytext);
 
68
  return XBT_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
  ++xbt_ddt_parse_line_pos;
 
90
  xbt_ddt_parse_col_pos=0;
 
91
  xbt_ddt_parse_char_pos++;
 
92
}
 
93
<comment>"*"+"/" {
 
94
  xbt_ddt_parse_char_pos+= strlen(yytext);
 
95
  xbt_ddt_parse_col_pos+= strlen(yytext);
 
96
  BEGIN(comment_caller);
 
97
}
 
98
 
 
99
({letter}|{digit})* {  /****************** STATEMENTS ************************/
 
100
  xbt_ddt_parse_char_pos += strlen(yytext);
 
101
  xbt_ddt_parse_col_pos += strlen(yytext);
 
102
  SHOW_WHERE;
 
103
  return(XBT_DDT_PARSE_TOKEN_WORD);
 
104
}
 
105
"{"  { 
 
106
  xbt_ddt_parse_char_pos++; 
 
107
  xbt_ddt_parse_col_pos++; 
 
108
  SHOW_WHERE;
 
109
  return(XBT_DDT_PARSE_TOKEN_LA);
 
110
}
 
111
"}" {
 
112
  xbt_ddt_parse_char_pos++;
 
113
  xbt_ddt_parse_col_pos++;
 
114
  SHOW_WHERE;
 
115
  return(XBT_DDT_PARSE_TOKEN_RA);
 
116
}
 
117
"["  { 
 
118
  xbt_ddt_parse_char_pos++; 
 
119
  xbt_ddt_parse_col_pos++; 
 
120
  SHOW_WHERE;
 
121
  return(XBT_DDT_PARSE_TOKEN_LB);
 
122
}
 
123
"]" {
 
124
  xbt_ddt_parse_char_pos++;
 
125
  xbt_ddt_parse_col_pos++;
 
126
  SHOW_WHERE;
 
127
  return(XBT_DDT_PARSE_TOKEN_RB);
 
128
}
 
129
"("  { 
 
130
  xbt_ddt_parse_char_pos++; 
 
131
  xbt_ddt_parse_col_pos++; 
 
132
  SHOW_WHERE;
 
133
  return(XBT_DDT_PARSE_TOKEN_LP);
 
134
}
 
135
")" {
 
136
  xbt_ddt_parse_char_pos++;
 
137
  xbt_ddt_parse_col_pos++;
 
138
  SHOW_WHERE;
 
139
  return(XBT_DDT_PARSE_TOKEN_RP);
 
140
}
 
141
"*" {
 
142
  xbt_ddt_parse_char_pos++;
 
143
  xbt_ddt_parse_col_pos++;
 
144
  SHOW_WHERE;
 
145
  return(XBT_DDT_PARSE_TOKEN_STAR);
 
146
}
 
147
";" {
 
148
  xbt_ddt_parse_char_pos++;
 
149
  xbt_ddt_parse_col_pos++;
 
150
  SHOW_WHERE;
 
151
  return(XBT_DDT_PARSE_TOKEN_SEMI_COLON);
 
152
}
 
153
"," { 
 
154
  xbt_ddt_parse_char_pos++;
 
155
  xbt_ddt_parse_col_pos++;
 
156
  SHOW_WHERE;
 
157
  return(XBT_DDT_PARSE_TOKEN_COLON);
 
158
}
 
159
"\n" {
 
160
 xbt_ddt_parse_line_pos++; 
 
161
 xbt_ddt_parse_char_pos++;
 
162
 xbt_ddt_parse_col_pos=0;
 
163
  SHOW_WHERE;
 
164
}
 
165
. { 
 
166
  xbt_ddt_parse_char_pos++;
 
167
  xbt_ddt_parse_col_pos++;
 
168
  SHOW_WHERE;
 
169
}
 
170
%%
 
171
/* {space}+                { return(TOKEN_SPACE);} */
 
172
 
 
173
void xbt_ddt_parse_dump(void) {
 
174
  switch(xbt_ddt_parse_tok_num) {
 
175
  case XBT_DDT_PARSE_TOKEN_LA      : {printf("TOKEN_LA ");break;}
 
176
  case XBT_DDT_PARSE_TOKEN_RA      : {printf("TOKEN_RA ");break;}
 
177
  case XBT_DDT_PARSE_TOKEN_WORD    : {printf("TOKEN_WORD ");break;}
 
178
    /*  case XBT_DDT_PARSE_TOKEN_SPACE   : {printf("TOKEN_SPACE ");break;}*/
 
179
    /*  case XBT_DDT_PARSE_TOKEN_COMMENT : {printf("TOKEN_COMMENT ");break;}*/
 
180
  case XBT_DDT_PARSE_TOKEN_NEWLINE : {printf("TOKEN_NEWLINE\n");return;}
 
181
  case XBT_DDT_PARSE_TOKEN_EMPTY : {printf("TOKEN_EMPTY\n");return;}
 
182
  default             : {printf("Unknown token %d\n", xbt_ddt_parse_tok_num);return;}
 
183
  }
 
184
  printf("-->%s<-- [line %d, pos %d]\n",yytext,xbt_ddt_parse_line_pos,xbt_ddt_parse_char_pos);
 
185
  return;
 
186
}
 
187
 
 
188
int xbt_ddt_parse_lex_n_dump(void) {
 
189
  xbt_ddt_parse_tok_num = xbt_ddt_parse_lex();
 
190
  /*  xbt_ddt_parse_char_pos += strlen(yytext);*/
 
191
  return(xbt_ddt_parse_tok_num);
 
192
}
 
193
 
 
194
void  xbt_ddt_parse_pointer_init(const char *file) {
 
195
  xbt_ddt_file_to_parse = fopen(file,"r");
 
196
  xbt_ddt_input_buffer = yy_create_buffer( xbt_ddt_file_to_parse, 10 );
 
197
  yy_switch_to_buffer(xbt_ddt_input_buffer);
 
198
 
 
199
  xbt_ddt_parse_line_pos = 1;
 
200
  xbt_ddt_parse_char_pos = 0;
 
201
  xbt_ddt_parse_col_pos = 0;
 
202
  xbt_ddt_parse_tok_num = 0;
 
203
}
 
204
 
 
205
void  xbt_ddt_parse_pointer_close(void) {
 
206
  yy_delete_buffer(xbt_ddt_input_buffer);
 
207
  fclose(xbt_ddt_file_to_parse);
 
208
 
 
209
  xbt_ddt_parse_line_pos = 1;
 
210
  xbt_ddt_parse_char_pos = 0;
 
211
  xbt_ddt_parse_tok_num = 0;
 
212
}
 
213
 
 
214
 
 
215
void  xbt_ddt_parse_pointer_string_init(const char *string_to_parse) {
 
216
  xbt_ddt_input_buffer = yy_scan_string (string_to_parse);
 
217
  definition = string_to_parse;
 
218
  yy_switch_to_buffer(xbt_ddt_input_buffer);
 
219
 
 
220
  xbt_ddt_parse_line_pos = 1;
 
221
  xbt_ddt_parse_char_pos = 0;
 
222
  xbt_ddt_parse_tok_num = 0;
 
223
}
 
224
 
 
225
void  xbt_ddt_parse_pointer_string_close(void) {
 
226
  yy_delete_buffer(xbt_ddt_input_buffer);
 
227
 
 
228
  xbt_ddt_parse_line_pos = 1;
 
229
  xbt_ddt_parse_char_pos = 0;
 
230
  xbt_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: */