I am basically trying to get this LIR snippet to work -
startThe 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,
two = int 2
twoPlusTwo = add two, two
three = int 3
threePlusThree = add three, three
ret twoPlusTwo
[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.
Paritosh, the C++ standard template library includes features for directories like your name directory.
ReplyDeleteTry this link:
http://pastebin.mozilla.org/640891