【发布时间】:2015-02-11 13:47:43
【问题描述】:
所以我的目标是能够确定输入是否可以接受。以下是可接受的输入:
“u”、“d”、“l”、“r”、“n”的任意组合
**Example of valid inputs:**
udlrn
uuuuuuuuuuuu
dunrldd
dddddllll
dldnrrrrrrrrrrr
**Example of invalid inputs:**
abc
abcudlr
xudz
dclrxy
这是我的 Flex 代码
%%
"u" return UP;
"d" return DOWN;
"l" return LEFT;
"r" return RIGHT;
"n" return NONE;
\n return END;
%%
这是我的野牛代码
%token UP
%token DOWN
%token LEFT
%token RIGHT
%token NONE
%token END
%%
start: directions END
{
printf("\nParse complete with acceptable input\n");
}
;
directions: direction
|
directions direction
;
direction: UP | DOWN | LEFT | RIGHT | NONE
;
%%
但是,当我提供如下输入时:
- ldruabc
即使此输入无效,我也会收到解析完成消息。
【问题讨论】: