Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Kill dead cruft
[simgrid.git] / src / gras / DataDesc / ddt_parse.yy.l
index ee56c54..4a633ee 100644 (file)
 
 /* DataDesc/ddt_parse -- automatic parsing of data structures */
 
-/* Authors: Arnaud Legrand, Martin Quinson            */
-/* Copyright (C) 2003, 2004 Martin Quinson.                                 */
+/* Copyright (c) 2004 Arnaud Legrand, Martin Quinson. All rights reserved.  */
 
 /* This program is free software; you can redistribute it and/or modify it
  under the terms of the license (GNU LGPL) which comes with this package. */
* under the terms of the license (GNU LGPL) which comes with this package. */
 
 %option noyywrap
 %{
-#include"DataDesc/datadesc_private.h"
-#include"DataDesc/ddt_parse.yy.h"
+#include "gras/DataDesc/datadesc_private.h"
+#include "gras/DataDesc/ddt_parse.yy.h"
 #include <string.h>
-  YY_BUFFER_STATE input_buffer;
-  FILE *file_to_parse;
+  YY_BUFFER_STATE gras_ddt_input_buffer;
+  FILE *gras_ddt_file_to_parse;
 
   int gras_ddt_parse_line_pos = 1;
   int gras_ddt_parse_col_pos = 0;
   int gras_ddt_parse_char_pos = 0;
   int gras_ddt_parse_tok_num = 0;
-  GRAS_LOG_NEW_DEFAULT_SUBCATEGORY(lexer,parse);
-#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)
+  const char *definition;
+  XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lexer,ddt_parse,"The crude internals of the lexer used for type parsing");
+#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)
 %}
 
-%x comment foo str
+%x annotate comment foo
 space           [ \t]
 letter          [A-Za-z._-]
 digit           [0-9]
 
 %%
-        int comment_caller=0;
-
-        char string_buf[GRAS_DDT_PARSE_MAX_STR_CONST];
-        char *string_buf_ptr = NULL;
+   int comment_caller=0;
+   int annotate_caller=0;
 
 "//"[^\n]*
-"/*"         {
-             comment_caller = INITIAL;
-             BEGIN(comment);
-             }
-
-<foo>"/*"    {
-             comment_caller = foo;
-             BEGIN(comment);
-             }
 
-<comment>[^*\n]*        /* eat anything that's not a '*' */
-<comment>"*"+[^*/\n]*   /* eat up '*'s not followed by '/'s */
-<comment>\n             {
-  ++gras_ddt_parse_line_pos;
-  gras_ddt_parse_col_pos=0;
-  gras_ddt_parse_char_pos++;
+"/*g"{space}* { /****************** ANNOTATION ************************/
+  DEBUG0("Begin annotation");
+  annotate_caller = INITIAL;
+  gras_ddt_parse_char_pos+= strlen(yytext);
+  gras_ddt_parse_col_pos+= strlen(yytext);
+  BEGIN(annotate);
+}
+<foo>"/*g"{space}* { /* trim annotation */
+  DEBUG0("Begin annotation");
+  annotate_caller = foo;
+  gras_ddt_parse_char_pos+= strlen(yytext);
+  gras_ddt_parse_col_pos+= strlen(yytext);
+  BEGIN(annotate);
 }
-<comment>"*"+"/"        BEGIN(comment_caller);
-
-\"      string_buf_ptr = string_buf; gras_ddt_parse_char_pos++;gras_ddt_parse_col_pos++; BEGIN(str);
-
-<str>\"        { /* saw closing quote - all done */
-        BEGIN(INITIAL);
-        *string_buf_ptr = '\0';
-       yytext=string_buf;
-       gras_ddt_parse_char_pos++;
-       gras_ddt_parse_col_pos++;
-       return GRAS_DDT_PARSE_TOKEN_WORD;
-        /* return string constant token type and
-         * value to parser
-         */
-        }
-
-<str>\n        {
-        /* error - unterminated string constant */
-        /* generate error message */
-        }
-
-<str>\\[0-7]{1,3} {
-        /* octal escape sequence */
-        int result;
-
-        (void) sscanf( yytext + 1, "%o", &result );
-
-        if ( result > 0xff )
-                /* error, constant is out-of-bounds */
-
-        *string_buf_ptr++ = result;
-       gras_ddt_parse_char_pos++;
-       gras_ddt_parse_col_pos++;
-        }
-
-<str>\\[0-9]+ {
-        /* generate error - bad escape sequence; something
-         * like '\48' or '\0777777'
-         */
-        }
 
-<str>\\n  {
-  *string_buf_ptr++ = '\n';
-  gras_ddt_parse_char_pos++;
-  gras_ddt_parse_col_pos++;
+<annotate>{space}*"g*/" {
+  DEBUG0("End annotation");
+  gras_ddt_parse_char_pos+= strlen(yytext);
+  gras_ddt_parse_col_pos+= strlen(yytext);
+  BEGIN(annotate_caller);
 }
-<str>\\t  {
-  *string_buf_ptr++ = '\t';    
-  gras_ddt_parse_char_pos++;
-  gras_ddt_parse_col_pos++;
+
+<annotate>"*/" {
+  PARSE_ERROR0("``/*g'' construct closed by a regular ``*/''");
 }
-<str>\\r  {
-  *string_buf_ptr++ = '\r';    
-  gras_ddt_parse_char_pos++;
-  gras_ddt_parse_col_pos++;
+<annotate>\n  {
+  PARSE_ERROR0("Type annotation cannot spread over several lines");
 }
-<str>\\b  {
-  *string_buf_ptr++ = '\b';    
-  gras_ddt_parse_char_pos++;
-  gras_ddt_parse_col_pos++;
+
+<annotate>.* { /* eat the rest */
+  gras_ddt_parse_char_pos+= strlen(yytext);
+  gras_ddt_parse_col_pos+= strlen(yytext);
+  return GRAS_DDT_PARSE_TOKEN_ANNOTATE;
 }
-<str>\\f  {
-  *string_buf_ptr++ = '\f';
-  gras_ddt_parse_char_pos++;
-  gras_ddt_parse_col_pos++;
+
+"/*[^g]"   { /****************** COMMENTS ************************/
+  /* constructs like : */
+    /*g [string] g*/ 
+  /* are not comments but size annotations */
+  comment_caller = INITIAL;
+  BEGIN(comment);
 }
 
-<str>\\(.|\n)  {
-  *string_buf_ptr++ = yytext[1];       
-  if(yytext[1]=='\n') {
-    ++gras_ddt_parse_line_pos;
-    gras_ddt_parse_col_pos=0;
-  } else {
-    gras_ddt_parse_col_pos++;
-  }
-  gras_ddt_parse_char_pos++;
+<foo>"/*[^g]"    {
+  comment_caller = foo;
+  BEGIN(comment);
 }
 
-<str>[^\\\n\"]+  {
-  char *yptr = yytext;
-  
-  while ( *yptr )
-    *string_buf_ptr++ = *yptr++;
+<comment>[^*\n]*      { /* eat anything that's not a '*' */
+}
+<comment>"*"+[^*/\n]* { /* eat up '*'s not followed by '/'s */
+}
+<comment>\n             {
+  ++gras_ddt_parse_line_pos;
+  gras_ddt_parse_col_pos=0;
   gras_ddt_parse_char_pos++;
-  gras_ddt_parse_col_pos++;
 }
-
-({letter}|{digit})* { 
+<comment>"*"+"/" {
   gras_ddt_parse_char_pos+= strlen(yytext);
   gras_ddt_parse_col_pos+= strlen(yytext);
+  BEGIN(comment_caller);
+}
+
+({letter}|{digit})* {  /****************** STATEMENTS ************************/
+  gras_ddt_parse_char_pos += strlen(yytext);
+  gras_ddt_parse_col_pos += strlen(yytext);
+  SHOW_WHERE;
   return(GRAS_DDT_PARSE_TOKEN_WORD);
 }
 "{"  { 
   gras_ddt_parse_char_pos++; 
   gras_ddt_parse_col_pos++; 
   SHOW_WHERE;
-  return(GRAS_DDT_PARSE_TOKEN_LP);
+  return(GRAS_DDT_PARSE_TOKEN_LA);
 }
 "}" {
   gras_ddt_parse_char_pos++;
   gras_ddt_parse_col_pos++;
   SHOW_WHERE;
-  return(GRAS_DDT_PARSE_TOKEN_RP);
+  return(GRAS_DDT_PARSE_TOKEN_RA);
 }
 "["  { 
   gras_ddt_parse_char_pos++; 
@@ -169,6 +128,18 @@ digit           [0-9]
   SHOW_WHERE;
   return(GRAS_DDT_PARSE_TOKEN_RB);
 }
+"("  { 
+  gras_ddt_parse_char_pos++; 
+  gras_ddt_parse_col_pos++; 
+  SHOW_WHERE;
+  return(GRAS_DDT_PARSE_TOKEN_LP);
+}
+")" {
+  gras_ddt_parse_char_pos++;
+  gras_ddt_parse_col_pos++;
+  SHOW_WHERE;
+  return(GRAS_DDT_PARSE_TOKEN_RP);
+}
 "*" {
   gras_ddt_parse_char_pos++;
   gras_ddt_parse_col_pos++;
@@ -203,11 +174,11 @@ digit           [0-9]
 
 void gras_ddt_parse_dump(void) {
   switch(gras_ddt_parse_tok_num) {
-  case GRAS_DDT_PARSE_TOKEN_LP      : {printf("TOKEN_LP ");break;}
-  case GRAS_DDT_PARSE_TOKEN_RP      : {printf("TOKEN_RP ");break;}
+  case GRAS_DDT_PARSE_TOKEN_LA      : {printf("TOKEN_LA ");break;}
+  case GRAS_DDT_PARSE_TOKEN_RA      : {printf("TOKEN_RA ");break;}
   case GRAS_DDT_PARSE_TOKEN_WORD    : {printf("TOKEN_WORD ");break;}
-    //  case GRAS_DDT_PARSE_TOKEN_SPACE   : {printf("TOKEN_SPACE ");break;}
-    //  case GRAS_DDT_PARSE_TOKEN_COMMENT : {printf("TOKEN_COMMENT ");break;}
+    /*  case GRAS_DDT_PARSE_TOKEN_SPACE   : {printf("TOKEN_SPACE ");break;}*/
+    /*  case GRAS_DDT_PARSE_TOKEN_COMMENT : {printf("TOKEN_COMMENT ");break;}*/
   case GRAS_DDT_PARSE_TOKEN_NEWLINE : {printf("TOKEN_NEWLINE\n");return;}
   case GRAS_DDT_PARSE_TOKEN_EMPTY : {printf("TOKEN_EMPTY\n");return;}
   default             : {printf("Unknown token %d\n", gras_ddt_parse_tok_num);return;}
@@ -218,14 +189,14 @@ void gras_ddt_parse_dump(void) {
 
 int gras_ddt_parse_lex_n_dump(void) {
   gras_ddt_parse_tok_num = gras_ddt_parse_lex();
-  //  gras_ddt_parse_char_pos += strlen(yytext);
+  /*  gras_ddt_parse_char_pos += strlen(yytext);*/
   return(gras_ddt_parse_tok_num);
 }
 
 void  gras_ddt_parse_pointer_init(const char *file) {
-  file_to_parse = fopen(file,"r");
-  input_buffer = yy_create_buffer( file_to_parse, 10 );
-  yy_switch_to_buffer(input_buffer);
+  gras_ddt_file_to_parse = fopen(file,"r");
+  gras_ddt_input_buffer = yy_create_buffer( gras_ddt_file_to_parse, 10 );
+  yy_switch_to_buffer(gras_ddt_input_buffer);
 
   gras_ddt_parse_line_pos = 1;
   gras_ddt_parse_char_pos = 0;
@@ -234,8 +205,8 @@ void  gras_ddt_parse_pointer_init(const char *file) {
 }
 
 void  gras_ddt_parse_pointer_close(void) {
-  yy_delete_buffer(input_buffer);
-  fclose(file_to_parse);
+  yy_delete_buffer(gras_ddt_input_buffer);
+  fclose(gras_ddt_file_to_parse);
 
   gras_ddt_parse_line_pos = 1;
   gras_ddt_parse_char_pos = 0;
@@ -244,8 +215,9 @@ void  gras_ddt_parse_pointer_close(void) {
 
 
 void  gras_ddt_parse_pointer_string_init(const char *string_to_parse) {
-  input_buffer = yy_scan_string (string_to_parse);
-  yy_switch_to_buffer(input_buffer);
+  gras_ddt_input_buffer = yy_scan_string (string_to_parse);
+  definition = string_to_parse;
+  yy_switch_to_buffer(gras_ddt_input_buffer);
 
   gras_ddt_parse_line_pos = 1;
   gras_ddt_parse_char_pos = 0;
@@ -253,13 +225,16 @@ void  gras_ddt_parse_pointer_string_init(const char *string_to_parse) {
 }
 
 void  gras_ddt_parse_pointer_string_close(void) {
-  yy_delete_buffer(input_buffer);
+  yy_delete_buffer(gras_ddt_input_buffer);
 
   gras_ddt_parse_line_pos = 1;
   gras_ddt_parse_char_pos = 0;
   gras_ddt_parse_tok_num = 0;
+
+  if (0)
+    yyunput('\0',NULL); /* fake a use of this function to calm gcc down */
 }
 
-// Local variables:
-// mode: c
-// End:
+/* Local variables:*/
+/* mode: c */
+/* End: */