PageRenderTime 171ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/other/netcdf_write_matrix/src/ncgen/ncgen.l

http://github.com/jbeezley/wrf-fire
LEX | 208 lines | 181 code | 15 blank | 12 comment | 0 complexity | a73294fcefa5f35f8fa2c210019ef331 MD5 | raw file
Possible License(s): AGPL-1.0
  1. %{
  2. /*********************************************************************
  3. * Copyright 1993, UCAR/Unidata
  4. * See netcdf/COPYRIGHT file for copying and redistribution conditions.
  5. * $Id: ncgen.l,v 1.16 2004/10/04 22:04:02 russ Exp $
  6. *********************************************************************/
  7. /* lex specification for tokens for ncgen */
  8. /* Fill value used by ncdump from version 2.4 and later. Should match
  9. definition of FILL_STRING in ../ncdump/vardata.h */
  10. #define FILL_STRING "_"
  11. #define XDR_INT_MIN (-2147483647-1)
  12. #define XDR_INT_MAX 2147483647
  13. char errstr[100]; /* for short error messages */
  14. #include <string.h>
  15. #include <ctype.h>
  16. #include "genlib.h"
  17. #include "ncgentab.h"
  18. #define YY_BREAK /* defining as nothing eliminates unreachable
  19. statement warnings from flex output,
  20. but make sure every action ends with
  21. "return" or "break"! */
  22. %}
  23. %p 6000
  24. escaped \\.
  25. nonquotes ([^"\\]|{escaped})*
  26. exp ([eE][+-]?[0-9]+)
  27. %%
  28. \/\/.* { /* comment */
  29. break;
  30. }
  31. \"{nonquotes}\" {
  32. if(yyleng > MAXTRST) {
  33. yyerror("string too long, truncated\n");
  34. yytext[MAXTRST-1] = '\0';
  35. }
  36. expand_escapes(termstring,(char *)yytext,yyleng);
  37. return (TERMSTRING);
  38. }
  39. float|FLOAT|real|REAL {return (FLOAT_K);}
  40. char|CHAR {return (CHAR_K);}
  41. byte|BYTE {return (BYTE_K);}
  42. short|SHORT {return (SHORT_K);}
  43. long|LONG|int|INT|integer|INTEGER {return (INT_K);}
  44. double|DOUBLE {return (DOUBLE_K);}
  45. unlimited|UNLIMITED {int_val = -1;
  46. return (NC_UNLIMITED_K);}
  47. dimensions:|DIMENSIONS: {return (DIMENSIONS);}
  48. variables:|VARIABLES: {return (VARIABLES);}
  49. data:|DATA: {return (DATA);}
  50. (netcdf|NETCDF|netCDF)[ \t]+[^\{]+ {
  51. char *s = (char*)yytext+strlen("netcdf");
  52. char *t = (char*)yytext+yyleng-1;
  53. while (isspace(*s))
  54. s++;
  55. while (isspace(*t))
  56. t--;
  57. t++;
  58. if (t-s+1 < 1) {
  59. yyerror("netCDF name required");
  60. return (DATA); /* generate syntax error */
  61. }
  62. netcdfname = (char *) emalloc(t-s+1);
  63. (void) strncpy(netcdfname, s, t-s);
  64. netcdfname[t-s] = '\0';
  65. return (NETCDF);
  66. }
  67. DoubleInf|NaN|-?Infinity { /* missing value (pre-2.4 backward compatibility) */
  68. if (yytext[0] == '-') {
  69. double_val = -NC_FILL_DOUBLE;
  70. } else {
  71. double_val = NC_FILL_DOUBLE;
  72. }
  73. return (DOUBLE_CONST);
  74. }
  75. FloatInf|-?Inff { /* missing value (pre-2.4 backward compatibility) */
  76. if (yytext[0] == '-') {
  77. float_val = -NC_FILL_FLOAT;
  78. } else {
  79. float_val = NC_FILL_FLOAT;
  80. }
  81. return (FLOAT_CONST);
  82. }
  83. [A-Za-z_][A-Z.@#\[\]a-z_0-9+-]* {
  84. if (STREQ((char *)yytext, FILL_STRING))
  85. return (FILLVALUE);
  86. if ((yylval = lookup((char *)yytext)) == NULL) {
  87. yylval = install((char *)yytext);
  88. }
  89. return (IDENT);
  90. }
  91. \n {
  92. lineno++ ;
  93. break;
  94. }
  95. [+-]?[0-9]*[0-9][Bb] {
  96. int ii;
  97. if (sscanf((char*)yytext, "%d", &ii) != 1) {
  98. sprintf(errstr,"bad byte constant: %s",(char*)yytext);
  99. yyerror(errstr);
  100. }
  101. byte_val = ii;
  102. if (ii != (int)byte_val) {
  103. sprintf(errstr,"byte constant out of range (-128,127): %s",(char*)yytext);
  104. yyerror(errstr);
  105. }
  106. return (BYTE_CONST);
  107. }
  108. [+-]?[0-9]*\.[0-9]*{exp}?[LlDd]?|[+-]?[0-9]*{exp}[LlDd]? {
  109. if (sscanf((char*)yytext, "%le", &double_val) != 1) {
  110. sprintf(errstr,"bad long or double constant: %s",(char*)yytext);
  111. yyerror(errstr);
  112. }
  113. return (DOUBLE_CONST);
  114. }
  115. [+-]?[0-9]*\.[0-9]*{exp}?[Ff]|[+-]?[0-9]*{exp}[Ff] {
  116. if (sscanf((char*)yytext, "%e", &float_val) != 1) {
  117. sprintf(errstr,"bad float constant: %s",(char*)yytext);
  118. yyerror(errstr);
  119. }
  120. return (FLOAT_CONST);
  121. }
  122. [+-]?[0-9]+[sS]|0[xX][0-9a-fA-F]+[sS] {
  123. if (sscanf((char*)yytext, "%hd", &short_val) != 1) {
  124. sprintf(errstr,"bad short constant: %s",(char*)yytext);
  125. yyerror(errstr);
  126. }
  127. return (SHORT_CONST);
  128. }
  129. [+-]?([1-9][0-9]*|0)[lL]? {
  130. char *ptr;
  131. errno = 0;
  132. double_val = strtod((char*)yytext, &ptr);
  133. if (errno != 0 && double_val == 0.0) {
  134. sprintf(errstr,"bad numerical constant: %s",(char*)yytext);
  135. yyerror(errstr);
  136. }
  137. if (double_val < XDR_INT_MIN ||double_val > XDR_INT_MAX) {
  138. return DOUBLE_CONST;
  139. } else {
  140. int_val = (int) double_val;
  141. return INT_CONST;
  142. }
  143. }
  144. 0[xX]?[0-9a-fA-F]+[lL]? {
  145. char *ptr;
  146. long long_val;
  147. errno = 0;
  148. long_val = strtol((char*)yytext, &ptr, 0);
  149. if (errno != 0) {
  150. sprintf(errstr,"bad long constant: %s",(char*)yytext);
  151. yyerror(errstr);
  152. }
  153. if (long_val < XDR_INT_MIN || long_val > XDR_INT_MAX) {
  154. double_val = (double) long_val;
  155. return DOUBLE_CONST;
  156. } else {
  157. int_val = (int) long_val;
  158. return INT_CONST;
  159. }
  160. }
  161. \'[^\\]\' {
  162. (void) sscanf((char*)&yytext[1],"%c",&byte_val);
  163. return (BYTE_CONST);
  164. }
  165. \'\\[0-7][0-7]?[0-7]?\' {
  166. byte_val = (char) strtol((char*)&yytext[2], (char **) 0, 8);
  167. return (BYTE_CONST);
  168. }
  169. \'\\[xX][0-9a-fA-F][0-9a-fA-F]?\' {
  170. byte_val = (char) strtol((char*)&yytext[3], (char **) 0, 16);
  171. return (BYTE_CONST);
  172. }
  173. \'\\.\' {
  174. switch ((char)yytext[2]) {
  175. case 'a': byte_val = '\007'; break; /* not everyone under-
  176. * stands '\a' yet */
  177. case 'b': byte_val = '\b'; break;
  178. case 'f': byte_val = '\f'; break;
  179. case 'n': byte_val = '\n'; break;
  180. case 'r': byte_val = '\r'; break;
  181. case 't': byte_val = '\t'; break;
  182. case 'v': byte_val = '\v'; break;
  183. case '\\': byte_val = '\\'; break;
  184. case '?': byte_val = '\177'; break;
  185. case '\'': byte_val = '\''; break;
  186. default: byte_val = (char)yytext[2];
  187. }
  188. return (BYTE_CONST);
  189. }
  190. [ \t\f]+ { /* whitespace */
  191. break;
  192. }
  193. . return (yytext[0]) ;