In the YACC file, you write your own main() function, which calls yyparse() at one point. The function yyparse() is created for you by YACC, and ends up in y.
yyin is a variable of the type FILE* and points to the input file. yyin is defined by LEX automatically. If the programmer assigns an input file to yyin in the auxiliary functions section, then yyin is set to point to that file. Otherwise LEX assigns.
lex and yacc often work well together for developing compilers. As noted, a program uses the lex-generated scanner by repeatedly calling the function yylex() . This name is convenient because a yacc-generated parser calls its lexical analyzer with this name.
those $$ , $1 , $3 are the semantic values for for the symbols and tokens used in the rule in the order that they appear. The semantic value is that one that you get in yylval when the scanner gets a new token. $1 has the semantic value of the first num.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With