GRAM.H 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* Data definitions for internal representation of bison's input,
  2. Copyright (C) 1984, 1986, 1989 Free Software Foundation, Inc.
  3. This file is part of Bison, the GNU Compiler Compiler.
  4. Bison is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 1, or (at your option)
  7. any later version.
  8. Bison is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with Bison; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. /* representation of the grammar rules:
  16. ntokens is the number of tokens, and nvars is the number of variables (nonterminals).
  17. nsyms is the total number, ntokens + nvars.
  18. Each symbol (either token or variable) receives a symbol number.
  19. Numbers 0 to ntokens-1 are for tokens, and ntokens to nsyms-1 are for variables.
  20. Symbol number zero is the end-of-input token. This token is counted in ntokens.
  21. The rules receive rule numbers 1 to nrules in the order they are written.
  22. Actions and guards are accessed via the rule number.
  23. The rules themselves are described by three arrays: rrhs, rlhs and ritems.
  24. rlhs[r] is the symbol number of the left hand side of rule r.
  25. The right hand side is stored as symbol numbers in a portion of ritems.
  26. rrhs[r] contains the index in ritems of the beginning of the portion for rule r.
  27. The length of the portion is one greater
  28. than the number of symbols in the rule's right hand side.
  29. The last element in the portion contains minus r, which
  30. identifies it as the end of a portion and says which rule it is for.
  31. The portions of ritems come in order of increasing rule number and are
  32. followed by an element which is zero to mark the end. nitems is the
  33. total length of ritems, not counting the final zero. Each element of
  34. ritems is called an "item" and its index in ritems is an item number.
  35. Item numbers are used in the finite state machine to represent
  36. places that parsing can get to.
  37. Precedence levels are recorded in the vectors sprec and rprec.
  38. sprec records the precedence level of each symbol,
  39. rprec the precedence level of each rule.
  40. rprecsym is the symbol-number of the symbol in %prec for this rule (if any).
  41. Precedence levels are assigned in increasing order starting with 1
  42. so that numerically higher precedence values mean tighter binding
  43. as they ought to. Zero as a symbol or rule's precedence means none is assigned.
  44. Associativities are recorded similarly in rassoc and sassoc. */
  45. #define ISTOKEN(s) ((s) < ntokens)
  46. #define ISVAR(s) ((s) >= ntokens)
  47. extern int nitems;
  48. extern int nrules;
  49. extern int nsyms;
  50. extern int ntokens;
  51. extern int nvars;
  52. extern short *ritem;
  53. extern short *rlhs;
  54. extern short *rrhs;
  55. extern short *rprec;
  56. extern short *rprecsym;
  57. extern short *sprec;
  58. extern short *rassoc;
  59. extern short *sassoc;
  60. extern short *rline; /* Source line number of each rule */
  61. extern int start_symbol;
  62. /* associativity values in elements of rassoc, sassoc. */
  63. #define RIGHT_ASSOC 1
  64. #define LEFT_ASSOC 2
  65. #define NON_ASSOC 3
  66. /* token translation table:
  67. indexed by a token number as returned by the user's yylex routine,
  68. it yields the internal token number used by the parser and throughout bison.
  69. If translations is zero, the translation table is not used because
  70. the two kinds of token numbers are the same. */
  71. extern short *token_translations;
  72. extern int translations;
  73. extern int max_user_token_number;
  74. /* semantic_parser is nonzero if the input file says to use the hairy parser
  75. that provides for semantic error recovery. If it is zero, the yacc-compatible
  76. simplified parser is used. */
  77. extern int semantic_parser;
  78. /* pure_parser is nonzero if should generate a parser that is all pure and reentrant. */
  79. extern int pure_parser;
  80. /* error_token_number is the token number of the error token. */
  81. extern int error_token_number;