Re: Forward Definitions
- Posted by "Carl R. White" <C.R.White at SCM.BRAD.AC.UK> Feb 26, 1999
- 436 views
I've been trying to avoid the language arguments 'cause I always come out looking bad, but I've got to put in my tuppence here... It seems that everybody wants routine_id() to work like open() already does. When the interpreter starts it creates an inbuilt table/sequence of valid file handles, StdIn, StdOut and StdErr. Every time open() is called, another entry is added to the table. On close() the entry is removed, but this wouldn't apply to routine_id(). AFAICT, all Rob needs to do is add a table for the built-in functions. e.g. (Using Euphoria pseudocode to represent what the Interpreter would do, rather than C :) ) : -- Preparsing declarations global sequence routine_id_table = { PUTS_TOKEN, LENGTH_TOKEN, SEQUENCE_TOKEN, ROUTINE_ID_TOKEN, -- insane concept! etc_etc_TOKENS } -- Setup for parsing/running Euphoria program while parsing_program do -- Do keyword stuff if find(tokenize(keyword), {FUNCTION_TOKEN, PROCEDURE_TOKEN, TYPE_TOKEN}) name = get_function_name() -- Check here to see if it's already defined. Do error stuff. routine_id_table = append(routine_id_table, name) -- granted this means that the first half of the r_i_t list -- is integers, while the second half is strings... end if -- Do builtin function stuff if tokenize(keyword) = ROUTINE_ID_TOKEN then name = get_function_parameters(1) name = name[1] t = tokenize(name) if t then t = find(t, routine_id_table) else t = find(name, routine_id_table) end if t = t - 1 -- this mimics the behaviour of the current routine_id() -- and gives a value in the range -1..maxint -- place t in the variable specified before the function call -- or whatever... end if -- Whatever else needs to be done program_counter = program_counter + whatever if program_counter > length(program) then parsing_program = FALSE end if end while -- Finish up execution/parsing I admit I've probably taken a rather naive view of how the interpreter does things, but to me, this seems to work. It wouldn't even break code, because it still only needs one pass, IMHO it remains within the Euphorian idiom, and it adds the feature that everyone wants. Remove the "t = t - 1" line, and some more people are happy, but not necessarily Rob... ;) Comments? (/me detects: "You're mad!" etc.) Carl -- Carl R White -- Final Year Computer Science at the University of Bradford E-mail........: cyrek- at -bigfoot.com -- Remove hyphens. Ta :) URL...........: http://www.bigfoot.com/~cyrek/ Uncrackable...: "19.6A.23.38.52.73.45 25.31.1C 3C.53.44.39.58"