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.

347 lines
13 KiB

  1. // GRAMMAR.H -- Contains grammar of NMAKE ************************************
  2. //
  3. // Copyright (c) 1988-1989, Microsoft Corporation. All rights reserved.
  4. //
  5. // Purpose:
  6. // Module contains grammar of NMAKE and definitions used by lexer & parser
  7. //
  8. // Revision History:
  9. // 08-Oct-1989 SB Added QUOTE_ and NOQ and QUO to handle OS/2 1.2 quoted names
  10. // 31-Jul-1989 SB Added BKS, DEF and BEG to add lookahead to the lexer
  11. // 18-May-1989 SB Added BKSLH_ definition for use by lexer's nameStates[]
  12. // This file contains the grammar for nmake.
  13. //
  14. //
  15. //
  16. // e is the symbol epsilon
  17. //
  18. //
  19. // nonterminals begin w/ capitals
  20. //
  21. //
  22. // terminals begin w/ lower-case letters
  23. //
  24. //
  25. // terminals: name newline newlineWhitespace semicolon colon equals string e
  26. // doublecolon value
  27. //
  28. //
  29. // Makefile -> e |
  30. // BlankLines Makefile |
  31. // newline name Body Makefile
  32. //
  33. // Body -> NameList Separator BuildInfo |
  34. // equals value
  35. //
  36. // NameList -> e |
  37. // name NameList
  38. //
  39. // Commands -> e |
  40. // MoreBuildLines |
  41. // semicolon string MoreBuildLines
  42. //
  43. // MoreBuildLines -> e |
  44. // newlineWhitespace string MoreBuildLines |
  45. // newline MoreBuildLines
  46. //
  47. // BlankLines -> e |
  48. // newline BlankLines |
  49. // newlineWhitespace BlankLines
  50. //
  51. // BuildInfo -> e |
  52. // NameList Commands
  53. //
  54. // Separator -> colon | doublecolon
  55. //
  56. //
  57. //
  58. //
  59. //
  60. // note: a "string" is everything from the current input character up
  61. // to the first newline which is not preceded by a backslash, or
  62. // end of file (whichever comes first). a macro "value" is the
  63. // same as a "string" with the exception that comments are stripped
  64. // from it (a comment ending in a backslash does not cause the
  65. // value to be continued on the next line).
  66. // Compute FIRST() and FOLLOW() for each nonterminal in order to construct
  67. // parse table (it'd be nice to have a simple utility to build the
  68. // table, but it's still a pretty easy thing to do by hand).
  69. //
  70. //
  71. // FIRST(Makefile) = e newline FIRST(BlankLines)
  72. // = e newline newlineWhitespace
  73. //
  74. // FIRST(Body) = equals FIRST(NameList) FIRST(Separator)
  75. // = equals name colon doublecolon
  76. //
  77. // FIRST(NameList) = e name
  78. //
  79. // FIRST(Commands) = e semicolon FIRST(BuildLine)
  80. // = e semicolon newlineWhitespace
  81. //
  82. // FIRST(MoreBuildLines) = e FIRST(BuildLine) FIRST(BlankLines)
  83. // = e newlineWhitespace newline
  84. //
  85. // FIRST(BlankLines) = e newline newlineWhitespace
  86. //
  87. // FIRST(BuildInfo) = FIRST(NameList) FIRST(Commands)
  88. // = e name semicolon newlineWhitespace
  89. //
  90. // FIRST(Separator) = colon doublecolon
  91. // ---------------------------------------------------------------
  92. //
  93. //
  94. // FOLLOW(Makefile) = $
  95. //
  96. // FOLLOW(Body) = FIRST(Makefile) FOLLOW(Makefile)
  97. // = newline newlineWhitespace $
  98. //
  99. // FOLLOW(NameList) = FIRST(Commands) FIRST(MoreBuildLines)
  100. // colon FOLLOW(Body)
  101. // = colon semicolon newlineWhitespace
  102. // newline $
  103. //
  104. // FOLLOW(Commands) = FOLLOW(Body)
  105. // = newline newlineWhitespace $
  106. //
  107. // FOLLOW(MoreBuildLines) = FOLLOW(Commands)
  108. // = newline newlineWhitespace $
  109. //
  110. // FOLLOW(BlankLines) = FIRST(Body) FOLLOW(Makefile)
  111. // = newlineWhitespace newline $
  112. //
  113. // FOLLOW(BuildInfo) = FOLLOW(Body)
  114. // = newline newlineWhitespace $
  115. //
  116. // FOLLOW(Separator) = FIRST(BuildInfo) FOLLOW(Body)
  117. // = name semicolon newlineWhitespace
  118. // newline $
  119. //
  120. //------------------------------------------------------------------------------
  121. //
  122. // for building the table, I number the productions:
  123. //
  124. //
  125. //
  126. // 0. Makefile -> e
  127. //
  128. // 1. Makefile -> BlankLines Makefile
  129. //
  130. // 2. MakeFile -> newline name Body Makefile
  131. //
  132. // 3. Body -> NameList Separator BuildInfo
  133. //
  134. // 4. Body -> equals value
  135. //
  136. // 5. NameList -> e
  137. //
  138. // 6. NameList -> name NameList
  139. //
  140. // 7. Commands -> e
  141. //
  142. // 8. Commands -> MoreBuildLines
  143. //
  144. // 9. Commands -> semicolon string MoreBuildLines
  145. //
  146. // 10. MoreBuildLines -> newlineWhiteSpace string MoreBuildLines
  147. //
  148. // 11. MoreBuildLines -> e
  149. //
  150. // 12. MoreBuildLines -> newline MoreBuildLines
  151. //
  152. // 13. BlankLines -> e
  153. //
  154. // 14. BlankLines -> newline BlankLines
  155. //
  156. // 15. BlankLines -> newlineWhitespace BlankLines
  157. //
  158. // 16. BuildInfo -> e
  159. //
  160. // 17. BuildInfo -> NameList Commands
  161. //
  162. // 18. Separator -> colon
  163. //
  164. // 19. Separator -> doublecolon
  165. //
  166. //------------------------------------------------------------------------------
  167. //
  168. // NOTE THAT THIS GRAMMAR IS NOT LL(1) (it's really LL(2) because we need
  169. // an extra symbol of lookahead to decide which production to use in
  170. // a few cases)
  171. //
  172. //
  173. // the resulting parse table (empty entries are error conditions):
  174. //
  175. //
  176. // newline-
  177. // White- semi- double-
  178. // |name |newline| space | colon | colon | colon |equals |$ |
  179. // -----------------------------------------------------------------
  180. // A | | | | | | | | |
  181. // Makefile | | 1,2 | 1 | | | | | 0 |
  182. // | | | | | | | | |
  183. // -----------------------------------------------------------------
  184. // B | | | | | | | | |
  185. // Blank- | | 13,14 | 13[15]| | | | | 13 |
  186. // Lines | | | -- | | | | | |
  187. // -----------------------------------------------------------------
  188. // C | | | | | | | | |
  189. // More- | | 11,12 | 10 | | | | | 11 |
  190. // Build- | | | | | | | | |
  191. // Lines -----------------------------------------------------------------
  192. // D | | | | | | | | |
  193. // Commands | | 7 | [7]8 | 9 | | | | 7 |
  194. // | | | - | | | | | |
  195. // -----------------------------------------------------------------
  196. // E | | | | | | | | |
  197. // Body | 3 | | | | 3 | | 4 | |
  198. // | | | | | | | | |
  199. // -----------------------------------------------------------------
  200. // F | | | | | | | | |
  201. // NameList | 6 | 5 | 5 | 5 | 5 | 5 | | 5 |
  202. // | | | | | | | | |
  203. // -----------------------------------------------------------------
  204. // G | | | | | | | | |
  205. // Build- | 17 | 16 |[16]17 | 17 | | | | 16 |
  206. // Info | | | -- | | | | | |
  207. // -----------------------------------------------------------------
  208. // H | | | | | | | | |
  209. // Separ- | | | | | 18 | 19 | | |
  210. // ator | | | | | | | | |
  211. // -----------------------------------------------------------------
  212. //
  213. // G2 -- always uses 17 -- anytime the user puts a line beginning w/
  214. // whitespace immediately after a target-dependency line, it's
  215. // a build line. Same for D2.
  216. // IMPORTANT: IF YOU CHANGE THE VALUES OF ANY OF THE FOLLOWING
  217. // CONSTANTS FOR TERMINAL OR NONTERMINAL SYMBOLS, YOU MUST ADJUST
  218. // THE APPROPRIATE TABLES (AND STRING LITERALS) ACCORDINGLY.
  219. //
  220. // Nonterminal symbols first (these are used to index the parse table
  221. // along the first dimension):
  222. //
  223. // define nonterminals . . .
  224. #define MAKEFILE 0x00 // productions w/ 2
  225. #define BLANKLINES 0x01 // alternatives in a
  226. #define MOREBUILDLINES 0x02 // table entry must
  227. #define COMMANDS 0x03 // come first (so
  228. #define BODY 0x04 // that I can use
  229. #define NAMELIST 0x05 // them as array
  230. #define BUILDINFO 0x06 // subscripts when
  231. #define SEPARATOR 0x07 // resolving the
  232. // conflict)
  233. #define START MAKEFILE
  234. #define LAST_PRODUCTION SEPARATOR
  235. // Now the terminal symbols (the 4 low bits of which are used to index
  236. // the parse table alone 2nd dimension -- bit 5 simply distinguishes
  237. // tokens from nonterminals in productions):
  238. #define NAME 0x10 // TOKEN_MASK | 0
  239. #define NEWLINE 0x11 // TOKEN_MASK | 1
  240. #define NEWLINESPACE 0x12 // TOKEN_MASK | 2
  241. #define SEMICOLON 0x13 // TOKEN_MASK | 3
  242. #define COLON 0x14 // TOKEN_MASK | 4
  243. #define DOUBLECOLON 0x15 // etc.
  244. #define EQUALS 0x16
  245. #define ACCEPT 0x17 // this is $
  246. #define STRING 0x18 // no columns in table
  247. #define VALUE 0x19 // for these two
  248. // Error values -- these are equal to the error exit code minus 1000
  249. // if you change them, you must change the corresponding values in
  250. // nmmsg.txt
  251. #define MACRO 0x20 // ERROR_MASK | 0
  252. #define SYNTAX 0x21 // ERROR_MASK | 1
  253. #define SEPRTR 0x22 // ERROR_MASK | 2
  254. #define SEPEQU 0x23 // ERROR_MASK | 3
  255. #define NAMES 0x24 // ERROR_MASK | 4
  256. #define NOTARG 0x25 // ERROR_MASK | 5
  257. #define LEXER 0x26 // ERROR_MASK | 6
  258. #define PARSER 0x27 // ERROR_MASK | 7
  259. // Parser actions -- these are indexes into the "action" function table,
  260. // telling the parser which function to call at a certain point in
  261. // a production
  262. #define DONAME 0x40 // ACTION_MASK | 0
  263. #define DONAMELIST 0x41
  264. #define DOMACRO 0x42
  265. #define DODEPENDS 0x43
  266. #define DOLASTNAME 0x44
  267. #define DOBUILDCMDS 0x45
  268. // a few macros to simplify dealing w/ tokens:
  269. #define TOKEN_MASK 0x10
  270. #define ERROR_MASK 0x20
  271. #define ACTION_MASK 0x40
  272. #define AMBIG_MASK 0x80 // conflict in table
  273. #define LOW_NIBBLE 0x0F
  274. // values for alternate productions table
  275. // (a YES in the slot for a given input token and a given nonterminal
  276. // on top of the stack means use the next production (+1) from the
  277. // one given in the production table)
  278. #define YES 1
  279. #define NO 0
  280. // values for lexer's state machine that recognizes names
  281. // append an underscore to distinguish these from parser's tokens
  282. #define DEFAULT_ 0x00 // char not defined
  283. #define COMMENT_ 0x01 // below
  284. #define EQUALS_ 0x02
  285. #define SEMICOLON_ 0x03
  286. #define COLON_ 0x04
  287. #define WHITESPACE_ 0x05 // \t and ' '
  288. #define NEWLINE_ 0x06 // \n and EOF
  289. #define DOLLAR_ 0x07
  290. #define OPENPAREN_ 0x08
  291. #define CLOSEPAREN_ 0x09
  292. #define MACROCHAR_ 0x0A // A-Z,a-z,0-9,_
  293. #define OPENCURLY_ 0x0B
  294. #define CLOSECURLY_ 0x0C
  295. #define BKSLSH_ 0x0D
  296. #define QUOTE_ 0x0E
  297. #define STAR_ 0x0B // only for strings:
  298. #define SPECIAL1_ 0x0C // @ * < ?
  299. #define SPECIAL2_ 0x0D // B F D R
  300. #define BACKSLASH_ 0x03 // don't need semi if
  301. // we have backslash
  302. // (names need ; but
  303. // strings need \)
  304. // values for state tables -- for error values, mask off the error bit (0x20)
  305. // to get the message number.
  306. #define OK 0x40 // means accept token
  307. #define BEG 0x00 // means beginning
  308. #define DEF 0x01 // means normal name
  309. #define BKS 0x0f // processing bkslash
  310. #define PAR 0x20 // close paren missing
  311. #define CHR 0x21 // bad char in macro
  312. #define BAD 0x22 // single $ w/o macro
  313. #define EQU 0x23 // substitution w/o =
  314. #define NAM 0x24 // illegal macro name
  315. #define SEQ 0x25 // subst w/o strings
  316. #define NOQ 0x26 // no matching quote
  317. #define QUO 0x27 // illegal " in name