cppBisonDefs.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // Filename: cppBison.h
  2. // Created by: drose (17Jan99)
  3. //
  4. ////////////////////////////////////////////////////////////////////
  5. #ifndef CPPBISON_H
  6. #define CPPBISON_H
  7. // This header file defines the interface to the yacc (actually,
  8. // bison) parser and grammar. None of these interfaces are intended
  9. // to be used directly; they're defined here strictly to be used by
  10. // the CPPParser and CPPExpressionParser classes.
  11. #include <dtoolbase.h>
  12. #include <string>
  13. #include "cppExtensionType.h"
  14. #include "cppFile.h"
  15. using namespace std;
  16. class CPPParser;
  17. class CPPExpression;
  18. class CPPPreprocessor;
  19. class CPPDeclaration;
  20. class CPPInstance;
  21. class CPPType;
  22. class CPPStructType;
  23. class CPPEnumType;
  24. class CPPSimpleType;
  25. class CPPInstanceIdentifier;
  26. class CPPParameterList;
  27. class CPPTemplateParameterList;
  28. class CPPScope;
  29. class CPPIdentifier;
  30. void parse_cpp(CPPParser *cp);
  31. CPPExpression *parse_const_expr(CPPPreprocessor *pp,
  32. CPPScope *new_current_scope,
  33. CPPScope *new_global_scope);
  34. CPPType *parse_type(CPPPreprocessor *pp,
  35. CPPScope *new_current_scope,
  36. CPPScope *new_global_scope);
  37. extern CPPScope *current_scope;
  38. extern CPPScope *global_scope;
  39. extern CPPPreprocessor *current_lexer;
  40. // This structure holds the return value for each token.
  41. // Traditionally, this is a union, and is declared with the %union
  42. // declaration in the parser.y file, but unions are pretty worthless
  43. // in C++ (you can't include an object that has member functions in a
  44. // union), so we'll use a class instead. That means we need to
  45. // declare it externally, here.
  46. class YYSTYPE {
  47. public:
  48. string str;
  49. union {
  50. int integer;
  51. double real;
  52. CPPScope *scope;
  53. CPPDeclaration *decl;
  54. CPPInstance *instance;
  55. CPPType *type;
  56. CPPStructType *struct_type;
  57. CPPEnumType *enum_type;
  58. CPPSimpleType *simple_type;
  59. CPPInstanceIdentifier *inst_ident;
  60. CPPParameterList *param_list;
  61. CPPTemplateParameterList *template_param_list;
  62. CPPExtensionType::Type extension_enum;
  63. CPPExpression *expr;
  64. CPPIdentifier *identifier;
  65. } u;
  66. };
  67. // This structure takes advantage of a bison feature to track the
  68. // exact location in the file of each token, for more useful error
  69. // reporting. We define it up here so we can reference it in the
  70. // lexer.
  71. struct cppyyltype {
  72. int timestamp;
  73. int first_line;
  74. int first_column;
  75. int last_line;
  76. int last_column;
  77. char *text;
  78. CPPFile file;
  79. };
  80. #define YYLTYPE cppyyltype
  81. #endif