📄 netlist.l
字号:
%{
#include "component.h"
#include "y.tab.h"
extern YYSTYPE yyval, yylval;
#define read_to_eol() do {char c;while ((c = input()) && !strchr("\r\n\f",c) ); }while(0)
#ifdef __DEBUG
#define DBG(a) printf (#a "-%s\n",yytext)
#else
#define DBG(a)
#endif
%}
%option lex-compat
%x id1 id2 value unit post_unit
%x net pin pin_detect net2
%%
\[ {BEGIN(id1);return COMPONENT_START;}
<post_unit>\] {BEGIN(0);return COMPONENT_END;}
<*>[\n\r\f] ;
<*>[ \t]* ;
<id1>[^\[\]\(\)\n][^\r\n]* {
BEGIN(id2);
strcpy (yylval.svalue,yytext);
DBG(0);
return IDENTIFIER;
}
<id2>[^\[\]\(\)\n][^\r\n]* {
BEGIN(value);
strcpy (yylval.svalue,yytext);
DBG(1);
return IDENTIFIER;
}
<value>[0-9]+("."[0-9]+)?[ \t]*pF([^a-zA-Z][^\r\n]*)? {
BEGIN(post_unit);
yylval.fvalue = atof (yytext) * 1e-9;
DBG(2);
return CAPACITOR;
}
<value>[0-9]+("."[0-9]+)?[ \t]*F([^a-zA-Z][^\r\n]*)? {
BEGIN(post_unit);
yylval.fvalue = atof (yytext);
DBG(3);
return CAPACITOR;
}
<value>[0-9]+("."[0-9]+)?[ \t]*uF([^a-zA-Z][^\r\n]*)? {
BEGIN(post_unit);
yylval.fvalue = atof (yytext) * 1e-6;
DBG(4);
return CAPACITOR;
}
<value>[[0-9]+("."[0-9]+)?[ \t]*H([^a-zA-Z][^\r\n]*)? {
BEGIN(post_unit);
yylval.fvalue = atof (yytext);
DBG(5);
return INDUCTOR;
}
<value>[0-9]+("."[0-9]+)?[ \t]*mH([^a-zA-Z][^\r\n]*)? {
BEGIN(post_unit);
yylval.fvalue = atof (yytext) * 1e-3;
DBG(6);
return INDUCTOR;
}
<value>[0-9]+("."[0-9]+)?[ \t]*uH([^a-zA-Z][^\r\n]*)? {
BEGIN(post_unit);
yylval.fvalue = atof (yytext) * 1e-6;
DBG(7);
return INDUCTOR;
}
<value>[0-9]+("."[0-9]+)?[ \t]*K([^0-9a-zA-Z][^\r\n]*)? {
BEGIN(post_unit);
yylval.fvalue = atof (yytext) * 1e3;
DBG(8);
return RESISTOR;
}
<value>[0-9]+K[0-9]*([^a-zA-Z][^\r\n]*)? {
BEGIN(post_unit);
strcpy (yylval.svalue,yytext);
DBG(9);
return RESISTOR;
}
<value>[^\[\]\(\)\n][^\r\n]* {
BEGIN(post_unit);
strcpy (yylval.svalue,yytext);
DBG(A);
return IDENTIFIER;
}
\( {BEGIN(net);return NODE_START;}
<net2>\) {BEGIN(0);return NODE_END;}
<net>[^\[\]\(\)\n][^\n\r]* {
char c;
BEGIN(net2);
strcpy (yylval.svalue,yytext);
DBG(B);
return IDENTIFIER;
}
<net2>[^\[\]\(\)\n][^-\n\r]* {
char c;
BEGIN(pin);
strcpy (yylval.svalue,yytext);
DBG(B);
return IDENTIFIER;
}
<pin>"-"[0-9]+[^\r\n]* {
BEGIN(net2);
yylval.ivalue = atoi (yytext+1);
DBG(C);
return INTEGER;
}
<pin>"-"[^0-9][^\r\n]* {
BEGIN(net2);
strcpy (yylval.svalue,yytext+1);
DBG(D);
return IDENTIFIER;
}
%%
int yywrap () {return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -