我正在尝试使用 yacc 和 lex 编写 shell,但我的 I/O 重定向器遇到了一些问题。目前,我可以按任何顺序很好地使用 < 和 > 运算符,但我的问题是我可以重定向两次而没有错误,例如“ls > log > log2”
我的规则代码如下,谁能给我一些关于如何解决这个问题的提示?谢谢!
io_mod:
iomodifier_opt io_mod
|
;
iomodifier_opt:
GREAT WORD {
printf(" Yacc: insert output \"%s\"\n", $2);
Command::_currentCommand._outFile = $2;
}
|
LESS WORD {
printf(" Yacc: insert input \"%s\"\n", $2);
Command::_currentCommand._inputFile = $2;
}
| /* can be empty */
;
编辑:在与我的 TA 交谈后,我了解到我实际上不需要为我的命令只使用 1 个修饰符,而且我实际上可以拥有相同 I/O 重定向的多个副本。