1
Please write an interpreter that understands the commands input and output. Output shall do the same as echo, print or cout in real-world languages. Input shall do the same as read, input or cin: it shall return the string entered by the user. Your interpreter shall be able to execute
output("Hello "+input("What is your name ? "))
Execution will then look like:
What is your name ? Thorsten
Hello Thorsten
Note that in order to execute the outer command (output) the execution of the nested (inner) command (input) is needed. input returns Thorsten in this case and output prints it. Your take how you deal with parentheses and operators like +. Please make your interpreter extendable so do not scan for "input" and "output" as keywords.
Right now this problem is rather underspecified. input() doesn't just read input, it apparently also does output as well. And it looks like this interpreter also needs to understand + as a concatenation operator. I'm assuming multiple concatenations can be chained together, left-associatively. Can parentheses be used to override that? Does the interpreter need to understand a single top-level command or are multiple commands permitted? – breadbox – 2014-01-05T09:23:53.620
input only inputs and returns a string. output outputs this string. And yes you can allow multiple concatenators and multiple top-level commands. Thanks, will edit my original text. – Thorsten Staerk – 2014-01-05T09:44:58.710
You should give a primary winning criterion and add a tag. Also the definition of the requirements seems to be very vague. If you are unsure about how to specify a puzzle or want to discuss any details there is a questions sandbox available which you should use before posting here.
– Howard – 2014-01-05T12:00:11.503The last two sentences in particular need a much clearer explanation. – Peter Taylor – 2014-01-05T16:25:25.163
This puzzle needs a grammar to answer questions such as: is
input("What is your " + "name? ")
valid? – Wayne Conrad – 2014-01-05T17:38:20.760