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.

172 lines
4.3 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. #include "y2.h"
  3. #include <ctype.h>
  4. #include <string.h>
  5. extern int peekline; /* number of '\n' seen in lookahead */
  6. SSIZE_T
  7. gettok()
  8. {
  9. register i, base;
  10. register reserve;
  11. SSIZE_T match, c;
  12. begin:
  13. reserve = 0;
  14. lineno += peekline;
  15. peekline = 0;
  16. c = unix_getc(finput);
  17. while( c==' ' || c=='\n' || c=='\t' || c=='\f' || c=='\r')
  18. {
  19. if( c == '\n' ) ++lineno;
  20. c=unix_getc(finput);
  21. }
  22. if( c == '/' )
  23. {
  24. /* skip comment */
  25. lineno += skipcom();
  26. goto begin;
  27. }
  28. switch(c)
  29. {
  30. case -1: /* EOF */
  31. return(ENDFILE);
  32. case '{':
  33. yungetc( c, finput );
  34. return( '=' ); /* action ... */
  35. case '<': /* get, and look up, a type name (union member name) */
  36. i = 0;
  37. while( (c=unix_getc(finput)) != '>' && c>=0 && c!= '\n' )
  38. {
  39. tokname[i] = (char) c;
  40. if( ++i >= NAMESIZE ) --i;
  41. }
  42. if( c != '>' ) error( "unterminated < ... > clause" );
  43. tokname[i] = '\0';
  44. for( i=1; i<=ntypes; ++i )
  45. {
  46. if( !strcmp( typeset[i], tokname ) )
  47. {
  48. numbval = i;
  49. return( TYPENAME );
  50. }
  51. }
  52. typeset[numbval = ++ntypes] = cstash( tokname );
  53. return( TYPENAME );
  54. case '"':
  55. case '\'':
  56. match = c;
  57. tokname[0] = ' ';
  58. i = 1;
  59. for(;;)
  60. {
  61. c = unix_getc(finput);
  62. if( c == '\n' || c == EOF )
  63. error("illegal or missing ' or \"" );
  64. if( c == '\\' )
  65. {
  66. c = unix_getc(finput);
  67. tokname[i] = '\\';
  68. if( ++i >= NAMESIZE ) --i;
  69. }
  70. else if( c == match ) break;
  71. tokname[i] = (char) c;
  72. if( ++i >= NAMESIZE ) --i;
  73. }
  74. break;
  75. case '%':
  76. case '\\':
  77. switch(c=unix_getc(finput))
  78. {
  79. case '0':
  80. return(TERM);
  81. case '<':
  82. return(LEFT);
  83. case '2':
  84. return(BINARY);
  85. case '>':
  86. return(RIGHT);
  87. case '%':
  88. case '\\':
  89. return(MARK);
  90. case '=':
  91. return(PREC);
  92. case '{':
  93. return(LCURLY);
  94. default:
  95. reserve = 1;
  96. }
  97. default:
  98. if( isdigit((int) c) )
  99. {
  100. /* number */
  101. numbval = c-'0' ;
  102. base = (c=='0') ? 8 : 10 ;
  103. for( c=unix_getc(finput); isdigit((int) c) ; c=getc(finput) )
  104. {
  105. numbval = numbval*base + c - '0';
  106. }
  107. yungetc( c, finput );
  108. return(NUMBER);
  109. }
  110. else if( islower((int) c) || isupper((int) c) || c=='_' || c=='.' || c=='$' )
  111. {
  112. i = 0;
  113. while( islower((int) c) || isupper((int) c) || isdigit((int) c) || c=='_' || c=='.' || c=='$' )
  114. {
  115. tokname[i] = (char) c;
  116. if( reserve && isupper((int) c) ) tokname[i] += 'a'-'A';
  117. if( ++i >= NAMESIZE ) --i;
  118. c = unix_getc(finput);
  119. }
  120. }
  121. else return(c);
  122. yungetc( c, finput );
  123. }
  124. tokname[i] = '\0';
  125. if( reserve )
  126. {
  127. /* find a reserved word */
  128. if( !strcmp(tokname,"term")) return( TERM );
  129. if( !strcmp(tokname,"token")) return( TERM );
  130. if( !strcmp(tokname,"left")) return( LEFT );
  131. if( !strcmp(tokname,"nonassoc")) return( BINARY );
  132. if( !strcmp(tokname,"binary")) return( BINARY );
  133. if( !strcmp(tokname,"right")) return( RIGHT );
  134. if( !strcmp(tokname,"prec")) return( PREC );
  135. if( !strcmp(tokname,"start")) return( START );
  136. if( !strcmp(tokname,"type")) return( TYPEDEF );
  137. if( !strcmp(tokname,"union")) return( UNION );
  138. error("invalid escape, or illegal reserved word: %s", tokname );
  139. }
  140. /* look ahead to distinguish IDENTIFIER from C_IDENTIFIER */
  141. c = unix_getc(finput);
  142. while( c==' ' || c=='\t'|| c=='\n' || c=='\f' || c== '/' )
  143. {
  144. if( c == '\n' ) ++peekline;
  145. else if( c == '/' )
  146. {
  147. /* look for comments */
  148. peekline += skipcom();
  149. }
  150. c = unix_getc(finput);
  151. }
  152. if( c == ':' ) return( C_IDENTIFIER );
  153. yungetc( c, finput );
  154. return( IDENTIFIER );
  155. }