我的 Flex 文件输出错误

2024-01-05

我编写了一个 .l 文件并希望输出“c17.isc”中的内容。

但有一个错误我不知道为什么。我已经给出了我打算读取的文件、flex文件和执行结果。

这是 c17.isc 文件 内容的意思是

number  gate_name  gate_type  output_number  input_number  fault

带“from”的行表示扇出。 有2个数字的行仅表示输入列表。

*c17 iscas example (to test conversion program only)
*---------------------------------------------------
*
*
*  total number of lines in the netlist ..............    17
*  simplistically reduced equivalent fault set size =     22
*        lines from primary input  gates .......     5
*        lines from primary output gates .......     2
*        lines from interior gate outputs ......     4
*        lines from **     3 ** fanout stems ...     6
*
*        avg_fanin  =  2.00,     max_fanin  =  2
*        avg_fanout =  2.00,     max_fanout =  2
*
* 
*
*
*
    1     1gat inpt    1   0      >sa1
    2     2gat inpt    1   0      >sa1
    3     3gat inpt    2   0 >sa0 >sa1
    8     8fan from     3gat      >sa1
    9     9fan from     3gat      >sa1
    6     6gat inpt    1   0      >sa1
    7     7gat inpt    1   0      >sa1
   10    10gat nand    1   2      >sa1
     1     8
   11    11gat nand    2   2 >sa0 >sa1
     9     6
   14    14fan from    11gat      >sa1
   15    15fan from    11gat      >sa1
   16    16gat nand    2   2 >sa0 >sa1
     2    14
   20    20fan from    16gat      >sa1
   21    21fan from    16gat      >sa1
   19    19gat nand    1   2      >sa1
    15     7
   22    22gat nand    0   2 >sa0 >sa1
    10    20
   23    23gat nand    0   2 >sa0 >sa1
    21    19

这是我写的flex文件。

首先,这是声明文件:

# include <stdio.h>
# include <string.h>
# include <stdlib.h>

# define INPT 1
# define NOR 2
# define NAND 3
# define NOT 4
# define XOR 5
# define AND 6
# define BUFF 7
# define FROM 8

其次,这是 Flex 文件:

%{
# include "declare.h"

/*gi=1,it's input;gi=7,it's fanout;otherwise,it's gate*/
int gi=-1;
int inum=0;
int val;


struct{
    char *symbol;
    int val;
} symtab[]={
"inpt", INPT,
"nor", NOR,
"nand", NAND,
"not", NOT,
"xor", XOR,
"and", AND,
"buff", BUFF,
"from",FROM,
"0",0
};

extern FILE *yyin;
%}

%start A B C D E

DIGITS [0-9]+
BLANK [ \t\n]+
ALPHA [a-z]+

%%

"*".*\n     {ECHO; BEGIN A;}

<A>{BLANK}{DIGITS} {printf("num=%s\t",yytext); BEGIN B;}
<B>{BLANK}{DIGITS}{ALPHA} {printf("name=%s",yytext); BEGIN C;}
<C>{BLANK}{DIGITS} {printf("op=%s\t",yytext);BEGIN D;}
<C>{BLANK}{DIGITS}{ALPHA} {ECHO; BEGIN A;}
<D>{BLANK}{DIGITS} {inum=atoi(yytext);
                    printf("ip=%s\t",yytext);
                    if(gi==1)
                    {BEGIN A;}
                    if(gi!=1)
                    {BEGIN E;}
                   }

<E>{BLANK}{DIGITS} {inum--;
                    if(inum<0)
                    {printf("num=%s\t",yytext); BEGIN B;}
                    else
                    {printf("il=%s\t",yytext); BEGIN E;} 
                   }


{ALPHA} {gi=lookup(yytext);
         if(gi!=0) printf("\tty=%d\t",gi);
         else ECHO;

         }

{BLANK}">sa"[0-1] {val=atoi(&yytext[yyleng-1]);printf("\tfl=%d",val);}

{BLANK}    ;



%%
lookup(s)
char* s;
{int i;
for (i=0;symtab[i].val!=0;i++)
{
if(strcmp(symtab[i].symbol,s)==0)
break;
}
return(symtab[i].val);
}

main()
{
FILE *x=fopen("c17.isc","r");
yyin=x;
yylex();
}

这是执行结果。我用*标记了错误的地方。基本上错误发生在输入列表的行上。

例如,图中第一行错误的行应该是“num=10”,第二个错误行应该是“il=1 il=8" etc.

我对flex文件中输入列表的操作位于E部分。但我不知道为什么它不起作用。

num=1  name=1gat  ty=1  op=1  ip=0  fl=1
num=2  name=2gat  ty=1  op=1  ip=0  fl=1
num=3  name=3gat  ty=1  op=2  ip=0  fl=0  fl=1
num=8  name=8fan  ty=8  3gat  fl=1
num=9  name=9fan  ty=8  3gat  fl=1
num=6  name=6gat  ty=1  op=1  ip=0  fl=1
num=7  name=7gat  ty=1  op=1  ip=0  fl=1
**il=10**  name=10gat  ty=3  op=1  ip=2  fl=1
**num=1**  il=8
**il=11**  name=11gat  ty=3  op=2  ip=2  fl=0  fl=1
**num=9**  il=6
**num=4**  ...
**num=5**  ...
**il=16**  ...
**num=2**  il=14
**num=0**  ...
**num=1**  ...
**il=19**  ...
**num=15** il=7
**il=22**  ...
**il=23**  ...

您的代码的这种改编似乎可能会按您的预期工作。有各种变化,最显着的是输出一些换行符,并明确在哪里num=零件被识别。

%{
#include "declare.h"

/*gi=1, it's input;gi=7, it's fanout;otherwise, it's gate*/
static int gi = -1;
static int inum = 0;

extern int lookup(const char *s);

struct
{
    char *symbol;
    int val;
} symtab[]=
{
    {   "inpt", INPT },
    {   "nor",  NOR  },
    {   "nand", NAND },
    {   "not",  NOT  },
    {   "xor",  XOR  },
    {   "and",  AND  },
    {   "buff", BUFF },
    {   "from", FROM },
    {   "0",    0    },
};

extern FILE *yyin;
%}

%start A B C D E

DIGITS [0-9]+
BLANK [ \t\n]+
ALPHA [a-z]+

%%

"*".*\n              {ECHO; BEGIN A;}

<A>{DIGITS}          {printf("\nnum1=%s\t", yytext); BEGIN B;}
<B>{DIGITS}{ALPHA}   {printf(" name=%s\t",  yytext); BEGIN C;}
<C>{DIGITS}          {printf(" op=%s\t",    yytext); BEGIN D;}
<C>{DIGITS}{ALPHA}   {ECHO; BEGIN A;}
<D>{DIGITS}          {
                     inum=atoi(yytext);
                     printf(" ip=%s\t", yytext);
                     if (gi==1)
                     {BEGIN A;}
                     if (gi!=1)
                     {BEGIN E;}
                     }

<E>{DIGITS}          {inum--;
                     if (inum<0)
                     {printf("\nnum2=%s\t", yytext); BEGIN B;}
                     else
                     {printf(" il=%s\t", yytext); BEGIN E;} 
                     }

{ALPHA}              {
                     gi = lookup(yytext);
                     if (gi!=0) printf(" ty=%d (%s)\t", gi, yytext);
                     else { printf("Lookup failed: "); ECHO; }
                     }

">sa"[0-1]           {int val=atoi(&yytext[yyleng-1]);printf(" fl=%d", val);}

{BLANK}              ;
.                    { printf("Unmatched: %s\n", yytext); }

%%
int lookup(const char *s)
{
    int i;
    for (i = 0; symtab[i].val != 0; i++)
    {
        if (strcmp(symtab[i].symbol, s) == 0)
            break;
    }
    return(symtab[i].val);
}

int main(void)
{
    FILE *x=fopen("c17.isc", "r");
    yyin=x;
    yylex();
    putchar('\n');
}

对于您的示例输入,输出为:

*c17 iscas example (to test conversion program only)
*---------------------------------------------------
*
*
*  total number of lines in the netlist ..............    17
*  simplistically reduced equivalent fault set size =     22
*        lines from primary input  gates .......     5
*        lines from primary output gates .......     2
*        lines from interior gate outputs ......     4
*        lines from **     3 ** fanout stems ...     6
*
*        avg_fanin  =  2.00,     max_fanin  =  2
*        avg_fanout =  2.00,     max_fanout =  2
*
* 
*
*
*

num1=1   name=1gat   ty=1 (inpt)     op=1    ip=0    fl=1
num1=2   name=2gat   ty=1 (inpt)     op=1    ip=0    fl=1
num1=3   name=3gat   ty=1 (inpt)     op=2    ip=0    fl=0 fl=1
num1=8   name=8fan   ty=8 (from)    3gat fl=1
num1=9   name=9fan   ty=8 (from)    3gat fl=1
num1=6   name=6gat   ty=1 (inpt)     op=1    ip=0    fl=1
num1=7   name=7gat   ty=1 (inpt)     op=1    ip=0    fl=1
num1=10  name=10gat  ty=3 (nand)     op=1    ip=2    fl=1 il=1   il=8   
num2=11  name=11gat  ty=3 (nand)     op=2    ip=2    fl=0 fl=1 il=9  il=6   
num2=14  name=14fan  ty=8 (from)    11gat fl=1
num1=15  name=15fan  ty=8 (from)    11gat fl=1
num1=16  name=16gat  ty=3 (nand)     op=2    ip=2    fl=0 fl=1 il=2  il=14  
num2=20  name=20fan  ty=8 (from)    16gat fl=1
num1=21  name=21fan  ty=8 (from)    16gat fl=1
num1=19  name=19gat  ty=3 (nand)     op=1    ip=2    fl=1 il=15  il=7   
num2=22  name=22gat  ty=3 (nand)     op=0    ip=2    fl=0 fl=1 il=10     il=20  
num2=23  name=23gat  ty=3 (nand)     op=0    ip=2    fl=0 fl=1 il=21     il=19

该行与num1=10 has il=1 and il=8与之相关,这似乎反映了数据。 (我修改了打印输出以包括类型名称和类型编号。)

我不确定哪些变化是重要的。失去了{BLANK}我认为,匹配数字和 alpha 的部分规则简化了事情(扫描仪基本上忽略间距是很常见的)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

我的 Flex 文件输出错误 的相关文章

随机推荐

  • 为什么我的函数在修改数组时会更改参数? [复制]

    这个问题在这里已经有答案了 我不希望 foo 在此示例中发生任何更改 但是当我将其修改为函数中的数组时 它会更改参数 注意 foo 没有被 function1 改变 我猜是因为它没有直接修改参数 任何避免这种情况的帮助将不胜感激 http
  • 我应该使用哪一个? “docker Kill”还是“docker stop”?

    Will docker stop如果容器内运行的进程无法停止 则会失败 如果我使用docker kill 容器内未保存的数据可以保留吗 Is docker stop相比之下耗时docker kill 我想关闭容器 但不会丢失任何数据 没有高
  • 在 mongodb 中创建同名数据库?

    我发现可以创建具有相同名称的数据库 因此当我需要指定要使用哪些数据库时 具有相同名称的数据库会导致问题 事情是这样发生的 我已经有一个名为 test1 的数据库 它只存储带有文档的集合 然后 我用它来使用 GridFS 存储文件 因此它包含
  • 表行上的材质波纹效果

    我正在玩谷歌材料设计引导主题菲斯瓦斯塔 https github com FezVrasta bootstrap material design 大多数组件工作并且看起来都很棒 但是表行上的连锁反应对我来说不能正常工作 Demo jsfid
  • OpenERP 服务器错误 访问被拒绝

    安装 Odoo 后 我进入了 Web 面板 它要求创建新数据库 当我输入详细信息时出现错误 我可以成功更改主密码 我已经在 putty 上创建了数据库 并且 etc 文件夹下没有 openerp server conf 文件 Odoo Op
  • Javascript 有类似 VBA 的 DoEvents 的东西吗?

    我的代码中有一个长时间运行的 for 循环 我想延迟循环来处理事件队列中的其他任务 例如按下按钮 javascript 或 JQuery 有什么可以帮助我的吗 基本上我正在尝试做一些类似于延迟循环的事情 如下所示 https support
  • 带有“悬停”触发器的 AngularStrap bs-dropdown 没有保持打开足够长的时间

    当使用带有 悬停 触发器的 bs dropdown 时 菜单保持可见的时间不够长 无法允许用户单击菜单项 http plnkr co edit Fi39BdCOqHXnPAgITD01 p preview http plnkr co edi
  • 导入 scikits.talkbox 时出错

    我想使用 scikits talkbox 但在导入 scikits talkbox 时出现以下错误 回溯 最近一次调用最后一次 文件 home seref Desktop machinelearningcodes MFCC main py
  • 两个鸡蛋掉落拼图变化:未知/无限楼层

    Preface 这个问题的灵感来自于上周 SO 上的一个类似问题 该问题在弄清楚真正的问题是什么之前就被删除了 我认为这种变化提出了一个我想分享的好问题 两个鸡蛋问题 详细的定义和解决方案可以找到here https brilliant o
  • Dotfuscator 如何工作?

    Dotfuscator 如何工作 我尝试混淆我的一些类 并将方法 类重命名为 a b c 等 但我仍然可以看到这些方法中的代码 难道是我做错了什么 有什么可以阻止完全阻止拆卸我的组件吗 代码混淆远远超出了类 成员和变量的简单重命名 尽管这是
  • 在 Coldfusion 中使用 Unicode 字符解析 XML

    我正在使用 cfhttp 连接到外部 API 返回的数据为 XML 格式 我无法控制 API 或其返回的格式 当数据返回时 我循环遍历它并执行 cfquery 插入到我自己的 MySQL 数据库中 该数据库具有 UTF8 字符集 但是 某些
  • 如何获取已注册COM接口的IID?

    我知道我可以从注册表中的 COM 类对象读取 CLSIDClasses
  • 数据绑定到嵌套属性 - 无法绑定属性或列 (Winforms)

    我们正在使用 Windows 窗体运行 NET 4 0 应用程序 该应用程序对两种不同类型的对象使用单一表单 namespace NetIssue public partial class Form1 Form B myObj public
  • PowerShell 字符串插值语法

    我总是使用以下语法来确保变量在字符串中扩展 my string with a variable 我最近遇到了以下语法 my string with a variable 它们相等吗 有什么区别吗 tl dr Inside 只需要嵌入整个表达
  • ARM 上的快速浮点到整数转换和浮点精度 (iPhone 3GS/4)

    I read http www stereopsis com FPU html http www stereopsis com FPU html 中提到 在 x86 上将 float 转换为 int 的最快方法是什么 https stack
  • 扩展Python中的内置类

    如何扩展 python 中的内置类 我想向 str 类添加一个方法 我已经做了一些搜索 但我发现的只是较旧的帖子 我希望有人知道更新的内容 只需对类型进行子类化 gt gt gt class X str def my method self
  • 为什么 iPhone 请求 .m3u8 播放列表文件 4 次?

    为什么 iPhone 请求 m3u8 播放列表文件 4 次 并且 是否可以让它仅请求一次 请求执行如下 第一个是完整的请求 第二个是字节范围请求 范围为0 1 第三个是完整文件的另一个字节范围请求 最终的请求又是一个完整的请求 注意 iPh
  • 如何查看应用程序当前使用的堆大小?

    我想我在 NetBeans 中将堆大小增加到 1 GB 因为我将配置更改为如下所示 netbeans default options J Xmx1g 重新启动 NetBeans 后 我能否确定我的应用程序现在已获得 1 GB 空间 有没有办
  • 访问应用的外部脚本中的 buildscript 块中定义的类路径依赖项

    我最初的目标是能够使用中定义的类路径依赖项buildscript in build gradle 在导入的脚本内build gradle using apply from 但是 由于无法解析类 因此外部脚本无法编译 研究这个问题后 我发现逻
  • 我的 Flex 文件输出错误

    我编写了一个 l 文件并希望输出 c17 isc 中的内容 但有一个错误我不知道为什么 我已经给出了我打算读取的文件 flex文件和执行结果 这是 c17 isc 文件 内容的意思是 number gate name gate type o