1
在Flex中,您可以使用[a-zA-Z] [a-zA-Z0-9] *來定義一個單詞。我如何定義一個句子? 以下是我的Flex代碼:Flex-BISON:如何定義一個句子?
%{
#include <stdio.h>
#include <string.h>
#include "y.tab.h"
%}
%%
[0-9]+ yylval=atoi(yytext);return NUMBER;
[a-zA-Z][a-zA-Z]* return WORD;
[a-zA-Z][a-zA-Z0-9]* return TERM;
%%
而且下面是野牛:
%{
#include <stdio.h>
#include <string.h>
void yyerror(const char *str)
{
fprintf(stderr,"error: %s\n",str);
}
int yywrap()
{
return 1;
}
main()
{
yyparse();
}
%}
%token NUMBER WORD TERM
commands: /* empty */
| commands command
;
command:
rule1
|
rule2
;
.....
感謝