小编Jen*_*nny的帖子

BNF到Flex/Bison

我正在尝试从BNF Grammar编写一个Flex/Bison文件.但是,当我尝试编译时出现错误,我不确定如何调试它们.

BNF Grammer:

<exp>::=<list> | head(<list>)
<list>::=<num1>::<list> | <list>@<list> | tail(<list>) | [<numlist>] 
<numlist>::=<empty> | <num1><num2>
<num2>::=<empty> | ,<num1><num2>
<num1>::=<D1><N> | <N> | head(<list>)
<D1>::=<D1><N> | <D2>
<D2>::=[1-9]
<N>::=[0-9]
Run Code Online (Sandbox Code Playgroud)

我的Flex文件

%option noyywrap

%{
#include <stdlib.h>
#include <list>
using namespace std;
#define YYSTYPE list<int>
#include "listop.tab.h"
%}

hd head
tl tail
ap [@()\[\]]
con ::
n [0-9]
d2 [1-9]
d1 ({d2}{n}+)|{d2}
ws[ \t\n]+

%%

{d1} yylval.clear(); yylval.push_front(atoi(yytext)); return D1;
{n} yylval.clear(); yylval.push_front(atoi(yytext)); return N;
{hd} return HEAD;
{tl} return TAIL; …
Run Code Online (Sandbox Code Playgroud)

yacc bnf bison flex-lexer

1
推荐指数
1
解决办法
3154
查看次数

标签 统计

bison ×1

bnf ×1

flex-lexer ×1

yacc ×1