php - How do scripting languages set/modify/read out variables? -


Containing interpreter for language (PHP can be anything up to ruby) is written in C. How are the variables (or more complex data structures not only include name and value), which is defined by the script, which is currently being executed, stored and read?

I, with my poor knowledge of C, will be concluded that it can only be done with an array.

  // variable type definition will be var * here; There are two strings in the   

var type name and values ​​.

Okay. So a script defines, for example: 30 variable now, if any one is to read, then the function getVar (or something similar) must be run through all 30 variables and your Name The name of the requested variable would be imagined that one request with a loop

  • Am I doing it completely wrong? If so, how (modern?) Handle scripting languages ​​variables? How are they stored and read?

  • In languages ​​where the variables are explicitly defined by syntax (PHP: $ myVar ), the interpreter can replace the parsing process with all the numeric values Variable (Am I right?) Is this the case?

hashtable, scope-linked lists, references ... there is a lot in it.

What you are asking is half-concise, and the implementation variable is.

Depending on the implementation:

  1. The identifier can be compiled in the namespaces identified by the memory address, or relative memory address, or bytecocks.
  2. Identifiers can be viewed dynamically in scope on runtime

In the original scripting language, encoutered when the variable name is in the scope structure Such that in a link-list hashtable implementation to see the identifiers in that area.

When any variable is referenced, the runtime code is found in this Hashtable and receives some value (a memory address example of a structure) that is related to the value. Structs can be used to implement the scaler variable:

  enum stype = {INT, STRING, flot, bool}; Straight scaler {ANIM stype type; Generic_blob_t * heap_blob; };  

Or some bad changes to my source source.

Reading some good books "" and "it is a good idea; I would recommend it to any programmer.


Comments

Popular posts from this blog

sql - dynamically varied number of conditions in the 'where' statement using LINQ -

asp.net mvc - Dynamically Generated Ajax.BeginForm -

Debug on symbian -