⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 由matlab开发的hybrid系统的描述语言
💻 C
字号:
/*	HYSDEL	Copyright (C) 1999-2002  Fabio D. Torrisi	This file is part of HYSDEL.    	HYSDEL 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 2 of the License, or (at your option) any later version.	HYSDEL 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 this library; if not, write to the Free Software	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA	CONTACT INFORMATION	===================	Fabio D. Torrisi	ETH Zentrum	Physikstrasse. 3 ETL,	CH-8032 Zurich	Switzerland	mailto:torrisi@aut.ee.ethz.ch (preferred)*/#include <stdio.h>#include <fstream.h>#include <time.h>#include <signal.h>#include <string>#include "Pure_lexer.h"#include "lexer_input.h"#include "parser_input.h"#include "Problem.h"#include "Problem_handler.h"#include "cmdline.h"#include "Globals.h"#include "Cmd_options.h"#include "Symbol_table.h"int yyparse(void *);void process_system(string *sys_name, Implementation *impl, t_parser_input *p_in){  Symbol_table *symbol_table = p_in->globals->symbol_table;  Cmd_options *cmd_options = p_in->globals->cmd_options;  ostream *out;	         MLD_representation *mld;  string param_checks, symb_checks;;  p_in->globals->system_name=*sys_name;  symbol_table->semantic_checks();  symb_checks=impl->checks();	  impl->prepare_translate_MLD();  symbol_table->find_computable_order();  if (cmd_options->gen_param_checks()) {    param_checks = symbol_table->matlab_symb_param_exist_check();    param_checks+=symb_checks;  }  // MLD output  if (cmd_options->do_MLD()) {	           out=(p_in->MLD_out);    if ( cmd_options->use_matlab_symbolic() )      *out << symbol_table->symbs_as_matalb_symbolic();    *out << param_checks;    if ( cmd_options->all_params_symbolic() ) {      p_in->globals->all_params_symbolic=true;      *out << symbol_table->initialize_nonsymb_params_matlab();    }    mld=impl->translate_MLD();    *out << mld->to_matlab() << endl;    delete mld;    if (cmd_options->print_symtable()) {      *out << symbol_table->to_matlab("S.");    }    p_in->globals->all_params_symbolic=false;			  }  // simulator output  if (cmd_options->do_simulator()) {    out = (p_in->simu_out);    if (!symbol_table->matlab_simulateable()) {      string msg;      msg+=string("cannot generate simulator because not all variables are defined");      p_in->globals->problem_handler->process(new Problem(ERROR, msg));    }    *out << symbol_table->matlab_simu_header(cmd_options->simulator_name());    if (cmd_options->use_matlab_symbolic() )      *out << symbol_table->symbs_as_matalb_symbolic();				    *out << param_checks;    if ( cmd_options->all_params_symbolic() ) {      p_in->globals->all_params_symbolic=true;      *out << symbol_table->initialize_nonsymb_params_matlab();    }				    if ( cmd_options->use_matlab_symbolic() )      *out << symbol_table->symbs_as_matalb_symbolic();    *out << symbol_table->matlab_simu();    p_in->globals->all_params_symbolic=false;			  }							}string license_note(bool comment) {  string res, txt;  char buf[200];		if (comment) txt=string("% ");			sprintf(buf,"%d",COMPILATION_DATE);	 	res= txt + string("HYSDEL ") + string(HYSDEL_VERSION) + 	string(" (Build: ") + string(buf) + string(")\n")	+ txt + string("Copyright (C) 1999-2002  Fabio D. Torrisi\n")	  + txt + string("\n")	  + txt + string("HYSDEL comes with ABSOLUTELY NO WARRANTY;\n")	  + txt + string("HYSDEL is free software; you can redistribute it and/or\n")	  + txt + string("modify it under the terms of the GNU General Public\n")	  + txt + string("License as published by the Free Software Foundation; either\n")	  + txt + string("version 2 of the License, or (at your option) any later version.\n")	  ;	return res;}int expired(void) {	struct tm * today;	long int serial, mon, year;	time_t now;	now = time(0);	today = gmtime(& now);	mon=today->tm_mon - EXPIRATION_TIME;	year=today->tm_year + 1900;	while (mon<0) { mon+=12; year--; }	serial = 10000 * (year + 1900) + 100 *		(mon + 1) + (today->tm_mday);	return (serial <= (long int) COMPILATION_DATE);}/**	Handle a big failure: segmentation fault or abort signal by simply * printing out the email address to complain with */void failure_handler(int sig) {	string error;	if (sig == SIGSEGV) error = "Segmentation fault";	else if (sig == SIGABRT)error = "Abort signal"; else error = "Unknown";	cerr << endl << "HYSDEL " << HYSDEL_VERSION << endl;	cerr << "The program crashed due to some internal error ("		<< error << ")\n";	cerr << "Please report the error message to torrisi@aut.ee.ethz.ch \n";	cerr << "together with the hysdel source that produced the error \n";	exit(1);}/** **************************************************************************** * Main function of hysdel                                                    * */int main(int argc, char * argv[]) {	istream * input_stream;	struct parser_input * p_in;	struct lexer_input * l_in;	struct gengetopt_args_info args_info;	Pure_lexer * lexer;	Globals * glob;	string fn;	cmdline_parser(argc, argv, & args_info);	/* Check if the current release is expired */	if (expired()) {		cerr << license_note(false);			cerr << "This version is expired,";		cerr << "please check http://control.ethz.ch/~hybrid/hysdel for an updated version";	}	// register the internal error handlers	signal(SIGABRT, & failure_handler);	signal(SIGSEGV, & failure_handler);	if (args_info.input_given) {		input_stream = new ifstream(args_info.input_arg);		if (!((ifstream *) input_stream)->is_open()) {			cerr << "Cannot open file: '" <<				args_info.input_arg << "'" << endl;			return 1;		}	} else input_stream = & cin;	lexer = new Pure_lexer(input_stream);	glob = new Globals();	glob->symbol_table = new Symbol_table(glob);	glob->cmd_options = new Cmd_options(& args_info, glob);	glob->problem_handler = new Problem_handler(cerr, glob);	l_in = new t_lexer_input;	l_in->lexer = lexer;	l_in->globals = glob;	p_in = new t_parser_input;	p_in->globals = glob;	p_in->l_in = l_in;	if (args_info.MLDoutput_given) {		fn = string(args_info.MLDoutput_arg) + string(".m");
		char* p = new char[fn.length() +1];
		fn.copy(p,fn.length() +1);
		p[fn.length()] = 0;		p_in->MLD_out = new ofstream(p);		if (!((ofstream *) p_in->MLD_out)->is_open()) {			cerr << "Cannot open file: '" <<				fn << "'" << endl;			return 1;		}		*(p_in->MLD_out) << license_note(true); 	}	if (args_info.SIMoutput_given) {		fn = string(args_info.SIMoutput_arg) + string(".m");		char* p = new char[fn.length() +1];
		fn.copy(p,fn.length() +1);
		p[fn.length()] = 0;		p_in->simu_out = new ofstream(p);		if (!(*((ofstream *) p_in->simu_out))) {			cerr << "Cannot open file: '" <<				fn << "'" << endl;			return 1;		}	}	if (!args_info.MLDoutput_given && !args_info.SIMoutput_given ) {		p_in->MLD_out = & cout;		*(p_in->MLD_out) << license_note(true);	} else {		cout << license_note(false);		cout << endl;	}		yyparse(p_in);	if (args_info.MLDoutput_given) ((ofstream *) p_in->MLD_out)->close();	if (args_info.SIMoutput_given) ((ofstream *) p_in->simu_out)->close();	if (args_info.input_given) ((ifstream *) input_stream)->close();	delete glob;	delete p_in;	delete l_in;	delete lexer;	return 0;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -