lex.l 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. %C
  2. %{
  3. /*
  4. * Copyright Nicholas B. Tufillaro, 1982-1994. All rights reserved.
  5. *
  6. * GNU enhancements Copyright (C) 1996, 1997, 1998, 1999, 2005, 2008, Free
  7. * Software Foundation, Inc.
  8. */
  9. #include "sys-defines.h"
  10. #include "ode.h"
  11. #include "extern.h"
  12. #include "gram.h"
  13. int curline = 1;
  14. %}
  15. Dig [0-9]
  16. Expo ([eE][-+]?{Dig}{Dig}?{Dig}?)
  17. %%
  18. \#.*$ ; /* N.B.: comments can't be continued */
  19. \\\n {
  20. curline++;
  21. }
  22. [ \t] ;
  23. [;\n] {
  24. yylval.lexptr = lalloc();
  25. yylval.lexptr->lx_lino = curline;
  26. if (*yytext == '\n')
  27. curline++;
  28. return SEP;
  29. }
  30. PI {
  31. yylval.lexptr = lalloc();
  32. yylval.lexptr->lx_u.lxu_value = M_PI;
  33. return NUMBER;
  34. }
  35. ^\.$ {
  36. /* lonely . isn't EOF in a -f file */
  37. if (yyin == stdin)
  38. return EOF;
  39. REJECT;
  40. }
  41. every { return EVERY; }
  42. from { return FROM; }
  43. print { return PRINT; }
  44. step { return STEP; }
  45. examine { return EXAM; }
  46. abs { return ABS; }
  47. sqrt { return SQRT; }
  48. exp { return EXP; }
  49. log10 { return LOG10; }
  50. ln { return LOG; }
  51. log { return LOG; }
  52. sin { return SIN; }
  53. cos { return COS; }
  54. tan { return TAN; }
  55. asinh { return ASINH; }
  56. acosh { return ACOSH; }
  57. atanh { return ATANH; }
  58. asin { return ASIN; }
  59. acos { return ACOS; }
  60. atan { return ATAN; }
  61. sinh { return SINH; }
  62. cosh { return COSH; }
  63. tanh { return TANH; }
  64. floor { return FLOOR; }
  65. ceil { return CEIL; }
  66. besj0 { return J0; }
  67. besj1 { return J1; }
  68. besy0 { return Y0; }
  69. besy1 { return Y1; }
  70. erfc { return ERFC; }
  71. erf { return ERF; }
  72. inverf { return INVERF; }
  73. lgamma { return LGAMMA; }
  74. gamma { return GAMMA; }
  75. norm { return NORM; }
  76. invnorm { return INVNORM; }
  77. ibeta { return IBETA; }
  78. igamma { return IGAMMA; }
  79. [_a-zA-Z][_a-zA-Z0-9]* {
  80. yylval.lexptr = lalloc();
  81. strncpy(yylval.lexptr->lx_u.lxu_name,yytext,NAMMAX);
  82. return IDENT;
  83. }
  84. {Dig}+{Expo}? |
  85. {Dig}+"."{Dig}*{Expo}? |
  86. {Dig}*"."{Dig}+{Expo}? {
  87. /*
  88. * restrictions on numbers:
  89. * radix 10 only
  90. * a bare Expo isn't enough (matches IDENT)
  91. */
  92. yylval.lexptr = lalloc();
  93. yylval.lexptr->lx_u.lxu_value = atof(yytext);
  94. return NUMBER;
  95. }
  96. [-+*/^()',=?~!] {
  97. /*
  98. * accept as few as possible so the error
  99. * message can be a smart one
  100. */
  101. return yytext[0];
  102. }
  103. . {
  104. if (*yytext > '~' || *yytext < ' ')
  105. fprintf (stderr,
  106. "%s:%s:%d: bad char '\\%02o'\n",
  107. progname, filename,
  108. curline, *yytext&0377);
  109. else
  110. fprintf (stderr,
  111. "%s:%s:%d: bad char '%c'\n",
  112. progname, filename,
  113. curline, *yytext);
  114. return *yytext;
  115. }
  116. %%
  117. /*
  118. * space management for the lexer
  119. */
  120. struct lex *
  121. lalloc (void)
  122. {
  123. struct lex *lp;
  124. lp = (struct lex *)xmalloc (sizeof(struct lex));
  125. lp->lx_u.lxu_value = 0.0;
  126. lp->lx_lino = 0;
  127. return lp;
  128. }
  129. void
  130. lfree (struct lex *lp)
  131. {
  132. if (lp != NULL)
  133. free ((void *)lp);
  134. }