[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
changing the way script files are evaluated
From: |
John W. Eaton |
Subject: |
changing the way script files are evaluated |
Date: |
Tue, 15 Apr 2008 22:42:23 -0400 |
When I started working on modifying the lexer and parser to accept
block comments I realized that some cleanup was probably needed before
block comments could really be handled properly. This work devolved
into modifying the parser and evaluator so that script files are
parsed completely and then executed instead of being parsed and
executed one statement at a time.
The new code is mostly working now, but I noticed a problem after my
last round of changes when I ran make check.
The tests/fntests.m script has the line "clear all" at the top
and later, some function definitions in the script itself.
In the past, this caused no trouble because the lines from the file
were parsed and executed one at a time after this line. So in earlier
versions of Octave, after clearing all variables and functions from
the symbol table, functions in the script were parsed and added to the
symbol table again and everything worked. But now with my latest
changes (not checked in to the public archive yet) the functions from
the script are added to the symbol table when the script is parsed.
Then, when the script is evaluated, the "clear all" statement clears
the functions that were defined when the script was parsed so they are
no longer available when they are used later in the script.
I see a few options:
1. Do nothing; if you clear everything before running a script that
defines and uses functions, you deserve to lose.
2. Same as 1, but warn about clearing functions from a script that
defines them.
3. Instead of inserting the functions defined in a script in the
symbol table when the script is parsed, store a pointer to the
function definition in the parse tree for the script, then insert
it in the symbol table when the script is evaluated (if
necessary). This solution seems a bit complex, but offers a way
to get some increase in efficiency for scripts while still
allowing functions to be defined, and "clear all" to work as
before.
4. Don't allow functions to be defined in scripts (hey, it's
compatible behavior, but I doubt this will be a popular change).
I guess 3 is best? Comments? Other suggestions?
Thanks,
jwe