Skip to content
Snippets Groups Projects
Select Git revision
  • 347be1f89a82542c66c2ac7aa9611e93cb942ec1
  • master default protected
  • 6.x protected
  • madysson
  • 5.x protected
  • asm
  • time-varying-information-set
  • 4.6 protected
  • dynare_minreal
  • dragonfly
  • various_fixes
  • 4.5 protected
  • clang+openmp
  • exo_steady_state
  • declare_vars_in_model_block
  • julia
  • error_msg_undeclared_model_vars
  • static_aux_vars
  • slice
  • aux_func
  • penalty
  • 6.4 protected
  • 6.3 protected
  • 6.2 protected
  • 6.1 protected
  • 6.0 protected
  • 6-beta2 protected
  • 6-beta1 protected
  • 5.5 protected
  • 5.4 protected
  • 5.3 protected
  • 5.2 protected
  • 5.1 protected
  • 5.0 protected
  • 5.0-rc1 protected
  • 4.7-beta3 protected
  • 4.7-beta2 protected
  • 4.7-beta1 protected
  • 4.6.4 protected
  • 4.6.3 protected
  • 4.6.2 protected
41 results

check_dsge_var_model.m

Blame
  • Driver.hh 3.33 KiB
    /*
     * Copyright © 2019-2023 Dynare Team
     *
     * This file is part of Dynare.
     *
     * Dynare is free software: you can redistribute it and/or modify
     * it under the terms of the GNU General Public License as published by
     * the Free Software Foundation, either version 3 of the License, or
     * (at your option) any later version.
     *
     * Dynare is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
     */
    
    #ifndef MACRO_DRIVER_HH
    #define MACRO_DRIVER_HH
    
    #ifdef PARSING_DRIVER_HH
    # error Impossible to include both ../ParsingDriver.hh and Driver.hh
    #endif
    
    #include "Environment.hh"
    #include "Expressions.hh"
    #include "Parser.hh"
    
    #include <stack>
    
    // Declare TokenizerFlexLexer class
    #ifndef __FLEX_LEXER_H
    # define yyFlexLexer TokenizerFlexLexer
    # include <FlexLexer.h>
    # undef yyFlexLexer
    #endif
    
    namespace macro
    {
    /* The lexer class
     * It was necessary to subclass the TokenizerFlexLexer class generated by Flex,
     * since the prototype for TokenizerFlexLexer::yylex() was not convenient.
     */
    class TokenizerFlex : public TokenizerFlexLexer
    {
    public:
      TokenizerFlex(istream* in) : TokenizerFlexLexer {in}
      {
      }
      TokenizerFlex(const TokenizerFlex&) = delete;
      TokenizerFlex& operator=(const TokenizerFlex&) = delete;
    
      //! The main lexing function
      Tokenizer::parser::token_type lex(Tokenizer::parser::semantic_type* yylval,
                                        Tokenizer::parser::location_type* yylloc,
                                        macro::Driver& driver);
      static void location_increment(Tokenizer::parser::location_type* yylloc, const char* yytext);
    };
    
    //! Implements the macro expansion using a Flex scanner and a Bison parser
    class Driver
    {
    private:
      vector<DirectivePtr> statements;
      stack<vector<DirectivePtr>> directive_stack;
    
    public:
      Driver() = default;
      Driver(const Driver&) = delete;
      Driver& operator=(const Driver&) = delete;
    
      //! Exception thrown when value of an unknown variable is requested
      struct UnknownVariable
      {
        const string name;
      };
    
      //! Starts parsing a file, modifies `env`, `paths` and `output`
      //! as they are modified by various macro directives
      void parse(const string& file, const istream& modfile, bool debug,
                 const vector<pair<string, string>>& defines, Environment& env,
                 vector<filesystem::path>& paths, ostream& output);
    
      //! Name of main file being parsed (for error reporting purposes)
      string file;
    
      //! Reference to the lexer
      unique_ptr<TokenizerFlex> lexer;
    
      //! Error handler
      void error(const Tokenizer::parser::location_type& location, const string& message) const;
    
      [[nodiscard]] bool
      inContext() const
      {
        return !directive_stack.empty();
      }
    
      void
      pushContext()
      {
        directive_stack.emplace();
      }
    
      void
      pushContextTop(DirectivePtr statement)
      {
        directive_stack.top().emplace_back(move(statement));
      }
    
      void
      pushStatements(DirectivePtr statement)
      {
        statements.emplace_back(move(statement));
      }
    
      vector<DirectivePtr>
      popContext()
      {
        auto top = move(directive_stack.top());
        directive_stack.pop();
        return top;
      }
    };
    }
    #endif