在lex中如何使yyin指向yacc中具有main函数的文件?

时间:2022-03-23 09:40:42

I am storing the arguments passed to main in yacc in a file. Now I want the lex to read its input from this file rather than the terminal. I know I can point yyin to a file like yyin = fopen("fn","r"); but this works only when main is in lex. When I use this yyin declaration in main in yacc, it shows an error so please suggest something to overcome this problem.

我将传递给yacc中main的参数存储在一个文件中。现在我希望lex从这个文件而不是终端读取它的输入。我知道我可以将yyin指向yyin = fopen(“fn”,“r”)这样的文件;但这只适用于主要是在lex中。当我在yacc的main中使用这个yyin声明时,它显示错误,所以请提出一些建议来克服这个问题。

1 个解决方案

#1


24  

You probably just need to declare

你可能只需要声明

extern FILE * yyin;

If that doesn't solve the problem, please give the error message you got.

如果这不能解决问题,请提供您收到的错误消息。

#1


24  

You probably just need to declare

你可能只需要声明

extern FILE * yyin;

If that doesn't solve the problem, please give the error message you got.

如果这不能解决问题,请提供您收到的错误消息。