Sunday, April 5, 2009

Name Directory

I am currently trying to implement a name directory - basically, each expression in JIT is named. It is customary to implement a name(label) array, linked with the expression value, so that whenever a label is referenced, it can be searched within that array, and if found, the resulting expression can be used in the context of the call.
I am basically trying to get this LIR snippet to work -
start
two = int 2
twoPlusTwo = add two, two
three = int 3
threePlusThree = add three, three

ret twoPlusTwo
The current version of the parser will return the output from the latest computation only, since it uses only one variable. What needs to be done is usage of a name directory - whenever an instruction like two = int 2 is seen, or in general,
[a-zA-Z]+" = " are expressions of the assignment form. On seeing this, the parser should create an entry in the directory with this parameter name if it doesn't already exist, and then write the corresponding expression value in the parameter value array. If the value exists, the new value should be overwritten.
Hence, searching must be implemented so as to figure out whether a given value exists or not.
As for the return statement, it must return a variable name. Hence, searching must be employed there as well, to search for the given parameter name, and if found, the desired value is returned via the LIR_ret command, otherwise, an error occurs.
This is the basic outline I will try to implement currently.

1 comment:

  1. Paritosh, the C++ standard template library includes features for directories like your name directory.

    Try this link:

    http://pastebin.mozilla.org/640891

    ReplyDelete