📄 mod_yacc.y
字号:
%{ /* $Id: mod_yacc.y,v 1.7 2005/05/10 21:50:43 sjborley Exp $ *//*============================================================================FILE mod_yacc.yMEMBER OF process cmppCopyright 1991Georgia Tech Research CorporationAtlanta, Georgia 30332All Rights ReservedPROJECT A-8503AUTHORS 9/12/91 Steve TynorMODIFICATIONS <date> <person name> <nature of modifications> 20050420 Steven Borley Renamed strcmpi() to local_strcmpi() to avoid clash with strcmpi() in a windows header file.SUMMARY This file contains a BNF specification of the translation of cfunc.mod files to cfunc.c files, together with various support functions.INTERFACES mod_yyparse() - Function 'yyparse()' is generated automatically by UNIX 'yacc' utility and then converted to 'mod_yyparse()' by UNIX 'sed' utility under direction of Makefile.REFERENCED FILES mod_lex.lNON-STANDARD FEATURES Names of functions generated by 'yacc' are translated by 'sed' under direction of the Makefile to prevent collisions with functions generated from ifs_yacc.y.============================================================================*/#include <assert.h>#include <stdio.h>#include <stdlib.h>#include "mod_yacc_y.h"#define yymaxdepth mod_yymaxdepth#define yyparse mod_yyparse#define yylex mod_yylex#define yyerror mod_yyerror#define yylval mod_yylval#define yychar mod_yychar#define yydebug mod_yydebug#define yypact mod_yypact#define yyr1 mod_yyr1#define yyr2 mod_yyr2#define yydef mod_yydef#define yychk mod_yychk#define yypgo mod_yypgo#define yyact mod_yyact#define yyexca mod_yyexca#define yyerrflag mod_yyerrflag#define yynerrs mod_yynerrs#define yyps mod_yyps#define yypv mod_yypv#define yys mod_yys#define yy_yys mod_yyyys#define yystate mod_yystate#define yytmp mod_yytmp#define yyv mod_yyv#define yy_yyv mod_yyyyv#define yyval mod_yyval#define yylloc mod_yylloc#define yyreds mod_yyreds#define yytoks mod_yytoks#define yylhs mod_yyyylhs#define yylen mod_yyyylen#define yydefred mod_yyyydefred#define yydgoto mod_yyyydgoto#define yysindex mod_yyyysindex#define yyrindex mod_yyyyrindex#define yygindex mod_yyyygindex#define yytable mod_yyyytable#define yycheck mod_yyyycheck#define yyname mod_yyyyname#define yyrule mod_yyyyruleIfs_Table_t *mod_ifs_table;extern char *mod_yytext;extern FILE* mod_yyout; extern void mod_yyerror(char*);#include <string.h>#include <ctype.h>int mod_num_errors;#define BUFFER_SIZE 3000static char buffer [BUFFER_SIZE];static int buf_len; typedef enum {CONN, PARAM, STATIC_VAR} Id_Kind_t;/*--------------------------------------------------------------------------*/static char *subscript (Sub_Id_t sub_id){ if (sub_id.has_subscript) { return sub_id.subscript; } else { return "0"; }}/*--------------------------------------------------------------------------*/int local_strcmpi(s, t) char *s; char *t; /* string compare - case insensitive */{ for (; *s && t && tolower(*s) == tolower(*t); s++, t++); if (*s && !*t) { return 1; } if (!*s && *t) { return -1; } if (! (*s || *t)) { return 0; } return (tolower(*s) - tolower(*t));}/*---------------------------------------------------------------------------*/static void put_type (FILE *fp, Data_Type_t type){ char ch = ' '; switch (type) { case INTEGER: ch = 'i'; break; case REAL: ch = 'r'; break; case COMPLEX: ch = 'c'; break; case BOOLEAN: ch = 'b'; break; case STRING: ch = 's'; break; case POINTER: ch = 'p'; break; } fprintf (fp, ".%cvalue", ch);}/*---------------------------------------------------------------------------*/static void put_conn_type (FILE *fp, Port_Type_t type){ char ch; switch (type) { case USER_DEFINED: ch = 'p'; break; case DIGITAL: ch = 'p'; break; default: ch = 'r'; break; } fprintf (fp, ".%cvalue", ch);}/*---------------------------------------------------------------------------*/static void check_dir (int conn_number, Dir_t dir, char *context){ Dir_t conn_dir; if (conn_number >= 0) { /* * If negative, this is an invalid port ID and we've already issued * an error. */ conn_dir = mod_ifs_table->conn[conn_number].direction; if ((conn_dir != dir) && (conn_dir != INOUT)) { char error_str[200]; sprintf (error_str, "Direction of port `%s' in %s() is not %s or INOUT", mod_ifs_table->conn[conn_number].name, context, (dir == IN) ? "IN" : "OUT"); yyerror (error_str); mod_num_errors++; } }}/*---------------------------------------------------------------------------*/static void check_subscript (Boolean_t formal, Boolean_t actual, Boolean_t missing_actual_ok, char *context, char *id){ char error_str[200]; if ((formal && !actual) && !missing_actual_ok) { sprintf (error_str, "%s `%s' is an array - subscript required", context, id); yyerror (error_str); mod_num_errors++; return; } else if (!formal && actual) { sprintf (error_str, "%s `%s' is not an array - subscript prohibited", context, id); yyerror (error_str); mod_num_errors++; return; }}/*---------------------------------------------------------------------------*/static int check_id (Sub_Id_t sub_id, Id_Kind_t kind, Boolean_t do_subscript){ int i; char error_str[200]; switch (kind) { case CONN: for (i = 0; i < mod_ifs_table->num_conn; i++) { if (0 == local_strcmpi (sub_id.id, mod_ifs_table->conn[i].name)) { if (do_subscript) { check_subscript (mod_ifs_table->conn[i].is_array, sub_id.has_subscript, FALSE, "Port", sub_id.id); } return i; } } break; case PARAM: for (i = 0; i < mod_ifs_table->num_param; i++) { if (0 == local_strcmpi (sub_id.id, mod_ifs_table->param[i].name)) { if (do_subscript) { check_subscript (mod_ifs_table->param[i].is_array, sub_id.has_subscript, FALSE, "Parameter", sub_id.id); } return i; } } break; case STATIC_VAR: for (i = 0; i < mod_ifs_table->num_inst_var; i++) { if (0 == local_strcmpi (sub_id.id, mod_ifs_table->inst_var[i].name)) { if (do_subscript) { check_subscript (mod_ifs_table->inst_var[i].is_array, sub_id.has_subscript, TRUE, "Static Variable", sub_id.id); } return i; } } break; } sprintf (error_str, "No %s named '%s'", ((kind==CONN) ? "port" : ((kind==PARAM) ? "parameter" :"static variable")), sub_id.id); yyerror (error_str); mod_num_errors++; return -1;}/*---------------------------------------------------------------------------*/static int valid_id (Sub_Id_t sub_id, Id_Kind_t kind){ return check_id (sub_id, kind, FALSE);}/*---------------------------------------------------------------------------*/static int valid_subid (Sub_Id_t sub_id, Id_Kind_t kind)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -