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

📄 ifs_yacc.c

📁 ngspice又一个电子CAD仿真软件代码.功能更全
💻 C
📖 第 1 页 / 共 5 页
字号:
/* A Bison parser, made by GNU Bison 1.875d.  *//* Skeleton parser for Yacc-like parsing with Bison,   Copyright (C) 1984, 1989, 1990, 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.   This program 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, or (at your option)   any later version.   This program 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 program; if not, write to the Free Software   Foundation, Inc., 59 Temple Place - Suite 330,   Boston, MA 02111-1307, USA.  *//* As a special exception, when this file is copied by Bison into a   Bison output file, you may use that output file without restriction.   This special exception was added by the Free Software Foundation   in version 1.24 of Bison.  *//* Written by Richard Stallman by simplifying the original so called   ``semantic'' parser.  *//* All symbols defined below should begin with yy or YY, to avoid   infringing on user name space.  This should be done even for local   variables, as they might otherwise be expanded by user macros.   There are some unavoidable exceptions within include files to   define necessary library symbols; they are noted "INFRINGES ON   USER NAME SPACE" below.  *//* Identify Bison output.  */#define YYBISON 1/* Skeleton name.  */#define YYSKELETON_NAME "yacc.c"/* Pure parsers.  */#define YYPURE 0/* Using locations.  */#define YYLSP_NEEDED 0/* Tokens.  */#ifndef YYTOKENTYPE# define YYTOKENTYPE   /* Put the tokens into the symbol table, so that GDB and other debuggers      know about them.  */   enum yytokentype {     TOK_ALLOWED_TYPES = 258,     TOK_ARRAY = 259,     TOK_ARRAY_BOUNDS = 260,     TOK_BOOL_NO = 261,     TOK_BOOL_YES = 262,     TOK_COMMA = 263,     TOK_PORT_NAME = 264,     TOK_PORT_TABLE = 265,     TOK_CTYPE_D = 266,     TOK_CTYPE_G = 267,     TOK_CTYPE_GD = 268,     TOK_CTYPE_H = 269,     TOK_CTYPE_HD = 270,     TOK_CTYPE_I = 271,     TOK_CTYPE_ID = 272,     TOK_CTYPE_V = 273,     TOK_CTYPE_VD = 274,     TOK_CTYPE_VNAM = 275,     TOK_C_FUNCTION_NAME = 276,     TOK_DASH = 277,     TOK_DATA_TYPE = 278,     TOK_DEFAULT_TYPE = 279,     TOK_DEFAULT_VALUE = 280,     TOK_DESCRIPTION = 281,     TOK_DIRECTION = 282,     TOK_DIR_IN = 283,     TOK_DIR_INOUT = 284,     TOK_DIR_OUT = 285,     TOK_DTYPE_BOOLEAN = 286,     TOK_DTYPE_COMPLEX = 287,     TOK_DTYPE_INT = 288,     TOK_DTYPE_POINTER = 289,     TOK_DTYPE_REAL = 290,     TOK_DTYPE_STRING = 291,     TOK_IDENTIFIER = 292,     TOK_STATIC_VAR_NAME = 293,     TOK_STATIC_VAR_TABLE = 294,     TOK_INT_LITERAL = 295,     TOK_LANGLE = 296,     TOK_LBRACKET = 297,     TOK_LIMITS = 298,     TOK_NAME_TABLE = 299,     TOK_NULL_ALLOWED = 300,     TOK_PARAMETER_NAME = 301,     TOK_PARAMETER_TABLE = 302,     TOK_RANGLE = 303,     TOK_RBRACKET = 304,     TOK_REAL_LITERAL = 305,     TOK_SPICE_MODEL_NAME = 306,     TOK_STRING_LITERAL = 307   };#endif#define TOK_ALLOWED_TYPES 258#define TOK_ARRAY 259#define TOK_ARRAY_BOUNDS 260#define TOK_BOOL_NO 261#define TOK_BOOL_YES 262#define TOK_COMMA 263#define TOK_PORT_NAME 264#define TOK_PORT_TABLE 265#define TOK_CTYPE_D 266#define TOK_CTYPE_G 267#define TOK_CTYPE_GD 268#define TOK_CTYPE_H 269#define TOK_CTYPE_HD 270#define TOK_CTYPE_I 271#define TOK_CTYPE_ID 272#define TOK_CTYPE_V 273#define TOK_CTYPE_VD 274#define TOK_CTYPE_VNAM 275#define TOK_C_FUNCTION_NAME 276#define TOK_DASH 277#define TOK_DATA_TYPE 278#define TOK_DEFAULT_TYPE 279#define TOK_DEFAULT_VALUE 280#define TOK_DESCRIPTION 281#define TOK_DIRECTION 282#define TOK_DIR_IN 283#define TOK_DIR_INOUT 284#define TOK_DIR_OUT 285#define TOK_DTYPE_BOOLEAN 286#define TOK_DTYPE_COMPLEX 287#define TOK_DTYPE_INT 288#define TOK_DTYPE_POINTER 289#define TOK_DTYPE_REAL 290#define TOK_DTYPE_STRING 291#define TOK_IDENTIFIER 292#define TOK_STATIC_VAR_NAME 293#define TOK_STATIC_VAR_TABLE 294#define TOK_INT_LITERAL 295#define TOK_LANGLE 296#define TOK_LBRACKET 297#define TOK_LIMITS 298#define TOK_NAME_TABLE 299#define TOK_NULL_ALLOWED 300#define TOK_PARAMETER_NAME 301#define TOK_PARAMETER_TABLE 302#define TOK_RANGLE 303#define TOK_RBRACKET 304#define TOK_REAL_LITERAL 305#define TOK_SPICE_MODEL_NAME 306#define TOK_STRING_LITERAL 307/* Copy the first part of user declarations.  */#line 1 "ifs_yacc.y" /* $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;

⌨️ 快捷键说明

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