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

📄 netlist.y

📁 circuit calculation program
💻 Y
字号:
%{
#include <stdio.h>
#include <stdarg.h>

#include "component.h"


extern char *yytext;
extern FILE *yyin;


%}

%start netlist

%token IDENTIFIER
%token CAPACITOR
%token INDUCTOR
%token RESISTOR

%token INTEGER

%token COMPONENT_START
%token COMPONENT_END
%token NODE_START
%token NODE_END


%union { char svalue[100]; double fvalue;comp_def cvalue; int ivalue;}

%type <svalue> IDENTIFIER 
%type <fvalue> CAPACITOR INDUCTOR RESISTOR
%type <cvalue> instance
%type <ivalue> INTEGER

%%
	
netlist:
	components 
	{pin_init();}
	netlists 
	{link_init();}
	;

components:
	components component 
	| component 
	;
	
component:
	COMPONENT_START
	IDENTIFIER
	IDENTIFIER
	instance
	COMPONENT_END
	{
		comp_t *comp;
		
		printf("Compoent done:%s %s <%d>\n",$2,$3,$4.type);
		switch ($4.type)
		{
		case COMP_CAP:
		case COMP_IND:
		case COMP_RES:				
			comp = new_basic_component ($4.type, $2,$4.value.f);
			break;
		default:
			comp = new_component ($4.value.class, $2, NULL);
			break;
		}
		if (!comp) {
			yyerror ("component not instantiated:%s", $2 );
			YYERROR;
		}
	}
	;
	
instance:
	CAPACITOR
	{
		$$.type = COMP_CAP;
		$$.value.f = $1;
	}
	|INDUCTOR
	{
		$$.type = COMP_IND;
		$$.value.f = $1;
	}
	|RESISTOR
	{
		$$.type = COMP_RES;
		$$.value.f = $1;
	}
	|IDENTIFIER
	{
		$$.type = COMP_COMP;
		printf ("\nnew component class:%s",$1);
		if (!($$.value.class = get_class ($1))) {
			yyerror ("component not defined:%s", $1 );
			YYERROR;
		}
	}
netlists :
	netlists node_entry
	| node_entry
	;	
	
node_entry:
	NODE_START
	IDENTIFIER
	{
		node_start ($2);
	}
	nets
	NODE_END
	{ 
		node_end();
	}
	;

nets:
	nets net
	|net
	;

net:

	IDENTIFIER  IDENTIFIER
	{
		int i = pin_map_str_str ($1, $2);
		if (i==-2 ){
			yyerror ("Unknown component:%s\n", $1 );
			YYERROR;
		}else	if (i<0 ){
			yyerror ("Unknown pin <%s> for component:%s\n", $2, $1 );
			YYERROR;
		}else
			node_add_pin (i);
	}
	| IDENTIFIER  INTEGER
	{
		int i = pin_map_str_pin ($1, $2);
		if (i==-2 ){
			yyerror ("Unknown component:%s\n", $1 );
			YYERROR;
		}else	if (i<0 ){
			yyerror ("Unknown pin <%d> for component:%s\n", $2, $1 );
			YYERROR;
		}else
			node_add_pin (i);
	}
	;		
		
%%



yyerror( const char *fmt,...)
{
	va_list a;
	va_start (a, fmt);
	extern int yylineno;
	
	printf("line %d:",yylineno);	
	vprintf (fmt, a);
	
	va_end (a);
}

⌨️ 快捷键说明

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