2222#include "statistics.h"
2323#include "parse.h"
2424
25+ #include <getopt.h>
26+
2527/* simple version info for --version command line option */
2628static void print_version ()
2729{
@@ -162,13 +164,13 @@ int main(int argc, char *argv[])
162164#if YYDEBUG
163165 yydebug = 1 ;
164166#endif
165-
166- // call setup to create the state needed to parse the file
167- setup ();
168167
169168 // parse the options and make sure we got a filename somewhere
170169 parse_options (argc , argv );
171170
171+ // call the interpreter's setup to create the state needed to parse the file
172+ interpreter_setup ();
173+
172174 // open the file...
173175 yyin = fopen (source_file , "r" );
174176 // and see if it exists
@@ -184,40 +186,8 @@ int main(int argc, char *argv[])
184186 // if we were able to open the file, parse it
185187 yyparse ();
186188
187- // run all the lines together into a single continuous list
188- // by pointing the ->next for each line to the head of the next
189- // non-empty line. that way we don't have to search through the line
190- // array for the next non-null entry during the run loop, we just
191- // keep stepping through the ->next until we fall off the end
192- {
193- // look for the first entry in the lines array with a non-empty statement list
194- int first_line = 0 ;
195- while ((first_line < MAXLINE - 1 ) && (interpreter_state .lines [first_line ] == NULL ))
196- first_line ++ ;
197-
198- // that statement is going to be the head of the list when we're done
199- GList * first_statement = interpreter_state .lines [first_line ];
200-
201- // now find the next non-null line and concat it to the first one, and repeat
202- for (int i = first_line + 1 ; (i < MAXLINE ); i ++ ) {
203- if (interpreter_state .lines [i ])
204- first_statement = g_list_concat (first_statement , interpreter_state .lines [i ]);
205- }
206-
207- // and set the resulting list back into the first line
208- // NOTE: do we need to do this? isn't this already there?
209- interpreter_state .lines [first_line ] = first_statement ;
210- // and keep track of this for posterity
211- interpreter_state .first_line = first_line ;
212-
213- // a program runs from the first line, so...
214- interpreter_state .current_statement = first_statement ; // the first statement
215- interpreter_state .current_data_statement = first_statement ; // the DATA can point anywhere
216- interpreter_state .current_data_element = NULL ; // the element within the DATA is nothing
217- }
218-
219- // the cursor starts in col 0
220- interpreter_state .cursor_column = 0 ;
189+ // prepare the code
190+ interpreter_post_parse ();
221191
222192 // seed the random with the provided number or randomize it
223193 if (random_seed > -1 )
@@ -227,7 +197,7 @@ int main(int argc, char *argv[])
227197
228198 // and go!
229199 if (run_program )
230- run ();
200+ interpreter_run ();
231201
232202 // we're done, print/write desired stats
233203 if (print_stats || write_stats )
0 commit comments