Skip to content

Commit

Permalink
[faq] added input method
Browse files Browse the repository at this point in the history
  • Loading branch information
chiakicage committed Mar 27, 2024
1 parent 2f1e3d8 commit 8fcd5a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/appendix/faq.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# FAQ

## 为什么我的 lexer/parser 卡住了

flex/bison 默认从 `stdin` 读入输入, 由于 `\n` 也会视为输入的一部分, 你需要手动输入 `EOF` 结束, 这在 `bash` 上是 `Ctrl+D`.

如果你想从文件里输入的话 (比如 `./compiler test.in`), 这里提供一个供参考的解决方法:

```cpp
extern int yyparse();

extern FILE* yyin;

int main(int argc, char **argv) {
yyin = fopen(argv[1], "r");
yyparse();
return 0;
}
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ nav:
- SysY 语言规范: appendix/sysy-spec.md
- SysY 运行时库: appendix/sysy-runtime.md
- Accipit IR 规范: appendix/accipit-spec.md
- FAQ: appendix/faq.md

plugins:
- search
Expand Down

0 comments on commit 8fcd5a1

Please sign in to comment.