cppExpressionParser.cxx 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * PANDA 3D SOFTWARE
  3. * Copyright (c) Carnegie Mellon University. All rights reserved.
  4. *
  5. * All use of this software is subject to the terms of the revised BSD
  6. * license. You should have received a copy of this license along
  7. * with this source code in a file named "LICENSE."
  8. *
  9. * @file cppExpressionParser.cxx
  10. * @author drose
  11. * @date 1999-10-25
  12. */
  13. #include "cppExpressionParser.h"
  14. #include "cppBisonDefs.h"
  15. #include "cppDeclaration.h"
  16. #include "cppExpression.h"
  17. /**
  18. *
  19. */
  20. CPPExpressionParser::
  21. CPPExpressionParser(CPPScope *current_scope, CPPScope *global_scope) :
  22. _current_scope(current_scope),
  23. _global_scope(global_scope)
  24. {
  25. _expr = nullptr;
  26. }
  27. /**
  28. *
  29. */
  30. CPPExpressionParser::
  31. ~CPPExpressionParser() {
  32. }
  33. /**
  34. *
  35. */
  36. bool CPPExpressionParser::
  37. parse_expr(const std::string &expr) {
  38. if (!init_const_expr(expr)) {
  39. std::cerr << "Unable to parse expression\n";
  40. return false;
  41. }
  42. _expr = parse_const_expr(this, _current_scope, _global_scope);
  43. return get_error_count() == 0;
  44. }
  45. /**
  46. *
  47. */
  48. bool CPPExpressionParser::
  49. parse_expr(const std::string &expr, const CPPPreprocessor &filepos) {
  50. if (!init_const_expr(expr)) {
  51. std::cerr << "Unable to parse expression\n";
  52. return false;
  53. }
  54. copy_filepos(filepos);
  55. _expr = parse_const_expr(this, _current_scope, _global_scope);
  56. return get_error_count() == 0;
  57. }
  58. /**
  59. *
  60. */
  61. void CPPExpressionParser::
  62. output(std::ostream &out) const {
  63. if (_expr == nullptr) {
  64. out << "(null expr)";
  65. } else {
  66. out << *_expr;
  67. }
  68. }