defToken.ll 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. %option noyywrap
  2. %a 30000
  3. %e 10000
  4. %k 10000
  5. %n 10000
  6. %o 40000
  7. %p 20000
  8. %{
  9. /* $XConsortium: defToken.l /main/5 1996/11/19 16:54:10 drk $ */
  10. #include <string.h>
  11. #include "FeatureDefDictionary.h"
  12. #include "defParser.tab.h"
  13. #include "Debug.h"
  14. #include <iostream>
  15. using namespace std;
  16. extern istream *g_defParserin;
  17. #define YY_INPUT(buf,result,max_size)\
  18. {\
  19. if (g_defParserin -> eof()) {\
  20. result=0;\
  21. } else {\
  22. g_defParserin -> read((char *)buf, max_size-1); \
  23. result = g_defParserin -> gcount(); \
  24. buf[result] = 0; \
  25. }\
  26. }
  27. unsigned char* defToken_string_buf = new unsigned char[1024];
  28. int defToken_string_buf_size = 1024;
  29. int defToken_string_buf_content_size = 0;
  30. unsigned char* new_copy(const unsigned char* str, int size)
  31. {
  32. unsigned char* x = new unsigned char[ ( size <= 0 ) ? 1 : size + 1];
  33. memcpy(x, str, size);
  34. x[size] = 0;
  35. return x;
  36. }
  37. void addToDefTokenStringBuf(const char* str, int size)
  38. {
  39. if ( size <= 0 ) return;
  40. if ( defToken_string_buf_size - defToken_string_buf_content_size < size ) {
  41. defToken_string_buf_size = 2*(size+defToken_string_buf_content_size);
  42. unsigned char* x = new unsigned char[defToken_string_buf_size];
  43. memcpy(x, defToken_string_buf, defToken_string_buf_content_size);
  44. delete [] defToken_string_buf;
  45. defToken_string_buf = x;
  46. }
  47. memcpy(defToken_string_buf + defToken_string_buf_content_size, str, size);
  48. defToken_string_buf_content_size += size;
  49. defToken_string_buf[defToken_string_buf_content_size] = 0;
  50. }
  51. %}
  52. stringprefix ([Ss][Tt][Rr][Ii][Nn][Gg][_][Pp][Rr][Ee][Ff][Ii][Xx])
  53. string ([Ss][Tt][Rr][Ii][Nn][Gg])
  54. integer ([Ii][Nn][Tt][Ee][Gg][Ee][Rr])
  55. array([Aa][Rr][Rr][Aa][Yy])
  56. real ([Rr][Ee][Aa][Ll])
  57. unit ([Dd][Ii][Mm][Ee][Nn][Ss][Ii][Oo][Nn])
  58. unitpixel ([Dd][Ii][Mm][Ee][Nn][Ss][Ii][Oo][Nn][_][Pp][Ii][Xx][Ee][Ll])
  59. boolean ([Bb][Oo][Oo][Ll][Ee][Aa][Nn])
  60. %x quoted_string
  61. %%
  62. ^"#".* {
  63. }
  64. "," {
  65. return(COMMA);
  66. }
  67. "*" {
  68. return(STAR);
  69. }
  70. ";" {
  71. return(SEMI_COLON);
  72. }
  73. ":" {
  74. return(COLON);
  75. }
  76. "{" {
  77. return(FSOPEN);
  78. }
  79. "}" {
  80. return(FSCLOSE);
  81. }
  82. "(" {
  83. return(OPER_parenopen);
  84. }
  85. ")" {
  86. return(OPER_parenclose);
  87. }
  88. {stringprefix} {
  89. defParserlval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
  90. return(TYPE);
  91. }
  92. {string} {
  93. defParserlval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
  94. return(TYPE);
  95. }
  96. {integer} {
  97. defParserlval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
  98. return(TYPE);
  99. }
  100. {real} {
  101. defParserlval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
  102. return(TYPE);
  103. }
  104. {unit} {
  105. defParserlval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
  106. return(TYPE);
  107. }
  108. {unitpixel} {
  109. defParserlval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
  110. return(TYPE);
  111. }
  112. {array} {
  113. defParserlval.charPtrData = new_copy((unsigned char*)yytext, yyleng);
  114. return(TYPE);
  115. }
  116. {boolean} {
  117. defParserlval.charPtrData =
  118. new_copy((unsigned char*)"INTEGER", strlen("INTEGER"));
  119. return(TYPE);
  120. }
  121. [0-9]+ {
  122. defParserlval.intData = atoi((char*)yytext);
  123. return(INTEGER);
  124. }
  125. [0-9]+"."[0-9]+ {
  126. defParserlval.realData = atof((char*)yytext);
  127. return(REAL);
  128. }
  129. \" {
  130. BEGIN quoted_string;
  131. }
  132. <quoted_string>\" {
  133. defParserlval.charPtrData =
  134. new unsigned char[defToken_string_buf_content_size+1];
  135. memcpy( defParserlval.charPtrData,
  136. defToken_string_buf,
  137. defToken_string_buf_content_size+1
  138. );
  139. defToken_string_buf_content_size = 0;
  140. BEGIN 0;
  141. return(QUOTED_STRING);
  142. }
  143. <quoted_string>. {
  144. addToDefTokenStringBuf(yytext, yyleng);
  145. }
  146. "&"[^ \t\n\";.=@+*\/\.\*:?\^,{}\[\]()]+ {
  147. defParserlval.charPtrData =
  148. (unsigned char*)strdup((const char*)(yytext+1));
  149. return(REF_NAME);
  150. }
  151. [^ \t\n\";.=@+*\/\.\*:?\^,{}\[\]()]+ {
  152. defParserlval.charPtrData =
  153. (unsigned char*)strdup((const char*)yytext);
  154. return(NORMAL_STRING);
  155. }
  156. [\t] {
  157. }
  158. [\n] {
  159. yylineno++;
  160. }
  161. . {
  162. }
  163. %%
  164. void defParsererror(char* msg)
  165. {
  166. cerr << "line " << yylineno << ": " << msg;
  167. }