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

📄 ifs_yacc.y

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 Y
📖 第 1 页 / 共 2 页
字号:
%{ /* $Id: ifs_yacc.y,v 1.5 2004/07/09 18:37:55 pnenzi Exp $ *//*============================================================================FILE  ifs_yacc.yMEMBER OF process cmppCopyright 1991Georgia Tech Research CorporationAtlanta, Georgia 30332All Rights ReservedPROJECT A-8503AUTHORS    9/12/91  Steve TynorMODIFICATIONS    12/31/91  Bill Kuhn  Fix bug in usage of strcmp in check_default_type()SUMMARY    This file contains the BNF specification of the language used in    the ifspec.ifs file together with various support functions,    and parses the ifspec.ifs file to get the information from it    and place this information into a data structure    of type Ifs_Table_t.INTERFACES    yyparse()     -    Generated automatically by UNIX 'yacc' utility.REFERENCED FILES    ifs_lex.lNON-STANDARD FEATURES    None.============================================================================*/#include <assert.h>#include <stdlib.h>#include <string.h>#include "ifs_yacc_y.h"#define	yymaxdepth ifs_yymaxdepth#define	yyparse	ifs_yyparse#define	yylex	ifs_yylex#define	yyerror	ifs_yyerror#define	yylval	ifs_yylval#define	yychar	ifs_yychar#define	yydebug	ifs_yydebug#define	yypact	ifs_yypact#define	yyr1	ifs_yyr1#define	yyr2	ifs_yyr2#define	yydef	ifs_yydef#define	yychk	ifs_yychk#define	yypgo	ifs_yypgo#define	yyact	ifs_yyact#define	yyexca	ifs_yyexca#define yyerrflag ifs_yyerrflag#define yynerrs	ifs_yynerrs#define	yyps	ifs_yyps#define	yypv	ifs_yypv#define	yys	ifs_yys#define	yy_yys	ifs_yyyys#define	yystate	ifs_yystate#define	yytmp	ifs_yytmp#define	yyv	ifs_yyv#define	yy_yyv	ifs_yyyyv#define	yyval	ifs_yyval#define	yylloc	ifs_yylloc#define yyreds	ifs_yyreds#define yytoks	ifs_yytoks#define yylhs	ifs_yyyylhs#define yylen	ifs_yyyylen#define yydefred ifs_yyyydefred#define yydgoto	ifs_yyyydgoto#define yysindex ifs_yyyysindex#define yyrindex ifs_yyyyrindex#define yygindex ifs_yyyygindex#define yytable	 ifs_yyyytable#define yycheck	 ifs_yyyycheck#define yyname   ifs_yyyyname#define yyrule   ifs_yyyyruleextern int yylineno;extern int yyival;extern double yydval;extern char *ifs_yytext;extern void yyerror (char*); extern int ifs_yylex();Boolean_t parser_just_names;static Boolean_t saw_model_name;static Boolean_t saw_function_name;static char *dtype_to_str[] = {   "BOOLEAN", "INTEGER", "REAL", "COMPLEX", "STRING", "POINTER"   };static Boolean_t did_default_type;static Boolean_t did_allowed_types;static int num_items;static int item;static int item_offset;static Boolean_t num_items_fixed;Ifs_Table_t *parser_ifs_table;#define TBL parser_ifs_tablestatic int alloced_size [4];/* * !!!!! Make sure these are large enough so that they never get realloced * !!!!! since that will cause garbage uninitialized data... * !!!!! (FIX THIS!) */#define DEFAULT_SIZE_CONN	100#define DEFAULT_SIZE_PARAM	100#define DEFAULT_SIZE_INST_VAR	100#define GROW_SIZE		10typedef enum {   TBL_NAME,   TBL_PORT,   TBL_PARAMETER,   TBL_STATIC_VAR,} Table_t;typedef struct {   Table_t table;   int record;} Context_t;Context_t context;#define ITEM_BUFFER_SIZE 20	/* number of items that can be put in a table				 * before requiring a new xxx_TABLE: keyword				 */#define FOR_ITEM(i) for (i = item_offset; i < num_items; i++)#define ITEM_BUF(i) item_buffer[i-item_offset]#define ASSIGN_BOUNDS(struct_name, i) \  if (ITEM_BUF(i).range.is_named) {\    TBL->struct_name[i].has_conn_ref = TRUE;\    TBL->struct_name[i].conn_ref = find_conn_ref (ITEM_BUF(i).range.u.name);\  } else {\    TBL->struct_name[i].has_conn_ref = FALSE;\    TBL->struct_name[i].has_lower_bound =\       ITEM_BUF(i).range.u.bounds.lower.has_bound;\    TBL->struct_name[i].has_upper_bound =\       ITEM_BUF(i).range.u.bounds.upper.has_bound;\    if (TBL->struct_name[i].has_lower_bound) {\      assert (ITEM_BUF(i).range.u.bounds.lower.bound.kind == INTEGER);\       TBL->struct_name[i].lower_bound =\	ITEM_BUF(i).range.u.bounds.lower.bound.u.ivalue;\    }\    if (TBL->struct_name[i].has_upper_bound) {\       assert (ITEM_BUF(i).range.u.bounds.upper.bound.kind == INTEGER);\       TBL->struct_name[i].upper_bound =\	  ITEM_BUF(i).range.u.bounds.upper.bound.u.ivalue;\    }\  }/*---------------------------------------------------------------------------*/static void fatal (char *str){   yyerror (str);   exit(1);}/*---------------------------------------------------------------------------*/static int find_conn_ref (name)     char *name;{   int i;   char str[130];      for (i = 0; i < TBL->num_conn; i++) {      if (strcmp (name, TBL->conn[i].name) == 0) {	 return i;      }   }   sprintf (str, "Port `%s' not found", name);   yyerror (str);   return 0;}typedef enum {C_DOUBLE, C_BOOLEAN, C_POINTER, C_UNDEF} Ctype_Class_t;/*---------------------------------------------------------------------------*/static Ctype_Class_t get_ctype_class (Port_Type_t type){   switch (type) {   case USER_DEFINED:      return C_POINTER;      break;   case DIGITAL:      return C_BOOLEAN;      break;   default:      return C_DOUBLE;      break;   }}/*---------------------------------------------------------------------------*/static void check_port_type_direction (Dir_t dir, Port_Type_t port_type){   switch (port_type) {   case VOLTAGE:   case DIFF_VOLTAGE:   case CURRENT:   case DIFF_CURRENT:   case DIGITAL:   case USER_DEFINED:      /*       * anything goes       */      break;   case VSOURCE_CURRENT:      if (dir != IN) {	 yyerror ("Port type `vnam' is only valid for `in' ports");      }      break;   case CONDUCTANCE:   case DIFF_CONDUCTANCE:   case RESISTANCE:   case DIFF_RESISTANCE:      if (dir != INOUT) {	 yyerror ("Port types `g', `gd', `h', `hd' are only valid for `inout' ports");      }      break;   default:      assert (0);   }}/*---------------------------------------------------------------------------*/static void check_dtype_not_pointer (Data_Type_t dtype){   if (dtype == POINTER) {      yyerror("Invalid parameter type - POINTER type valid only for STATIC_VARs");   }}/*---------------------------------------------------------------------------*/static void check_default_type (Conn_Info_t conn){   int i;      for (i = 0; i < conn.num_allowed_types; i++) {      if (conn.default_port_type == conn.allowed_port_type[i]) {	 if ((conn.default_port_type != USER_DEFINED) ||	     (strcmp (conn.default_type, conn.allowed_type[i]) == 0)) {	    return;	 }      }   }   yyerror ("Port default type is not an allowed type");}/*---------------------------------------------------------------------------*/static void assign_ctype_list (conn, ctype_list)     Conn_Info_t  *conn;     Ctype_List_t *ctype_list;{   int i;   Ctype_List_t *p;   Ctype_Class_t class = C_UNDEF;      conn->num_allowed_types = 0;   for (p = ctype_list; p; p = p->next) {      conn->num_allowed_types++;   }   conn->allowed_type = (char**) calloc (conn->num_allowed_types,					 sizeof (char*));   conn->allowed_port_type = (Port_Type_t*) calloc (conn->num_allowed_types,						    sizeof (Port_Type_t));   if (! (conn->allowed_type && conn->allowed_port_type)) {      fatal ("Could not allocate memory");   }   for (i = conn->num_allowed_types-1, p = ctype_list; p; i--, p = p->next) {      if (class == C_UNDEF) {	 class = get_ctype_class (p->ctype.kind);      }      if (class != get_ctype_class (p->ctype.kind)) {	 yyerror ("Incompatible port types in `allowed_types' clause");      }      check_port_type_direction (conn->direction, p->ctype.kind);            conn->allowed_port_type[i] = p->ctype.kind;      conn->allowed_type[i] = p->ctype.id;   } }/*---------------------------------------------------------------------------*/static void assign_value (type, dest_value, src_value)   Data_Type_t	type;   Value_t	*dest_value;   My_Value_t	src_value;{   char str[200];   if ((type == REAL) && (src_value.kind == INTEGER)) {      dest_value->rvalue = src_value.u.ivalue;      return;   } else if (type != src_value.kind) {      sprintf (str, "Invalid parameter type (saw %s - expected %s)",	       dtype_to_str[src_value.kind],	       dtype_to_str[type] );      yyerror (str);   }    switch (type) {   case BOOLEAN:      dest_value->bvalue = src_value.u.bvalue;      break;   case INTEGER:      dest_value->ivalue = src_value.u.ivalue;      break;   case REAL:      dest_value->rvalue = src_value.u.rvalue;      break;   case COMPLEX:      dest_value->cvalue = src_value.u.cvalue;      break;   case STRING:      dest_value->svalue = src_value.u.svalue;      break;   default:      yyerror ("INTERNAL ERROR - unexpected data type in `assign_value'");   }}   /*---------------------------------------------------------------------------*/static void assign_limits (type, param, range)     Data_Type_t	type;     Param_Info_t	*param;     Range_t		range;{   if (range.is_named) {      yyerror ("Named range not allowed for limits");   }   param->has_lower_limit = range.u.bounds.lower.has_bound;   if (param->has_lower_limit) {      assign_value (type, &param->lower_limit, range.u.bounds.lower.bound);   }   param->has_upper_limit = range.u.bounds.upper.has_bound;   if (param->has_upper_limit) {      assign_value (type, &param->upper_limit, range.u.bounds.upper.bound);   }}/*---------------------------------------------------------------------------*/static void check_item_num (){   if (item-item_offset >= ITEM_BUFFER_SIZE) {      fatal ("Too many items in table - split into sub-tables");   }   if (item > alloced_size [context.table] ) {      switch (context.table) {      case TBL_NAME:	 break;      case TBL_PORT:	 alloced_size[context.table] += GROW_SIZE;	 TBL->conn = (Conn_Info_t*)	    realloc (TBL->conn,		     alloced_size [context.table] * sizeof (Conn_Info_t));	 if (! TBL->conn) {	    fatal ("Error allocating memory for port definition");	 }	 break;      case TBL_PARAMETER:	 alloced_size [context.table] += GROW_SIZE;	 TBL->param = (Param_Info_t*)	    realloc (TBL->param,		     alloced_size [context.table] * sizeof (Param_Info_t));	 if (! TBL->param) {	    fatal ("Error allocating memory for parameter definition");	 }	 break;      case TBL_STATIC_VAR:	 alloced_size [context.table] += GROW_SIZE;	 TBL->inst_var = (Inst_Var_Info_t*)	    realloc (TBL->inst_var,		     alloced_size [context.table] * sizeof (Inst_Var_Info_t));	 if (! TBL->inst_var) {	    fatal ("Error allocating memory for static variable definition");	 }	 break;      }   }   item++;}/*---------------------------------------------------------------------------*/static void check_end_item_num (){   if (num_items_fixed) {      if (item != num_items) {	 char buf[200];	 sprintf	    (buf,	     "Wrong number of elements in sub-table (saw %d - expected %d)",	     item - item_offset,	     num_items - item_offset);	 fatal (buf);      }   } else {      num_items = item;      num_items_fixed = TRUE;      switch (context.table) {      case TBL_NAME:	 break;      case TBL_PORT:	 TBL->num_conn = num_items;	 break;      case TBL_PARAMETER:	 TBL->num_param = num_items;	 break;      case TBL_STATIC_VAR:	 TBL->num_inst_var = num_items;	 break;      }   }   item = item_offset;}#define INIT(n) item = (n); item_offset = (n); num_items = (n); num_items_fixed = FALSE#define ITEM check_item_num()#define END  check_end_item_num()   %}%token TOK_ALLOWED_TYPES%token TOK_ARRAY%token TOK_ARRAY_BOUNDS%token TOK_BOOL_NO%token TOK_BOOL_YES%token TOK_COMMA%token TOK_PORT_NAME%token TOK_PORT_TABLE%token TOK_CTYPE_D%token TOK_CTYPE_G%token TOK_CTYPE_GD%token TOK_CTYPE_H%token TOK_CTYPE_HD%token TOK_CTYPE_I%token TOK_CTYPE_ID%token TOK_CTYPE_V%token TOK_CTYPE_VD%token TOK_CTYPE_VNAM%token TOK_C_FUNCTION_NAME%token TOK_DASH%token TOK_DATA_TYPE%token TOK_DEFAULT_TYPE%token TOK_DEFAULT_VALUE%token TOK_DESCRIPTION%token TOK_DIRECTION%token TOK_DIR_IN%token TOK_DIR_INOUT%token TOK_DIR_OUT%token TOK_DTYPE_BOOLEAN%token TOK_DTYPE_COMPLEX%token TOK_DTYPE_INT%token TOK_DTYPE_POINTER%token TOK_DTYPE_REAL%token TOK_DTYPE_STRING

⌨️ 快捷键说明

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