I forgot to mention that i've changed the delete instruction. As Tim said, it's better free, or use brackets at the end of the delete sentence, since i was deleting an array. And strdup is needed, because ::c_str() returns const* char, instead of char*.
On 11/29/05, Ismael Moreno <[EMAIL PROTECTED]> wrote: > > First of all, i've included an "old" version of this piece of code. I > fixed after ask the yyin field, so sorry. > > Well, after using yyrestart and all what you said, now looks like the > problem is in the first yyparse() function. > > I made an diagram with an "assigment" node as a testcase. This diagrams > represents a very easy algorithm which returns 2+2. The assigment node > contanis: > Result <- 2+2 > Where "2+2" is the RValue and "Result" the LValue. It returns an > exception: "basic_string::_S_construct NULL not valid". > I've added debug tasks on the lex rules, so, where a token is identified, > it shows in the console what token is under processing. In RValue, only the > first number token is recognized. > It is really odd, since i've made earlier some parsers with a different > yyin from stdio. > That's the remodeled piece of code: > > *//RValue* > yyin = fmemopen(Text, strlen(Text) , "r"); > *if*(yyin == NULL) > *throw*(cError("you-know-that")); > > yyrestart(yyin); > yyparse(); > sMemReg Instr; > Instr.Func = push_ax; > vm.putMemoryCell(Instr); > > *//LValue (...)* > > > > I won't ask this if i hadn't tried before the parser. With yyin as stdin, > expressions are parsed correctly. > > Again, thank you in advance. > > > > yyparse() (well, yylex() really) can't (and won't) use your > > function-local yyin. > > Note that adjusting the code to use the global yyin won't necessarily > > work; flex will only cleanly switch to the new yyin if it got an EOF > > state on the original one. Using yyrestart(), you to tell flex/bison > > that a new "file" should be processed, even if the current/previous > > one wasn't fully processed (so that flex can clear its internal cache). > > So put a "yyrestart(yyin);" before each yyparse() and things should > > work. > > Depending on your lexer you may want to add a function of your own > > (say, yy_new_file()) to your .l file, that not only calls yyrestart(), > > but also sets the lexer state back to INITIAL (so that a parse error > > inside a state in the first yyparse() does not break the second > > yyparse()). > > You typically want to test yyparse()'s return value too, so that > > you can detect parse errors. > > > > > [snip] > > > delete Text; > > > > Memory allocated by malloc() (even indirectly via strdup()) should be > > freed using free(), not delete. > > > > I'm not sure the strdup() is even needed - I would expect that > > fmemopen(RValue.c_str(), RValue.size (), "r"); > > works just as well. > > > > > _______________________________________________ Help-bison@gnu.org http://lists.gnu.org/mailman/listinfo/help-bison