Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

388 lines
9.8 KiB

  1. /* Copyright (C) Boris Nikolaus, Germany, 1996-1997. All rights reserved. */
  2. %{
  3. #include <stdarg.h>
  4. #include <stdlib.h>
  5. #include <string.h>
  6. #include <ctype.h>
  7. #include "defs.h"
  8. #include "parser.h"
  9. #include "error.h"
  10. #define T_NOTOKEN 9999
  11. static LLPOS current_pos;
  12. static LLPOS last_pos;
  13. #undef YY_INPUT
  14. #define YY_INPUT(buf,result,max_size) {\
  15. if (!filelen) { result = YY_NULL;\
  16. } else { while (currentfilepos >= allfilestarts[currentfile+1]) currentfile++;\
  17. buf[0] = *currentfilepos++; filelen--;\
  18. last_pos = current_pos;\
  19. if (buf[0] == '\n') { current_pos.line++; current_pos.column = 1; }\
  20. else { current_pos.column++; }\
  21. current_pos.file = allfilenames[currentfile];\
  22. result = 1;\
  23. }}
  24. LLSTYPE yylval;
  25. char *file = NULL;
  26. int filelen = 0;
  27. char *currentfilepos = NULL;
  28. char **allfilenames;
  29. char **allfilestarts;
  30. int currentfile;
  31. %}
  32. %x DIRECTIVE
  33. %%
  34. ABSENT return T_ABSENT;
  35. ABSTRACT-SYNTAX return T_ABSTRACT_SYNTAX;
  36. ALL return T_ALL;
  37. ANY return T_ANY;
  38. APPLICATION return T_APPLICATION;
  39. AUTOMATIC return T_AUTOMATIC;
  40. BEGIN return T_BEGIN;
  41. BIT return T_BIT;
  42. BMPString return T_BMPString;
  43. BOOLEAN return T_BOOLEAN;
  44. BY return T_BY;
  45. CHARACTER return T_CHARACTER;
  46. CHOICE return T_CHOICE;
  47. CLASS return T_CLASS;
  48. COMPONENT return T_COMPONENT;
  49. COMPONENTS return T_COMPONENTS;
  50. CONSTRAINED return T_CONSTRAINED;
  51. DEFAULT return T_DEFAULT;
  52. DEFINED return T_DEFINED;
  53. DEFINITIONS return T_DEFINITIONS;
  54. EMBEDDED return T_EMBEDDED;
  55. empty return T_empty;
  56. END return T_END;
  57. ENUMERATED return T_ENUMERATED;
  58. EXCEPT return T_EXCEPT;
  59. EXPLICIT return T_EXPLICIT;
  60. EXPORTS return T_EXPORTS;
  61. EXTENSIBILITY return T_EXTENSIBILITY;
  62. EXTERNAL return T_EXTERNAL;
  63. FALSE return T_FALSE;
  64. FROM return T_FROM;
  65. GeneralizedTime return T_GeneralizedTime;
  66. GeneralString return T_GeneralString;
  67. GraphicString return T_GraphicString;
  68. IA5String return T_IA5String;
  69. TYPE-IDENTIFIER return T_TYPE_IDENTIFIER;
  70. IDENTIFIER return T_IDENTIFIER;
  71. identifier return T_identifier;
  72. IMPLICIT return T_IMPLICIT;
  73. IMPLIED return T_IMPLIED;
  74. IMPORTS return T_IMPORTS;
  75. INCLUDES return T_INCLUDES;
  76. INSTANCE return T_INSTANCE;
  77. INTEGER return T_INTEGER;
  78. INTERSECTION return T_INTERSECTION;
  79. ISO646String return T_ISO646String;
  80. MACRO return T_MACRO;
  81. MAX return T_MAX;
  82. MIN return T_MIN;
  83. MINUS-INFINITY return T_MINUS_INFINITY;
  84. NOTATION return T_NOTATION;
  85. NULL return T_NULL;
  86. number return T_Number;
  87. NumericString return T_NumericString;
  88. OBJECT return T_OBJECT;
  89. ObjectDescriptor return T_ObjectDescriptor;
  90. OCTET return T_OCTET;
  91. OF return T_OF;
  92. OPTIONAL return T_OPTIONAL;
  93. PDV return T_PDV;
  94. PLUS-INFINITY return T_PLUS_INFINITY;
  95. PRESENT return T_PRESENT;
  96. PrintableString return T_PrintableString;
  97. PRIVATE return T_PRIVATE;
  98. REAL return T_REAL;
  99. SEQUENCE return T_SEQUENCE;
  100. SET return T_SET;
  101. SIZE return T_SIZE;
  102. STRING return T_STRING;
  103. string return T_string;
  104. SYNTAX return T_SYNTAX;
  105. T61String return T_T61String;
  106. TAGS return T_TAGS;
  107. TeletexString return T_TeletexString;
  108. TRUE return T_TRUE;
  109. TYPE return T_TYPE;
  110. type return T_type;
  111. UNION return T_UNION;
  112. UNIQUE return T_UNIQUE;
  113. UNIVERSAL return T_UNIVERSAL;
  114. UniversalString return T_UniversalString;
  115. UTCTime return T_UTCTime;
  116. UTF8String return T_UTF8String;
  117. VALUE return T_VALUE;
  118. value return T_value;
  119. VideotexString return T_VideotexString;
  120. VisibleString return T_VisibleString;
  121. WITH return T_WITH;
  122. "{"|"}"|","|"."|"("|")"|"["|"]"|"-"|":"|";"|"@"|"|"|"!"|"^"|"<"|">" return *yytext;
  123. "::=" return T_DEF;
  124. "..." return T_TDOT;
  125. ".." return T_DDOT;
  126. 0|[1-9][0-9]* { int i;
  127. intx_t h;
  128. intx_setuint32(&yylval._XNumber, 0);
  129. for (i = 0; i < yyleng; i++) {
  130. intx_muloctet(&h, &yylval._XNumber,
  131. 10);
  132. intx_addoctet(&yylval._XNumber, &h,
  133. (octet_t)(yytext[i] - '0'));
  134. }
  135. return T_number;
  136. }
  137. \'[01 \t\n\r\f\v]*\'B { char *p, *q;
  138. q = yylval._XString =
  139. (char *)malloc(yyleng - 2);
  140. for (p = yytext + 1; *p != '\''; p++)
  141. if (*p == '0' || *p == '1')
  142. *q++ = *p;
  143. *q = 0;
  144. return T_bstring;
  145. }
  146. \'[0-9A-F \t\n\r\f\v]*\'H { char *p, *q;
  147. q = yylval._XString =
  148. (char *)malloc(yyleng - 2);
  149. for (p = yytext + 1; *p != '\''; p++)
  150. if (isxdigit(*p))
  151. *q++ = *p;
  152. *q = 0;
  153. return T_hstring;
  154. }
  155. \" { int s, l = 0, c;
  156. LLPOS start_pos;
  157. yylval._XString32 =
  158. (char32_t *)malloc(
  159. (s = 32) * sizeof(char32_t));
  160. start_pos = last_pos;
  161. for (;;) {
  162. c = input();
  163. if (!c || c == EOF) {
  164. error(E_unterminated_string,
  165. &start_pos);
  166. /*NOTREACHED*/
  167. }
  168. if (c == '\n') {
  169. while (l > 0 && is32space(
  170. yylval._XString32[l - 1]))
  171. l--;
  172. while (c = input()) {
  173. if (!isspace(c))
  174. break;
  175. }
  176. }
  177. if (c == '\"') {
  178. c = input();
  179. if (c != '\"') {
  180. unput(c);
  181. yylval._XString32[l] = 0;
  182. return T_cstring;
  183. }
  184. }
  185. if (l + 1 >= s) {
  186. yylval._XString32 = (char32_t *)
  187. realloc(yylval._XString32,
  188. (s *= 2) *
  189. sizeof(char32_t));
  190. }
  191. yylval._XString32[l++] = c;
  192. }
  193. }
  194. [A-Z][A-Z-]*[A-Z]|[A-Z] {
  195. yylval._XString =
  196. (char *)malloc(yyleng + 1);
  197. strcpy(yylval._XString, yytext);
  198. return T_only_uppercase_symbol;
  199. }
  200. [A-Z][A-Z0-9-]*[A-Z0-9] {
  201. yylval._XString =
  202. (char *)malloc(yyleng + 1);
  203. strcpy(yylval._XString, yytext);
  204. return T_only_uppercase_digits_symbol;
  205. }
  206. [A-Z][A-Za-z0-9-]*[A-Za-z0-9] {
  207. yylval._XString =
  208. (char *)malloc(yyleng + 1);
  209. strcpy(yylval._XString, yytext);
  210. return T_uppercase_symbol;
  211. }
  212. [a-z][A-Za-z0-9-]*[A-Za-z0-9]|[a-z] {
  213. yylval._XString =
  214. (char *)malloc(yyleng + 1);
  215. strcpy(yylval._XString, yytext);
  216. return T_lcsymbol;
  217. }
  218. &[a-z][A-Za-z0-9-]*[A-Za-z0-9]|&[a-z] {
  219. yylval._XString =
  220. (char *)malloc(yyleng + 1);
  221. strcpy(yylval._XString, yytext);
  222. return T_amplcsymbol;
  223. }
  224. &[A-Z][A-Za-z0-9-]*[A-Za-z0-9]|&[A-Z] {
  225. yylval._XString =
  226. (char *)malloc(yyleng + 1);
  227. strcpy(yylval._XString, yytext);
  228. return T_ampucsymbol;
  229. }
  230. "--$" { BEGIN DIRECTIVE;
  231. }
  232. <DIRECTIVE>"--" { BEGIN INITIAL;
  233. }
  234. <DIRECTIVE>"\n" { BEGIN INITIAL;
  235. }
  236. <DIRECTIVE>fixed-array |
  237. <DIRECTIVE>fa { return T_FIXED_ARRAY;
  238. }
  239. <DIRECTIVE>singly-linked-list |
  240. <DIRECTIVE>sll { return T_SINGLY_LINKED_LIST;
  241. }
  242. <DIRECTIVE>doubly-linked-list |
  243. <DIRECTIVE>dll { return T_DOUBLY_LINKED_LIST;
  244. }
  245. <DIRECTIVE>length-pointer |
  246. <DIRECTIVE>lp { return T_LENGTH_POINTER;
  247. }
  248. <DIRECTIVE>zero-terminated |
  249. <DIRECTIVE>zt { return T_ZERO_TERMINATED;
  250. }
  251. <DIRECTIVE>pointer |
  252. <DIRECTIVE>p { return T_POINTER;
  253. }
  254. <DIRECTIVE>no-pointer |
  255. <DIRECTIVE>np { return T_NO_POINTER;
  256. }
  257. <DIRECTIVE>[, \t\r\f\v]+ { /* ignore */
  258. }
  259. <DIRECTIVE>[^-]+ { fprintf(stderr,
  260. "Bad directive %s (ignored)\n",
  261. yytext);
  262. }
  263. -- { int c;
  264. for (;;) {
  265. c = input();
  266. if (c == 0 || c == EOF)
  267. break;
  268. if (c == '\n')
  269. break;
  270. if (c != '-')
  271. continue;
  272. c = input();
  273. if (c == 0 || c == EOF)
  274. break;
  275. if (c == '\n')
  276. break;
  277. if (c != '-')
  278. continue;
  279. break;
  280. }
  281. return T_NOTOKEN;
  282. }
  283. [ \t\r\f\v\n]+ return T_NOTOKEN;
  284. \32 return EOF;
  285. . { error(E_bad_character, &last_pos);
  286. }
  287. %%
  288. int llgettoken(int *token, LLSTYPE *lval, LLPOS *pos)
  289. {
  290. for (;;) {
  291. if (yy_hold_char == YY_END_OF_BUFFER_CHAR) {
  292. *pos = current_pos;
  293. } else {
  294. *pos = last_pos;
  295. }
  296. *token = yylex();
  297. if (*token == 0 || *token == EOF)
  298. return 0;
  299. if (*token == T_NOTOKEN)
  300. continue;
  301. *lval = yylval;
  302. return 1;
  303. }
  304. }
  305. void readfiles(char **filenames)
  306. {
  307. FILE *fin;
  308. long len;
  309. int i, nfiles;
  310. for (nfiles = 0; filenames[nfiles]; nfiles++) {}
  311. allfilenames = filenames;
  312. allfilestarts = (char **)malloc((nfiles + 1) * sizeof(char *));
  313. filelen = 0;
  314. for (i = 0; i < nfiles; i++) {
  315. fin = fopen(filenames[i], "r");
  316. if (!fin) {
  317. perror(filenames[i]);
  318. exit(1);
  319. }
  320. fseek(fin, 0, SEEK_END);
  321. filelen += ftell(fin);
  322. fclose(fin);
  323. }
  324. currentfilepos = file = (char *)malloc(filelen);
  325. for (i = 0; i < nfiles; i++) {
  326. fin = fopen(filenames[i], "r");
  327. if (!fin) {
  328. perror(filenames[i]);
  329. exit(1);
  330. }
  331. fseek(fin, 0, SEEK_END);
  332. len = ftell(fin);
  333. fseek(fin, 0, SEEK_SET);
  334. allfilestarts[i] = currentfilepos;
  335. len = fread(currentfilepos, 1, len, fin);
  336. currentfilepos += len;
  337. fclose(fin);
  338. }
  339. filelen = currentfilepos - file;
  340. allfilestarts[i] = currentfilepos;
  341. currentfilepos = file;
  342. current_pos.line = 1;
  343. current_pos.column = 1;
  344. current_pos.file = filenames[0];
  345. last_pos = current_pos;
  346. }
  347. void
  348. llprinttoken(LLTERM *term, char *identifier, FILE *f)
  349. {
  350. char32_t *p;
  351. switch (term->token) {
  352. case T_number:
  353. fprintf(f, "%s(%u)", identifier, intx2uint32(&term->lval._XNumber));
  354. break;
  355. case T_bstring:
  356. case T_hstring:
  357. case T_only_uppercase_symbol:
  358. case T_only_uppercase_digits_symbol:
  359. case T_uppercase_symbol:
  360. case T_lcsymbol:
  361. case T_ampucsymbol:
  362. case T_amplcsymbol:
  363. fprintf(f, "%s(%s)", identifier, term->lval._XString);
  364. break;
  365. case T_cstring:
  366. fprintf(f, "%s(", identifier);
  367. for (p = term->lval._XString32; *p; p++)
  368. putc(*p, f);
  369. putc(')', f);
  370. break;
  371. default:
  372. fprintf(f, "%s", identifier);
  373. }
  374. }