Re: Rob, no reply? Minor bug found in 3.1 and previous
- Posted by Pete Lomax <petelomax at blueyo?der.co.uk> Jul 07, 2007
- 576 views
Al Getz wrote: > > Al Getz wrote: > > > > > constant x=1 x > > > --error message: > > > x has not been declared > > > > Robert Craig wrote: > > > You've caught the parser and scanner at an awkward moment. In procedure Global_declaration(symtab_index type_ptr, integer is_global):
-- temporarily hide sym so it can't be used in defining itself buckets[SymTab[sym][S_HASHVAL]] = SymTab[sym][S_SAMEHASH] tok_match(EQUALS) StartSourceLine(FALSE) emit_opnd(sym) Expr() -- no new symbols can be defined in here buckets[SymTab[sym][S_HASHVAL]] = sym
Now, and there will be a shed-load of knock-on effects if you do this, comment out the first (and last) lines, gets a more respectable "cannot change the value of a constant". What seems to be happening here is that the "temporary hide" causes a new SC_UNDEFINED entry to be added to symtab, which is putback() and retrieved via next_token(). Probably difficult to better without imposing significant (and unwarranted, imo) overhead. The most obvious and most costly fix is to remove the above "unlink" and insert dozens or more additional checks for such cases throughout the parser. A possibly better fix might be to detect when the last added symtab entry would have been the unlinked one, so remove it and reset the "putback()" token. Good Luck Regards, Pete