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.

136 lines
2.8 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. %{
  3. /***
  4. *** lexer for preprocessing the parser driver generated by yacc, in
  5. *** order to convert the big switch statement into individual semantic
  6. *** functions
  7. ***/
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include <malloc.h>
  12. #include "lex.h"
  13. #include "gram.h"
  14. #define VC_PRINTF( x ) /** printf(x) **/
  15. void LexInstall_ID( void );
  16. void LexInstall_Number( void );
  17. int IsToken( void );
  18. lextype_t yylval;
  19. int Line = 0;
  20. int Incase = 0;
  21. int ActionSensed = 0;
  22. char LocalBuffer[ 100 ];
  23. %}
  24. letter [a-z_A-Z]
  25. digit [0-9]
  26. letter_or_digit [a-zA-Z_0-9]
  27. whitespace [ \t]
  28. other .
  29. %%
  30. {letter}{letter_or_digit}* {
  31. int Token;
  32. VC_PRINTF(" Case 1\n");
  33. if( Token = IsToken() )
  34. {
  35. return Token;
  36. }
  37. else
  38. LexInstall_ID();
  39. return ID;
  40. }
  41. "} break;\n" {
  42. VC_PRINTF(" Case 2\n");
  43. Line++;
  44. return TOKEN_END_CASE;
  45. }
  46. "} break;"{whitespace}*"\/\*"{whitespace}*"End of actions"{whitespace}*"\*\/\n" {
  47. VC_PRINTF(" Case 3\n");
  48. Line++;
  49. return TOKEN_END_CASE;
  50. }
  51. {digit}{digit}* {
  52. VC_PRINTF(" Case 4\n");
  53. LexInstall_Number();
  54. return NUMBER;
  55. }
  56. "\n" {
  57. VC_PRINTF(" Case 5\n");
  58. Line++;
  59. yylval.yycharval = '\n';
  60. return TOKEN_CHAR;
  61. }
  62. {other} {
  63. VC_PRINTF(" Case 6\n");
  64. yylval.yycharval = yytext[0];
  65. return TOKEN_CHAR;
  66. }
  67. %%
  68. /****************************************************************************
  69. * utility routines
  70. ****************************************************************************/
  71. /**************************************************************************
  72. *** install parser value stack
  73. **************************************************************************/
  74. void
  75. LexInstall_ID()
  76. {
  77. strncpy( LocalBuffer, yytext, yyleng );
  78. LocalBuffer[ yyleng ] = '\0';
  79. yylval.yystring = LocalBuffer;
  80. }
  81. void
  82. LexInstall_Number()
  83. {
  84. yylval.yynumber = atoi(yytext);
  85. }
  86. /**************************************************************************
  87. *** token search
  88. **************************************************************************/
  89. int
  90. IsToken()
  91. {
  92. static char *pTokens[] =
  93. {
  94. "case"
  95. ,"___a_r_u_myact"
  96. ,"___a_r_u_start"
  97. ,"___a_r_u_end"
  98. };
  99. static int Tokens[] =
  100. {
  101. TOKEN_CASE
  102. ,TOKEN_MYACT
  103. ,TOKEN_START
  104. ,TOKEN_END
  105. };
  106. int i = 0;
  107. int Token;
  108. while( i < sizeof(pTokens) / sizeof(char *) )
  109. {
  110. if(strcmp( pTokens[i] , yytext ) == 0 )
  111. {
  112. Token = Tokens[i];
  113. if(Token == TOKEN_CASE)
  114. {
  115. if(!ActionSensed || Incase)
  116. return 0;
  117. }
  118. return Token;
  119. }
  120. ++i;
  121. }
  122. return 0;
  123. }