PageRenderTime 58ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/ngspice-23/src/xspice/cmpp/ifs_yacc.y

#
Happy | 943 lines | 839 code | 104 blank | 0 comment | 0 complexity | be86a4baadb435fdbd6bb879a6f930f9 MD5 | raw file
Possible License(s): LGPL-2.0, GPL-2.0, LGPL-2.1
  1. %{ /* $Id: ifs_yacc.y,v 1.11 2011/05/01 19:46:53 rlar Exp $ */
  2. /*============================================================================
  3. FILE ifs_yacc.y
  4. MEMBER OF process cmpp
  5. Copyright 1991
  6. Georgia Tech Research Corporation
  7. Atlanta, Georgia 30332
  8. All Rights Reserved
  9. PROJECT A-8503
  10. AUTHORS
  11. 9/12/91 Steve Tynor
  12. MODIFICATIONS
  13. 12/31/91 Bill Kuhn Fix bug in usage of strcmp in check_default_type()
  14. SUMMARY
  15. This file contains the BNF specification of the language used in
  16. the ifspec.ifs file together with various support functions,
  17. and parses the ifspec.ifs file to get the information from it
  18. and place this information into a data structure
  19. of type Ifs_Table_t.
  20. INTERFACES
  21. yyparse() - Generated automatically by UNIX 'yacc' utility.
  22. REFERENCED FILES
  23. ifs_lex.l
  24. NON-STANDARD FEATURES
  25. None.
  26. ============================================================================*/
  27. #include <assert.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include "ifs_yacc_y.h"
  31. #define yymaxdepth ifs_yymaxdepth
  32. #define yyparse ifs_yyparse
  33. #define yylex ifs_yylex
  34. #define yyerror ifs_yyerror
  35. #define yylval ifs_yylval
  36. #define yychar ifs_yychar
  37. #define yydebug ifs_yydebug
  38. #define yypact ifs_yypact
  39. #define yyr1 ifs_yyr1
  40. #define yyr2 ifs_yyr2
  41. #define yydef ifs_yydef
  42. #define yychk ifs_yychk
  43. #define yypgo ifs_yypgo
  44. #define yyact ifs_yyact
  45. #define yyexca ifs_yyexca
  46. #define yyerrflag ifs_yyerrflag
  47. #define yynerrs ifs_yynerrs
  48. #define yyps ifs_yyps
  49. #define yypv ifs_yypv
  50. #define yys ifs_yys
  51. #define yy_yys ifs_yyyys
  52. #define yystate ifs_yystate
  53. #define yytmp ifs_yytmp
  54. #define yyv ifs_yyv
  55. #define yy_yyv ifs_yyyyv
  56. #define yyval ifs_yyval
  57. #define yylloc ifs_yylloc
  58. #define yyreds ifs_yyreds
  59. #define yytoks ifs_yytoks
  60. #define yylhs ifs_yyyylhs
  61. #define yylen ifs_yyyylen
  62. #define yydefred ifs_yyyydefred
  63. #define yydgoto ifs_yyyydgoto
  64. #define yysindex ifs_yyyysindex
  65. #define yyrindex ifs_yyyyrindex
  66. #define yygindex ifs_yyyygindex
  67. #define yytable ifs_yyyytable
  68. #define yycheck ifs_yyyycheck
  69. #define yyname ifs_yyyyname
  70. #define yyrule ifs_yyyyrule
  71. extern int yylineno;
  72. extern int yyival;
  73. extern double yydval;
  74. extern char *ifs_yytext;
  75. extern int ifs_yylex(void);
  76. Boolean_t parser_just_names;
  77. static Boolean_t saw_model_name;
  78. static Boolean_t saw_function_name;
  79. static char *dtype_to_str[] = {
  80. "BOOLEAN", "INTEGER", "REAL", "COMPLEX", "STRING", "POINTER"
  81. };
  82. static Boolean_t did_default_type;
  83. static Boolean_t did_allowed_types;
  84. static int num_items;
  85. static int item;
  86. static int item_offset;
  87. static Boolean_t num_items_fixed;
  88. Ifs_Table_t *parser_ifs_table;
  89. #define TBL parser_ifs_table
  90. static size_t alloced_size [4];
  91. /*
  92. * !!!!! Make sure these are large enough so that they never get realloced
  93. * !!!!! since that will cause garbage uninitialized data...
  94. * !!!!! (FIX THIS!)
  95. */
  96. #define DEFAULT_SIZE_CONN 100
  97. #define DEFAULT_SIZE_PARAM 100
  98. #define DEFAULT_SIZE_INST_VAR 100
  99. #define GROW_SIZE 10
  100. typedef enum {
  101. TBL_NAME,
  102. TBL_PORT,
  103. TBL_PARAMETER,
  104. TBL_STATIC_VAR,
  105. } Table_t;
  106. typedef struct {
  107. Table_t table;
  108. int record;
  109. } Context_t;
  110. Context_t context;
  111. #define ITEM_BUFFER_SIZE 20 /* number of items that can be put in a table
  112. * before requiring a new xxx_TABLE: keyword
  113. */
  114. #define FOR_ITEM(i) for (i = item_offset; i < num_items; i++)
  115. #define ITEM_BUF(i) item_buffer[i-item_offset]
  116. #define ASSIGN_BOUNDS(struct_name, i) \
  117. if (ITEM_BUF(i).range.is_named) {\
  118. TBL->struct_name[i].has_conn_ref = TRUE;\
  119. TBL->struct_name[i].conn_ref = find_conn_ref (ITEM_BUF(i).range.u.name);\
  120. } else {\
  121. TBL->struct_name[i].has_conn_ref = FALSE;\
  122. TBL->struct_name[i].has_lower_bound =\
  123. ITEM_BUF(i).range.u.bounds.lower.has_bound;\
  124. TBL->struct_name[i].has_upper_bound =\
  125. ITEM_BUF(i).range.u.bounds.upper.has_bound;\
  126. if (TBL->struct_name[i].has_lower_bound) {\
  127. assert (ITEM_BUF(i).range.u.bounds.lower.bound.kind == INTEGER);\
  128. TBL->struct_name[i].lower_bound =\
  129. ITEM_BUF(i).range.u.bounds.lower.bound.u.ivalue;\
  130. }\
  131. if (TBL->struct_name[i].has_upper_bound) {\
  132. assert (ITEM_BUF(i).range.u.bounds.upper.bound.kind == INTEGER);\
  133. TBL->struct_name[i].upper_bound =\
  134. ITEM_BUF(i).range.u.bounds.upper.bound.u.ivalue;\
  135. }\
  136. }
  137. /*---------------------------------------------------------------------------*/
  138. static void fatal (char *str)
  139. {
  140. yyerror (str);
  141. exit(1);
  142. }
  143. /*---------------------------------------------------------------------------*/
  144. static int
  145. find_conn_ref (char *name)
  146. {
  147. int i;
  148. char str[130];
  149. for (i = 0; i < TBL->num_conn; i++) {
  150. if (strcmp (name, TBL->conn[i].name) == 0) {
  151. return i;
  152. }
  153. }
  154. sprintf (str, "Port `%s' not found", name);
  155. yyerror (str);
  156. return 0;
  157. }
  158. typedef enum {C_DOUBLE, C_BOOLEAN, C_POINTER, C_UNDEF} Ctype_Class_t;
  159. /*---------------------------------------------------------------------------*/
  160. static Ctype_Class_t get_ctype_class (Port_Type_t type)
  161. {
  162. switch (type) {
  163. case USER_DEFINED:
  164. return C_POINTER;
  165. break;
  166. case DIGITAL:
  167. return C_BOOLEAN;
  168. break;
  169. default:
  170. return C_DOUBLE;
  171. break;
  172. }
  173. }
  174. /*---------------------------------------------------------------------------*/
  175. static void check_port_type_direction (Dir_t dir, Port_Type_t port_type)
  176. {
  177. switch (port_type) {
  178. case VOLTAGE:
  179. case DIFF_VOLTAGE:
  180. case CURRENT:
  181. case DIFF_CURRENT:
  182. case DIGITAL:
  183. case USER_DEFINED:
  184. /*
  185. * anything goes
  186. */
  187. break;
  188. case VSOURCE_CURRENT:
  189. if (dir != IN) {
  190. yyerror ("Port type `vnam' is only valid for `in' ports");
  191. }
  192. break;
  193. case CONDUCTANCE:
  194. case DIFF_CONDUCTANCE:
  195. case RESISTANCE:
  196. case DIFF_RESISTANCE:
  197. if (dir != INOUT) {
  198. yyerror ("Port types `g', `gd', `h', `hd' are only valid for `inout' ports");
  199. }
  200. break;
  201. default:
  202. assert (0);
  203. }
  204. }
  205. /*---------------------------------------------------------------------------*/
  206. static void check_dtype_not_pointer (Data_Type_t dtype)
  207. {
  208. if (dtype == POINTER) {
  209. yyerror("Invalid parameter type - POINTER type valid only for STATIC_VARs");
  210. }
  211. }
  212. /*---------------------------------------------------------------------------*/
  213. static void check_default_type (Conn_Info_t conn)
  214. {
  215. int i;
  216. for (i = 0; i < conn.num_allowed_types; i++) {
  217. if (conn.default_port_type == conn.allowed_port_type[i]) {
  218. if ((conn.default_port_type != USER_DEFINED) ||
  219. (strcmp (conn.default_type, conn.allowed_type[i]) == 0)) {
  220. return;
  221. }
  222. }
  223. }
  224. yyerror ("Port default type is not an allowed type");
  225. }
  226. /*---------------------------------------------------------------------------*/
  227. static void
  228. assign_ctype_list (Conn_Info_t *conn, Ctype_List_t *ctype_list )
  229. {
  230. int i;
  231. Ctype_List_t *p;
  232. Ctype_Class_t ctype_class = C_UNDEF;
  233. conn->num_allowed_types = 0;
  234. for (p = ctype_list; p; p = p->next) {
  235. conn->num_allowed_types++;
  236. }
  237. conn->allowed_type = (char**) calloc ((size_t) conn->num_allowed_types,
  238. sizeof (char*));
  239. conn->allowed_port_type = (Port_Type_t*) calloc ((size_t) conn->num_allowed_types,
  240. sizeof (Port_Type_t));
  241. if (! (conn->allowed_type && conn->allowed_port_type)) {
  242. fatal ("Could not allocate memory");
  243. }
  244. for (i = conn->num_allowed_types-1, p = ctype_list; p; i--, p = p->next) {
  245. if (ctype_class == C_UNDEF) {
  246. ctype_class = get_ctype_class (p->ctype.kind);
  247. }
  248. if (ctype_class != get_ctype_class (p->ctype.kind)) {
  249. yyerror ("Incompatible port types in `allowed_types' clause");
  250. }
  251. check_port_type_direction (conn->direction, p->ctype.kind);
  252. conn->allowed_port_type[i] = p->ctype.kind;
  253. conn->allowed_type[i] = p->ctype.id;
  254. }
  255. }
  256. /*---------------------------------------------------------------------------*/
  257. static void
  258. assign_value (Data_Type_t type, Value_t *dest_value, My_Value_t src_value)
  259. {
  260. char str[200];
  261. if ((type == REAL) && (src_value.kind == INTEGER)) {
  262. dest_value->rvalue = src_value.u.ivalue;
  263. return;
  264. } else if (type != src_value.kind) {
  265. sprintf (str, "Invalid parameter type (saw %s - expected %s)",
  266. dtype_to_str[src_value.kind],
  267. dtype_to_str[type] );
  268. yyerror (str);
  269. }
  270. switch (type) {
  271. case BOOLEAN:
  272. dest_value->bvalue = src_value.u.bvalue;
  273. break;
  274. case INTEGER:
  275. dest_value->ivalue = src_value.u.ivalue;
  276. break;
  277. case REAL:
  278. dest_value->rvalue = src_value.u.rvalue;
  279. break;
  280. case COMPLEX:
  281. dest_value->cvalue = src_value.u.cvalue;
  282. break;
  283. case STRING:
  284. dest_value->svalue = src_value.u.svalue;
  285. break;
  286. default:
  287. yyerror ("INTERNAL ERROR - unexpected data type in `assign_value'");
  288. }
  289. }
  290. /*---------------------------------------------------------------------------*/
  291. static void
  292. assign_limits (Data_Type_t type, Param_Info_t *param, Range_t range)
  293. {
  294. if (range.is_named) {
  295. yyerror ("Named range not allowed for limits");
  296. }
  297. param->has_lower_limit = range.u.bounds.lower.has_bound;
  298. if (param->has_lower_limit) {
  299. assign_value (type, &param->lower_limit, range.u.bounds.lower.bound);
  300. }
  301. param->has_upper_limit = range.u.bounds.upper.has_bound;
  302. if (param->has_upper_limit) {
  303. assign_value (type, &param->upper_limit, range.u.bounds.upper.bound);
  304. }
  305. }
  306. /*---------------------------------------------------------------------------*/
  307. static void
  308. check_item_num (void)
  309. {
  310. if (item-item_offset >= ITEM_BUFFER_SIZE) {
  311. fatal ("Too many items in table - split into sub-tables");
  312. }
  313. if (item > (int) alloced_size [context.table] ) {
  314. switch (context.table) {
  315. case TBL_NAME:
  316. break;
  317. case TBL_PORT:
  318. alloced_size[context.table] += GROW_SIZE;
  319. TBL->conn = (Conn_Info_t*)
  320. realloc (TBL->conn,
  321. alloced_size [context.table] * sizeof (Conn_Info_t));
  322. if (! TBL->conn) {
  323. fatal ("Error allocating memory for port definition");
  324. }
  325. break;
  326. case TBL_PARAMETER:
  327. alloced_size [context.table] += GROW_SIZE;
  328. TBL->param = (Param_Info_t*)
  329. realloc (TBL->param,
  330. alloced_size [context.table] * sizeof (Param_Info_t));
  331. if (! TBL->param) {
  332. fatal ("Error allocating memory for parameter definition");
  333. }
  334. break;
  335. case TBL_STATIC_VAR:
  336. alloced_size [context.table] += GROW_SIZE;
  337. TBL->inst_var = (Inst_Var_Info_t*)
  338. realloc (TBL->inst_var,
  339. alloced_size [context.table] * sizeof (Inst_Var_Info_t));
  340. if (! TBL->inst_var) {
  341. fatal ("Error allocating memory for static variable definition");
  342. }
  343. break;
  344. }
  345. }
  346. item++;
  347. }
  348. /*---------------------------------------------------------------------------*/
  349. static void
  350. check_end_item_num (void)
  351. {
  352. if (num_items_fixed) {
  353. if (item != num_items) {
  354. char buf[200];
  355. sprintf
  356. (buf,
  357. "Wrong number of elements in sub-table (saw %d - expected %d)",
  358. item - item_offset,
  359. num_items - item_offset);
  360. fatal (buf);
  361. }
  362. } else {
  363. num_items = item;
  364. num_items_fixed = TRUE;
  365. switch (context.table) {
  366. case TBL_NAME:
  367. break;
  368. case TBL_PORT:
  369. TBL->num_conn = num_items;
  370. break;
  371. case TBL_PARAMETER:
  372. TBL->num_param = num_items;
  373. break;
  374. case TBL_STATIC_VAR:
  375. TBL->num_inst_var = num_items;
  376. break;
  377. }
  378. }
  379. item = item_offset;
  380. }
  381. #define INIT(n) item = (n); item_offset = (n); num_items = (n); num_items_fixed = FALSE
  382. #define ITEM check_item_num()
  383. #define END check_end_item_num()
  384. %}
  385. %token TOK_ALLOWED_TYPES
  386. %token TOK_ARRAY
  387. %token TOK_ARRAY_BOUNDS
  388. %token TOK_BOOL_NO
  389. %token TOK_BOOL_YES
  390. %token TOK_COMMA
  391. %token TOK_PORT_NAME
  392. %token TOK_PORT_TABLE
  393. %token TOK_CTYPE_D
  394. %token TOK_CTYPE_G
  395. %token TOK_CTYPE_GD
  396. %token TOK_CTYPE_H
  397. %token TOK_CTYPE_HD
  398. %token TOK_CTYPE_I
  399. %token TOK_CTYPE_ID
  400. %token TOK_CTYPE_V
  401. %token TOK_CTYPE_VD
  402. %token TOK_CTYPE_VNAM
  403. %token TOK_C_FUNCTION_NAME
  404. %token TOK_DASH
  405. %token TOK_DATA_TYPE
  406. %token TOK_DEFAULT_TYPE
  407. %token TOK_DEFAULT_VALUE
  408. %token TOK_DESCRIPTION
  409. %token TOK_DIRECTION
  410. %token TOK_DIR_IN
  411. %token TOK_DIR_INOUT
  412. %token TOK_DIR_OUT
  413. %token TOK_DTYPE_BOOLEAN
  414. %token TOK_DTYPE_COMPLEX
  415. %token TOK_DTYPE_INT
  416. %token TOK_DTYPE_POINTER
  417. %token TOK_DTYPE_REAL
  418. %token TOK_DTYPE_STRING
  419. %token TOK_IDENTIFIER
  420. %token TOK_STATIC_VAR_NAME
  421. %token TOK_STATIC_VAR_TABLE
  422. %token TOK_INT_LITERAL
  423. %token TOK_LANGLE
  424. %token TOK_LBRACKET
  425. %token TOK_LIMITS
  426. %token TOK_NAME_TABLE
  427. %token TOK_NULL_ALLOWED
  428. %token TOK_PARAMETER_NAME
  429. %token TOK_PARAMETER_TABLE
  430. %token TOK_RANGLE
  431. %token TOK_RBRACKET
  432. %token TOK_REAL_LITERAL
  433. %token TOK_SPICE_MODEL_NAME
  434. %token TOK_STRING_LITERAL
  435. %union {
  436. Ctype_List_t *ctype_list;
  437. Dir_t dir;
  438. Boolean_t bool;
  439. Range_t range;
  440. Data_Type_t dtype;
  441. My_Port_Type_t ctype;
  442. My_Value_t value;
  443. char *str;
  444. Bound_t bound;
  445. int ival;
  446. double rval;
  447. Complex_t cval;
  448. }
  449. %type <ctype_list> ctype_list delimited_ctype_list
  450. %type <dir> direction
  451. %type <ctype> ctype
  452. %type <dtype> dtype
  453. %type <range> range int_range
  454. %type <value> value number integer_value value_or_dash
  455. %type <str> identifier string
  456. %type <bool> bool
  457. %type <bound> int_or_dash number_or_dash
  458. %type <ival> integer
  459. %type <rval> real
  460. %type <cval> complex
  461. %start ifs_file
  462. %{
  463. /*
  464. * resuse the Yacc union for our buffer:
  465. */
  466. YYSTYPE item_buffer [ITEM_BUFFER_SIZE];
  467. /*
  468. * Shorthand for refering to the current element of the item buffer:
  469. */
  470. #define BUF ITEM_BUF(item-1)
  471. %}
  472. %%
  473. ifs_file : {TBL->num_conn = 0;
  474. TBL->num_param = 0;
  475. TBL->num_inst_var = 0;
  476. saw_function_name = FALSE;
  477. saw_model_name = FALSE;
  478. alloced_size [TBL_PORT] = DEFAULT_SIZE_CONN;
  479. alloced_size [TBL_PARAMETER] = DEFAULT_SIZE_PARAM;
  480. alloced_size [TBL_STATIC_VAR] =
  481. DEFAULT_SIZE_INST_VAR;
  482. TBL->conn = (Conn_Info_t*)
  483. calloc (DEFAULT_SIZE_CONN,
  484. sizeof (Conn_Info_t));
  485. TBL->param = (Param_Info_t*)
  486. calloc (DEFAULT_SIZE_PARAM,
  487. sizeof (Param_Info_t));
  488. TBL->inst_var = (Inst_Var_Info_t*)
  489. calloc (DEFAULT_SIZE_INST_VAR,
  490. sizeof (Inst_Var_Info_t));
  491. if (! (TBL->conn && TBL->param &&
  492. TBL->inst_var) ) {
  493. fatal ("Could not allocate enough memory");
  494. }
  495. }
  496. list_of_tables
  497. ;
  498. list_of_tables : table
  499. | list_of_tables table
  500. ;
  501. table : TOK_NAME_TABLE
  502. {context.table = TBL_NAME;}
  503. name_table
  504. | TOK_PORT_TABLE
  505. {context.table = TBL_PORT;
  506. did_default_type = FALSE;
  507. did_allowed_types = FALSE;
  508. INIT (TBL->num_conn);}
  509. port_table
  510. {TBL->num_conn = num_items;}
  511. | TOK_PARAMETER_TABLE
  512. {context.table = TBL_PARAMETER;
  513. INIT (TBL->num_param);}
  514. parameter_table
  515. {TBL->num_param = num_items;}
  516. | TOK_STATIC_VAR_TABLE
  517. {context.table = TBL_STATIC_VAR;
  518. INIT (TBL->num_inst_var);}
  519. static_var_table
  520. {TBL->num_inst_var = num_items;}
  521. ;
  522. name_table : /* empty */
  523. | name_table name_table_item
  524. ;
  525. name_table_item : TOK_C_FUNCTION_NAME identifier
  526. {TBL->name.c_fcn_name =strdup (ifs_yytext);
  527. saw_function_name = TRUE;
  528. if (parser_just_names && saw_model_name) return 0;}
  529. | TOK_SPICE_MODEL_NAME identifier
  530. {TBL->name.model_name = strdup (ifs_yytext);
  531. saw_model_name = TRUE;
  532. if (parser_just_names && saw_function_name) return 0;}
  533. | TOK_DESCRIPTION string
  534. {TBL->name.description = strdup (ifs_yytext);}
  535. ;
  536. port_table : /* empty */
  537. | port_table port_table_item
  538. ;
  539. port_table_item : TOK_PORT_NAME list_of_ids
  540. {int i;
  541. END;
  542. FOR_ITEM (i) {
  543. TBL->conn[i].name = ITEM_BUF(i).str;
  544. }}
  545. | TOK_DESCRIPTION list_of_strings
  546. {int i;
  547. END;
  548. FOR_ITEM (i) {
  549. TBL->conn[i].description = ITEM_BUF(i).str;
  550. }}
  551. | TOK_DIRECTION list_of_directions
  552. {int i;
  553. END;
  554. FOR_ITEM (i) {
  555. TBL->conn[i].direction = ITEM_BUF(i).dir;
  556. }}
  557. | TOK_DEFAULT_TYPE list_of_ctypes
  558. {int i;
  559. END;
  560. did_default_type = TRUE;
  561. FOR_ITEM (i) {
  562. TBL->conn[i].default_port_type =
  563. ITEM_BUF(i).ctype.kind;
  564. TBL->conn[i].default_type = ITEM_BUF(i).ctype.id;
  565. if (did_allowed_types) {
  566. check_default_type (TBL->conn[i]);
  567. }
  568. }}
  569. | TOK_ALLOWED_TYPES list_of_ctype_lists
  570. {int i;
  571. END;
  572. did_allowed_types = TRUE;
  573. FOR_ITEM (i) {
  574. assign_ctype_list (&TBL->conn[i],
  575. ITEM_BUF(i).ctype_list);
  576. if (did_default_type) {
  577. check_default_type (TBL->conn[i]);
  578. }
  579. }}
  580. | TOK_ARRAY list_of_bool
  581. {int i;
  582. END;
  583. FOR_ITEM (i) {
  584. TBL->conn[i].is_array = ITEM_BUF(i).bool;
  585. }}
  586. | TOK_ARRAY_BOUNDS list_of_array_bounds
  587. {int i;
  588. END;
  589. FOR_ITEM (i) {
  590. ASSIGN_BOUNDS (conn, i);
  591. assert (!TBL->conn[i].has_conn_ref);
  592. }}
  593. | TOK_NULL_ALLOWED list_of_bool
  594. {int i;
  595. END;
  596. FOR_ITEM (i) {
  597. TBL->conn[i].null_allowed = ITEM_BUF(i).bool;
  598. }}
  599. ;
  600. parameter_table : /* empty */
  601. | parameter_table parameter_table_item
  602. ;
  603. parameter_table_item : TOK_PARAMETER_NAME list_of_ids
  604. {int i;
  605. END;
  606. FOR_ITEM (i) {
  607. TBL->param[i].name = ITEM_BUF(i).str;
  608. }}
  609. | TOK_DESCRIPTION list_of_strings
  610. {int i;
  611. END;
  612. FOR_ITEM (i) {
  613. TBL->param[i].description = ITEM_BUF(i).str;
  614. }}
  615. | TOK_DATA_TYPE list_of_dtypes
  616. {int i;
  617. END;
  618. FOR_ITEM (i) {
  619. check_dtype_not_pointer (ITEM_BUF(i).dtype);
  620. TBL->param[i].type = ITEM_BUF(i).dtype;
  621. }}
  622. | TOK_DEFAULT_VALUE list_of_values
  623. {int i;
  624. END;
  625. FOR_ITEM (i) {
  626. TBL->param[i].has_default =
  627. ITEM_BUF(i).value.has_value;
  628. if (TBL->param[i].has_default) {
  629. assign_value (TBL->param[i].type,
  630. &TBL->param[i].default_value,
  631. ITEM_BUF(i).value);
  632. }
  633. }}
  634. | TOK_LIMITS list_of_ranges
  635. {int i;
  636. END;
  637. FOR_ITEM (i) {
  638. assign_limits (TBL->param[i].type,
  639. &TBL->param[i],
  640. ITEM_BUF(i).range);
  641. }}
  642. | TOK_ARRAY list_of_bool
  643. {int i;
  644. END;
  645. FOR_ITEM (i) {
  646. TBL->param[i].is_array = ITEM_BUF(i).bool;
  647. }}
  648. | TOK_ARRAY_BOUNDS list_of_array_bounds
  649. {int i;
  650. END;
  651. FOR_ITEM (i) {
  652. ASSIGN_BOUNDS (param, i);
  653. }}
  654. | TOK_NULL_ALLOWED list_of_bool
  655. {int i;
  656. END;
  657. FOR_ITEM (i) {
  658. TBL->param[i].null_allowed = ITEM_BUF(i).bool;
  659. }}
  660. ;
  661. static_var_table : /* empty */
  662. | static_var_table static_var_table_item
  663. ;
  664. static_var_table_item : TOK_STATIC_VAR_NAME list_of_ids
  665. {int i;
  666. END;
  667. FOR_ITEM (i) {
  668. TBL->inst_var[i].name = ITEM_BUF(i).str;
  669. }}
  670. | TOK_DESCRIPTION list_of_strings
  671. {int i;
  672. END;
  673. FOR_ITEM (i) {
  674. TBL->inst_var[i].description = ITEM_BUF(i).str;
  675. }}
  676. | TOK_DATA_TYPE list_of_dtypes
  677. {int i;
  678. END;
  679. FOR_ITEM (i) {
  680. TBL->inst_var[i].type = ITEM_BUF(i).dtype;
  681. }}
  682. | TOK_ARRAY list_of_bool
  683. {int i;
  684. END;
  685. FOR_ITEM (i) {
  686. TBL->inst_var[i].is_array = ITEM_BUF(i).bool;
  687. }}
  688. ;
  689. list_of_ids : /* empty */
  690. | list_of_ids identifier {ITEM; BUF.str = $2;}
  691. ;
  692. list_of_array_bounds : /* empty */
  693. | list_of_array_bounds int_range
  694. {ITEM;
  695. BUF.range = $2;}
  696. | list_of_array_bounds identifier
  697. {ITEM;
  698. BUF.range.is_named = TRUE;
  699. BUF.range.u.name = $2;}
  700. ;
  701. list_of_strings : /* empty */
  702. | list_of_strings string {ITEM; BUF.str = $2;}
  703. ;
  704. list_of_directions : /* empty */
  705. | list_of_directions direction {ITEM; BUF.dir = $2;}
  706. ;
  707. direction : TOK_DIR_IN {$$ = IN;}
  708. | TOK_DIR_OUT {$$ = OUT;}
  709. | TOK_DIR_INOUT {$$ = INOUT;}
  710. ;
  711. list_of_bool : /* empty */
  712. | list_of_bool bool {ITEM; BUF.bool = $2;}
  713. ;
  714. list_of_ctypes : /* empty */
  715. | list_of_ctypes ctype {ITEM; BUF.ctype = $2;}
  716. ;
  717. ctype : TOK_CTYPE_V {$$.kind = VOLTAGE;}
  718. | TOK_CTYPE_VD {$$.kind = DIFF_VOLTAGE;}
  719. | TOK_CTYPE_VNAM {$$.kind = VSOURCE_CURRENT;}
  720. | TOK_CTYPE_I {$$.kind = CURRENT;}
  721. | TOK_CTYPE_ID {$$.kind = DIFF_CURRENT;}
  722. | TOK_CTYPE_G {$$.kind = CONDUCTANCE;}
  723. | TOK_CTYPE_GD {$$.kind = DIFF_CONDUCTANCE;}
  724. | TOK_CTYPE_H {$$.kind = RESISTANCE;}
  725. | TOK_CTYPE_HD {$$.kind = DIFF_RESISTANCE;}
  726. | TOK_CTYPE_D {$$.kind = DIGITAL;}
  727. | identifier {$$.kind = USER_DEFINED;
  728. $$.id = $1;}
  729. ;
  730. list_of_dtypes : /* empty */
  731. | list_of_dtypes dtype {ITEM; BUF.dtype = $2;}
  732. ;
  733. dtype : TOK_DTYPE_REAL {$$ = REAL;}
  734. | TOK_DTYPE_INT {$$ = INTEGER;}
  735. | TOK_DTYPE_BOOLEAN {$$ = BOOLEAN;}
  736. | TOK_DTYPE_COMPLEX {$$ = COMPLEX;}
  737. | TOK_DTYPE_STRING {$$ = STRING;}
  738. | TOK_DTYPE_POINTER {$$ = POINTER;}
  739. ;
  740. list_of_ranges : /* empty */
  741. | list_of_ranges range {ITEM; BUF.range = $2;}
  742. ;
  743. int_range : TOK_DASH {$$.is_named = FALSE;
  744. $$.u.bounds.lower.has_bound = FALSE;
  745. $$.u.bounds.upper.has_bound = FALSE;}
  746. | TOK_LBRACKET int_or_dash maybe_comma int_or_dash
  747. TOK_RBRACKET
  748. {$$.is_named = FALSE;
  749. $$.u.bounds.lower = $2;
  750. $$.u.bounds.upper = $4;}
  751. ;
  752. maybe_comma : /* empty */
  753. | TOK_COMMA
  754. ;
  755. int_or_dash : TOK_DASH {$$.has_bound = FALSE;}
  756. | integer_value {$$.has_bound = TRUE;
  757. $$.bound = $1;}
  758. ;
  759. range : TOK_DASH {$$.is_named = FALSE;
  760. $$.u.bounds.lower.has_bound = FALSE;
  761. $$.u.bounds.upper.has_bound = FALSE;}
  762. | TOK_LBRACKET number_or_dash maybe_comma
  763. number_or_dash TOK_RBRACKET
  764. {$$.is_named = FALSE;
  765. $$.u.bounds.lower = $2;
  766. $$.u.bounds.upper = $4;}
  767. ;
  768. number_or_dash : TOK_DASH {$$.has_bound = FALSE;}
  769. | number {$$.has_bound = TRUE;
  770. $$.bound = $1;}
  771. ;
  772. list_of_values : /* empty */
  773. | list_of_values value_or_dash {ITEM; BUF.value = $2;}
  774. ;
  775. value_or_dash : TOK_DASH {$$.has_value = FALSE;}
  776. | value
  777. ;
  778. value : string {$$.has_value = TRUE;
  779. $$.kind = STRING;
  780. $$.u.svalue = $1;}
  781. | bool {$$.has_value = TRUE;
  782. $$.kind = BOOLEAN;
  783. $$.u.bvalue = $1;}
  784. | complex {$$.has_value = TRUE;
  785. $$.kind = COMPLEX;
  786. $$.u.cvalue = $1;}
  787. | number
  788. ;
  789. complex : TOK_LANGLE real maybe_comma real TOK_RANGLE
  790. {$$.real = $2;
  791. $$.imag = $4;}
  792. ;
  793. list_of_ctype_lists : /* empty */
  794. | list_of_ctype_lists delimited_ctype_list
  795. {ITEM; BUF.ctype_list = $2;}
  796. ;
  797. delimited_ctype_list : TOK_LBRACKET ctype_list TOK_RBRACKET {$$ = $2;}
  798. ;
  799. ctype_list : ctype
  800. {$$ = (Ctype_List_t*)calloc (1,
  801. sizeof (Ctype_List_t));
  802. if (!$$) {
  803. fatal ("Error allocating memory");
  804. }
  805. $$->ctype = $1;
  806. $$->next = (Ctype_List_t*)0;}
  807. | ctype_list maybe_comma ctype
  808. {$$ = (Ctype_List_t*)calloc (1,
  809. sizeof (Ctype_List_t));
  810. if (!$$) {
  811. fatal ("Error allocating memory");
  812. }
  813. $$->ctype = $3;
  814. $$->next = $1;
  815. /*$$->next = (Ctype_List_t*)0;
  816. assert ($1);
  817. $1->next = $$;*/}
  818. ;
  819. bool : TOK_BOOL_YES {$$ = TRUE;}
  820. | TOK_BOOL_NO {$$ = FALSE;}
  821. ;
  822. string : TOK_STRING_LITERAL {$$ = strdup(ifs_yytext);}
  823. ;
  824. identifier : TOK_IDENTIFIER {$$ = strdup(ifs_yytext);}
  825. ;
  826. number : real {$$.has_value = TRUE;
  827. $$.kind = REAL;
  828. $$.u.rvalue = $1;}
  829. | integer_value
  830. ;
  831. integer_value : integer {$$.has_value = TRUE;
  832. $$.kind = INTEGER;
  833. $$.u.ivalue = $1;}
  834. ;
  835. real : TOK_REAL_LITERAL {$$ = yydval;}
  836. ;
  837. integer : TOK_INT_LITERAL {$$ = yyival;}
  838. ;
  839. %%