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.

81 lines
2.0 KiB

  1. // Copyright (c) 1993-1999 Microsoft Corporation
  2. #include "y2.h"
  3. int
  4. defin( int t, register char *s )
  5. {
  6. /* define s to be a terminal if t=0
  7. or a nonterminal if t=1 */
  8. register val;
  9. if (t)
  10. {
  11. if( ++nnonter >= NNONTERM ) error("too many nonterminals, limit %d",NNONTERM);
  12. nontrst[nnonter].name = cstash(s);
  13. return( NTBASE + nnonter );
  14. }
  15. /* must be a token */
  16. if( ++ntokens >= NTERMS ) error("too many terminals, limit %d",NTERMS );
  17. tokset[ntokens].name = cstash(s);
  18. /* establish value for token */
  19. if( s[0]==' ' && s[2]=='\0' ) /* single character literal */
  20. val = s[1];
  21. else if ( s[0]==' ' && s[1]=='\\' )
  22. {
  23. /* escape sequence */
  24. if( s[3] == '\0' )
  25. {
  26. /* single character escape sequence */
  27. switch ( s[2] )
  28. {
  29. /* character which is escaped */
  30. case 'n':
  31. val = '\n';
  32. break;
  33. case 'r':
  34. val = '\r';
  35. break;
  36. case 'b':
  37. val = '\b';
  38. break;
  39. case 't':
  40. val = '\t';
  41. break;
  42. case 'f':
  43. val = '\f';
  44. break;
  45. case '\'':
  46. val = '\'';
  47. break;
  48. case '"':
  49. val = '"';
  50. break;
  51. case '\\':
  52. val = '\\';
  53. break;
  54. default:
  55. error( "invalid escape" );
  56. }
  57. }
  58. else if( s[2] <= '7' && s[2]>='0' )
  59. {
  60. /* \nnn sequence */
  61. if( s[3]<'0' || s[3] > '7' || s[4]<'0' ||
  62. s[4]>'7' || s[5] != '\0' ) error("illegal \\nnn construction" );
  63. val = 64*s[2] + 8*s[3] + s[4] - 73*'0';
  64. if( val == 0 ) error( "'\\000' is illegal" );
  65. }
  66. }
  67. else
  68. {
  69. val = extval++;
  70. }
  71. tokset[ntokens].value = val;
  72. toklev[ntokens] = 0;
  73. return( ntokens );
  74. }