B
Bart Vandewoestyne
Hello all,
I am currently trying to get started with the code for Chapter 3
'Parsing' in Appel's 'Modern Compiler Implementation in C'. After
downloading the files and fixing some small bugs in it, the only problem
I'm left with when typing 'make' is the following error:
cc -g -c lex.yy.c
lex.yy.c:20:1: error: initializer element is not constant
lex.yy.c:20:1: error: (near initialization for ‘yyin’)
lex.yy.c:20:1: error: initializer element is not constant
lex.yy.c:20:1: error: (near initialization for ‘yyout’)
make: *** [lex.yy.o] Error 1
The file lex.yy.c is an output file of an old version of lex, and the
error is for the line:
FILE *yyin = {stdin}, *yyout = {stdout};
I would now like to know what is the cleanest way to solve this
compilation error. From the net, I've found that I can simply declare
yyin and yyout:
FILE *yyin, *yyout;
(which works), and then later initialize them in a main(), probably
something like:
int main()
{
yyin = stdin;
yyout = stdout;
}
However, i don't have a main function, so I was wondering where and how
I should initialize yyin and yyout. My educated guess is that this
should happen at the beginning of the yylex() function. So there, I added:
yylex() {
int nstr; extern int yyprevious;
yyin = stdin; yyout = stdout;
... other code...
See also lines 20-21 and 78-79 in
https://github.com/BartVandewoestyn..._Compiler_Implementation_in_C/chap03/lex.yy.c
Is this the correct, cleanest and most portable way to fix the above error?
Thanks,
Bart
I am currently trying to get started with the code for Chapter 3
'Parsing' in Appel's 'Modern Compiler Implementation in C'. After
downloading the files and fixing some small bugs in it, the only problem
I'm left with when typing 'make' is the following error:
cc -g -c lex.yy.c
lex.yy.c:20:1: error: initializer element is not constant
lex.yy.c:20:1: error: (near initialization for ‘yyin’)
lex.yy.c:20:1: error: initializer element is not constant
lex.yy.c:20:1: error: (near initialization for ‘yyout’)
make: *** [lex.yy.o] Error 1
The file lex.yy.c is an output file of an old version of lex, and the
error is for the line:
FILE *yyin = {stdin}, *yyout = {stdout};
I would now like to know what is the cleanest way to solve this
compilation error. From the net, I've found that I can simply declare
yyin and yyout:
FILE *yyin, *yyout;
(which works), and then later initialize them in a main(), probably
something like:
int main()
{
yyin = stdin;
yyout = stdout;
}
However, i don't have a main function, so I was wondering where and how
I should initialize yyin and yyout. My educated guess is that this
should happen at the beginning of the yylex() function. So there, I added:
yylex() {
int nstr; extern int yyprevious;
yyin = stdin; yyout = stdout;
... other code...
See also lines 20-21 and 78-79 in
https://github.com/BartVandewoestyn..._Compiler_Implementation_in_C/chap03/lex.yy.c
Is this the correct, cleanest and most portable way to fix the above error?
Thanks,
Bart