Skip to content

Instantly share code, notes, and snippets.

@HackerEarthBlog
Created February 1, 2017 06:04
Show Gist options
  • Save HackerEarthBlog/f0a5a4304326936142da39b0d853f944 to your computer and use it in GitHub Desktop.
Save HackerEarthBlog/f0a5a4304326936142da39b0d853f944 to your computer and use it in GitHub Desktop.
function expression for the list interpreter
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