Created
April 27, 2010 18:05
-
-
Save natebenes/381069 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Recursive Function Construct_Tree(expression) result(return_tree) | |
stack, intent(inout) :: expression | |
treenode :: left_exp, right_exp, return_tree | |
character :: symbol, op_symbol, closeparen | |
! some better pseudocode | |
symbol = pop(expression) | |
IF symbol == "(" | |
left_exp = construct_tree(expression) | |
op_symbol = pop(expression) | |
if op_symbol != operator | |
print error and exit | |
end if | |
right_exp = construct_tree(expression) | |
closeparen = pop(expression) | |
if closeparen != ")" then | |
print error and exit | |
end if | |
RL(return_tree) = right_exp | |
LL(return_tree) = left_exp | |
INFO(return_tree) = op_symbol | |
ElSE IF symbol == a number | |
RL(return_tree) = null | |
LL(return_tree) = null | |
INFO(return_tree) = symbol | |
ELSE | |
print error and exit (expected '(' or number) | |
ENDIF | |
END FUNCTION Construct_Tree | |
! Note: this pseudo-code is NOT mine | |
! @author: Kiwi | |
! @url: http://kiwi.archuser.com/about-me |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment