[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Calling two times yyparse reloading yyin
From: |
Ismael Moreno |
Subject: |
Calling two times yyparse reloading yyin |
Date: |
Tue, 29 Nov 2005 10:19:42 +0100 |
Hi all,
I'm including a parser in Bison for a C++ project (a flow chart
interpreter), but it brings me a lot of odd problems.
The translation of a assigment node ( a assigment instruction) first parses
the rvalue and, then, lvalue.
RValue and LValue are strings, so yyin is loaded by fmemopen. The piece of
code is:
//Assigment node translation
void cAssigNode::translate(cVM& vm) throw(std::exception)
{
char* Text;
Text = strdup(RValue.c_str());
FILE* yyin = fmemopen(Text, strlen(Text), "r");
if(yyin == NULL)
throw(cError("Can't open yyin stream"));
yyparse();
sMemReg Instr;
Instr.Func = push_ax;
vm.putMemoryCell(Instr);
fclose(yyin);
delete Text;
Text = strdup(LValue.c_str());
yyin = fmemopen(Text, strlen(Text), "r");
if(yyin == NULL)
throw(cError("Can't open yyin stream"));
IsDefiningVar = true;
MustReturnDir = true;
yyparse();
MustReturnDir = false;
IsDefiningVar = false;
Instr.Func = pop_bx;
vm.putMemoryCell(Instr);
Instr.Op1.setAddress(VM.getMemorySize() + 1);
Instr.Func = mov_op2_bx;
vm.putMemoryCell(Instr);
Instr.Op1.setAddress(VM.getMemorySize());
Instr.Func = mov_op1_ax;
vm.putMemoryCell(Instr);
Instr.Func = mov_mem_dat;
vm.putMemoryCell(Instr);
fclose(yyin);
delete Text;
}
vm is an instance of a virtual machine and Instr a instruction to insert on
it.
The first yyparse call works fine (as far as i know, because i haven't been
able to test the assigment operation), so the problem is in the last call.
yywrap is defined via the linker option -lfl.
Note that I've read previous mails about a simmilar problem, where the
solution was to use yyrestart(yyin). The difference now is that yyin is
cleaned and reloaded, so i think it is not needed to call it.
Thanks in advance, and sorry for my rude english.
- Calling two times yyparse reloading yyin,
Ismael Moreno <=