Skip to content
Snippets Groups Projects
Select Git revision
  • b364dd1d4cd06bfd79b5049bd4c36b972e63404f
  • 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

formula_parser.cpp

Blame
  • formula_parser.cpp 12.48 KiB
    // Copyright (C) 2005, Ondra Kamenik
    
    // $Id: formula_parser.cpp 2268 2008-11-22 10:38:03Z michel $
    
    #include "utils/cc/pascal_triangle.h"
    #include "utils/cc/exception.h"
    
    #include "parser_exception.h"
    #include "location.h"
    #include "formula_parser.h"
    #include "formula_tab.hh"
    
    #include <cmath>
    
    using namespace ogp;
    
    extern location_type fmla_lloc;
    
    FormulaParser::FormulaParser(const FormulaParser& fp, Atoms& a)
    	: otree(fp.otree), atoms(a), formulas(fp.formulas), ders()
    {
    	// create derivatives
    	for (unsigned int i = 0; i < fp.ders.size(); i++)
    		ders.push_back(new FormulaDerivatives(*(fp.ders[i])));
    }
    
    FormulaParser::~FormulaParser()
    {
    	destroy_derivatives();
    }
    
    void FormulaParser::differentiate(int max_order)
    {
    	destroy_derivatives();
    	vector<int> vars;
    	vars = atoms.variables();
    	for (unsigned int i = 0; i < formulas.size(); i++)
    		ders.push_back(new FormulaDerivatives(otree, vars, formulas[i], max_order));
    }
    
    const FormulaDerivatives& FormulaParser::derivatives(int i) const
    {
    	if (i < (int)ders.size())
    		return *(ders[i]);
    	else
    		throw ogu::Exception(__FILE__,__LINE__,
    							 "Wrong formula index in FormulaParser::derivatives");
    	return *(ders[0]); // just because of compiler
    }
    
    
    
    void FormulaParser::add_formula(int t)
    {
    	formulas.push_back(t);
    }
    
    int FormulaParser::add_binary(code_t code, int t1, int t2)
    {
    	return otree.add_binary(code, t1, t2);
    }
    
    int FormulaParser::add_unary(code_t code, int t)
    {
    	return otree.add_unary(code, t);
    }
    
    int FormulaParser::add_nulary(const char* str)
    {
    	int t = -1;