Bison 野牛通用识别命令
我正在开发一个野牛程序,需要有最后一个选项,允许它识别任何东西。很像其他的如果 谢谢Bison 野牛通用识别命令,bison,Bison,我正在开发一个野牛程序,需要有最后一个选项,允许它识别任何东西。很像其他的如果 谢谢 commands: F{ t[top++] = 'F'; } |PLUS{ t[top++] = '+'; } |MINUS{ t[topo++] = '-'; } |ACOL { t[top++] = '[
commands: F{
t[top++] = 'F';
}
|PLUS{
t[top++] = '+';
}
|MINUS{
t[topo++] = '-';
}
|ACOL {
t[top++] = '[';
}
|FCOL{
t[top++] = ']';
}
|POINT{
t[top++] = '.';
}
|EQUAL {
t[top++] = '=';
}
| {
/* generic command should be here
if any of the commands above were found it should run whatever is here*/
}
附加在标记非终端中识别出任何命令令牌后要运行的逻辑,如下所示。请注意,
标记
的产品右侧与任何标记都不匹配
command_and_marker: command marker;
command: F
{
t[top++] = 'F';
}
| PLUS
{
t[top++] = '+';
}
| MINUS
{
t[topo++] = '-';
}
| ACOL
{
t[top++] = '[';
}
| FCOL
{
t[top++] = ']';
}
| POINT
{
t[top++] = '.';
}
| EQUAL
{
t[top++] = '=';
}
marker: {
/* generic command should be here
if any of the commands above were found it should run whatever is here*/
}
我已经制定了我的答案来匹配代码中的注释,这些注释与您的问题文本有点不一致。如果您希望
command
匹配任何内容,而不仅仅是F
、PLUS
等,那么您必须拼写出您的lexer可以在command
的产品中生成的所有标记。这不一定是一个好主意,有几个原因。附加在标记非终端中识别出任何命令令牌后要运行的逻辑,如下所示。请注意,标记
的产品右侧与任何标记都不匹配
command_and_marker: command marker;
command: F
{
t[top++] = 'F';
}
| PLUS
{
t[top++] = '+';
}
| MINUS
{
t[topo++] = '-';
}
| ACOL
{
t[top++] = '[';
}
| FCOL
{
t[top++] = ']';
}
| POINT
{
t[top++] = '.';
}
| EQUAL
{
t[top++] = '=';
}
marker: {
/* generic command should be here
if any of the commands above were found it should run whatever is here*/
}
我已经制定了我的答案来匹配代码中的注释,这些注释与您的问题文本有点不一致。如果您希望command
匹配任何内容,而不仅仅是F
、PLUS
等,那么您必须拼写出您的lexer可以在command
的产品中生成的所有标记。出于几个原因,这不一定是个好主意