Created
February 1, 2017 06:04
-
-
Save HackerEarthBlog/f0a5a4304326936142da39b0d853f944 to your computer and use it in GitHub Desktop.
function expression for the list interpreter
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
function expression: | |
token = next_token() | |
if token is one of (-, +, 0-9, .): | |
putback the token | |
val = number() | |
elif token is (: | |
op = operator() | |
exp1 = expression() | |
exp2 = expression() | |
c = next_token() | |
c must be ) | |
val = calc(op, exp1, exp2) | |
else | |
SyntaxError | |
return val | |
function number: | |
n = get_number() | |
return n | |
function operator: | |
op = get_char() | |
if op is one of (+, -, *, /) | |
return op | |
else | |
Unknow Operator |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment