Branch data Line data Source code
1 : : /****************************************************************************** 2 : : * This file is part of the cvc5 project. 3 : : * 4 : : * Copyright (c) 2009-2026 by the authors listed in the file AUTHORS 5 : : * in the top-level source directory and their institutional affiliations. 6 : : * All rights reserved. See the file COPYING in the top-level source 7 : : * directory for licensing information. 8 : : * **************************************************************************** 9 : : * 10 : : * Base class for parsing. 11 : : */ 12 : : 13 : : #include "cvc5parser_public.h" 14 : : 15 : : #ifndef CVC5__PARSER__PARSER_H 16 : : #define CVC5__PARSER__PARSER_H 17 : : 18 : : #include <cvc5/cvc5.h> 19 : : 20 : : #include <list> 21 : : #include <memory> 22 : : 23 : : #include "parser/input.h" 24 : : #include "parser/parser_state.h" 25 : : 26 : : namespace cvc5 { 27 : : namespace parser { 28 : : 29 : : class Cmd; 30 : : class SymManager; 31 : : class Lexer; 32 : : 33 : : /** 34 : : * A parser that uses the Lexer for lexing. It is used as a callback 35 : : * for error reporting. Its main methods are those that set up the input, 36 : : * nextCommand for parsing commands and nextExpression for parsing terms. 37 : : */ 38 : : class Parser : public ParserStateCallback 39 : : { 40 : : public: 41 : : Parser(Solver* solver, SymManager* sm); 42 : 25050 : virtual ~Parser() {} 43 : : /** 44 : : * Set the logic 45 : : * 46 : : * @param name The name of the logic. 47 : : */ 48 : : virtual void setLogic(const std::string& name); 49 : : /** Set the input for the given file. 50 : : * 51 : : * @param filename the input filename 52 : : */ 53 : : void setFileInput(const std::string& filename); 54 : : 55 : : /** Set the input for the given stream. 56 : : * 57 : : * @param input the input stream 58 : : * @param name the name of the stream, for use in error messages 59 : : */ 60 : : void setStreamInput(std::istream& input, const std::string& name); 61 : : 62 : : /** Set the input for the given string 63 : : * 64 : : * @param input the input string 65 : : * @param name the name of the stream, for use in error messages 66 : : */ 67 : : void setStringInput(const std::string& input, const std::string& name); 68 : : 69 : : /** 70 : : * Parse and return the next command. 71 : : */ 72 : : std::unique_ptr<Cmd> nextCommand(); 73 : : 74 : : /** Parse and return the next expression. */ 75 : : Term nextTerm(); 76 : : 77 : : /** Is this parser done reading input? */ 78 : : bool done() const; 79 : : 80 : : /** Issue a warning to the user. */ 81 : : void warning(const std::string& msg) override; 82 : : /** Raise a parse error with the given message. */ 83 : : void parseError(const std::string& msg) override; 84 : : /** Unexpectedly encountered an EOF */ 85 : : void unexpectedEOF(const std::string& msg) override; 86 : : 87 : : /** make flex parser from language string */ 88 : : static std::unique_ptr<Parser> mkParser(modes::InputLanguage lang, 89 : : Solver* solver, 90 : : SymManager* sm); 91 : : 92 : : protected: 93 : : /** Initialize input */ 94 : : void initializeInput(const std::string& name); 95 : : 96 : : /** Sets the done flag */ 97 : 709103 : void setDone(bool done = true) { d_done = done; } 98 : : /** 99 : : * Parse and return the next command. 100 : : * NOTE: currently memory management of commands is handled internally. 101 : : */ 102 : : virtual std::unique_ptr<Cmd> parseNextCommand() = 0; 103 : : 104 : : /** Parse and return the next expression. */ 105 : : virtual Term parseNextTerm() = 0; 106 : : /** Solver */ 107 : : Solver* d_solver; 108 : : /** Symbol manager */ 109 : : SymManager* d_sm; 110 : : /** The lexer we are using */ 111 : : Lexer* d_lex; 112 : : /** The flex input */ 113 : : std::unique_ptr<Input> d_flexInput; 114 : : /** Are we done */ 115 : : bool d_done; 116 : : }; 117 : : 118 : : } // namespace parser 119 : : } // namespace cvc5 120 : : 121 : : #endif /* CVC5__PARSER__SMT2_H */