Assuming that the interpreter for the language (can be anything from PHP to Ruby) is written in C. How are the variables (or more complex data structures not only contacting the name and value) that are defined by the script that is currently being executed, stored and read ?
I, with my fairly poor knowledge of C, will end up being able to do this only with an array.
var* variables;
The type varwill contain two lines nameand value.
Good. Thus, a script defines, for example, 30 variables. Now, if you need to read one of the variables, the function getVar(or something similar) should go through all 30 variables and compare them namewith the name of the requested variable. Imagine that with a loop that asks
Am I really wrong? If so, how are (modern?) Scripting languages handling variables? How are they stored and read?
In languages where variables are clearly defined by the syntax (PHP:) $myVar, the interpreter can replace all variables with numerical values during the parsing process. (Am I right with this?) Is this the case?
lamas source
share