home *** CD-ROM | disk | FTP | other *** search
/ Serving the Web / ServingTheWeb1995.disc1of1.iso / linux / slacksrce / d / libc / libc-4.6 / libc-4 / libc-linux / locale / numeric / lexer.l < prev    next >
Encoding:
Lex Description  |  1994-03-13  |  1.8 KB  |  116 lines

  1. %{
  2.  
  3. #include <string.h>
  4.  
  5. #include "mknumeric.h"
  6. #include "y.tab.h"
  7.  
  8. void
  9. yyerror(char *);
  10.  
  11. int lineno = 1;
  12.  
  13. %}
  14.  
  15. white    [ \t]
  16.  
  17. %x    String
  18.  
  19. %%
  20.  
  21.     unsigned char string_buf[512];
  22.     unsigned char *string_buf_ptr;
  23.  
  24. ^#[^\n]*\n            lineno++;
  25.  
  26. \n                lineno++;
  27.  
  28. \\\n                lineno++;
  29.  
  30. ^{white}*codeset{white}+    return CODESET;
  31.  
  32. ^{white}*decimal_point{white}+    return DECIMAL_POINT;
  33.  
  34. ^{white}*thousands_sep{white}+    return THOUSANDS_SEP;
  35.  
  36. ^{white}*grouping{white}+    return GROUPING;
  37.  
  38. [a-zA-Z][a-zA-Z0-9_-]*[a-zA-Z0-9]    {
  39.                     yylval.str = strdup(yytext);
  40.                     return CODENAME;
  41.                 }
  42.  
  43. \"                {
  44.                     BEGIN(String);
  45.                     string_buf_ptr = string_buf;
  46.                 }
  47.  
  48. <String>\"            {
  49.                     /* saw closing quote - all done */
  50.  
  51.                     BEGIN(INITIAL);
  52.                     *string_buf_ptr = '\0';
  53.                     yylval.str = strdup(string_buf);
  54.                     return STRING;
  55.                 }
  56.  
  57. <String>\n            {
  58.                     yyerror("Unterminated string");
  59.                     exit(1);
  60.                 }
  61.  
  62. <String>\\[0-7]{1,3}        {
  63.                     int result;
  64.  
  65.                     (void)sscanf(yytext + 1, "%o", &result);
  66.  
  67.                     if (result > 0xff) {
  68.                         yyerror("Invalid octal code");
  69.                         exit(1);
  70.                     }
  71.  
  72.                     *string_buf_ptr++ = result;
  73.                 }
  74.  
  75. <String>\\[0-9]+        {
  76.                     yyerror("Invalid backslash escape");
  77.                     exit(1);
  78.                 }
  79.  
  80. <String>\\[Xx][0-9a-fA-F][0-9a-fA-F]        {
  81.                     int result;
  82.  
  83.                     (void)sscanf(yytext + 2, "%x", &result);
  84.                     *string_buf_ptr++ = result;
  85.                 }
  86.  
  87. <String>\\[Xx]..        {
  88.                     yyerror("Invalid backslash escape");
  89.                     exit(1);
  90.                 }
  91.  
  92. <String>\\n            *string_buf_ptr++ = '\n';
  93. <String>\\t            *string_buf_ptr++ = '\t';
  94. <String>\\r            *string_buf_ptr++ = '\r';
  95. <String>\\b            *string_buf_ptr++ = '\b';
  96. <String>\\f            *string_buf_ptr++ = '\f';
  97.  
  98. <String>\\(.|\n)        *string_buf_ptr++ = yytext[1];
  99.  
  100. <String>[^\\\n\"]+        {
  101.                     unsigned char *text_ptr = yytext;
  102.  
  103.                     while(*text_ptr)
  104.                         *string_buf_ptr++ = *text_ptr++;
  105.                 }
  106.  
  107. .
  108.  
  109. %%
  110.  
  111. void
  112. yyerror(char *txt)
  113. {
  114.   (void) fprintf(stderr, "Line %d: %s\n", lineno, txt);
  115. }
  116.