Hi all,
I regularly read the messages here in the group, but I never wrote because of my poor english. Now I'm having some difficulty so I decided to ask for help here... I'm developing a multiplatform old-style adventure game in Hollywood, wich features a small scripting language too. The scripting is needed to manage the status variables during the game action. Briefly I implemented the lexer and now I'm writing the parser that generates the syntax tree to be able to evaluate the expressions, but I can't figure out how to manage the tree data structure.
My difficulty lies in the way Hollywood manages the function's formal parameters, because I can't pass value by reference in a function call... is correct? Values are always passed by value, so I can't keep the pointer of the last processed node.
I.e. see the following code fragment:
Code: Select all
function mscInsertSyntaxTreeNode(root, currentNode, lastOperatorNode, newTok)
local newSTNode = mcsCreateSyntaxTreeNode(newTok)
if (getType(root) = #NIL)
switch(newSTNode.type)
case #MCSTYPE_OPERATOR:
return(newSTNode, newSTNode, newSTNode)
case #MCSTYPE_NUMBER or #MCSTYPE_IDENTIFIER:
return(newSTNode, nil, newSTNode)
endswitch
else
switch(newSTNode.type)
case #MCSTYPE_OPERATOR:
if (getType(lastOperatorNode) = #NIL)
lastOperatorNode = mcsInsertSyntaxTreeChildNode(newSTNode, currentNode)
...
endif
case #MCSTYPE_NUMBER or #MCSTYPE_IDENTIFIER:
lastOperatorNode = mcsInsertSyntaxTreeChildNode(lastOperatorNode, newSTNode)
...
endswitch
return(root, lastOperatorNode, newSTNode)
endif
endfunction
function mcsParser(tokenStream)
local tokCount = listItems(tokenStream)
local root = nil
local currentNode = nil
local lastOperatorNode = nil
local newTok = nil
for local i = 0 to tokCount - 1
newTok = tokenStream[i]
; Il nuovo nodo viene inserito nella struttura sintattica corrente
root, lastOperatorNode, currentNode = mscInsertSyntaxTreeNode(root, currentNode, lastOperatorNode, newTok)
next
return(root)
endfunction
Note: I voluntarily set aside the inverse Polish notation to maintain the ease of writing script expressions.
I hope someone can help me and I apologize for my english!
Thanks!