Talk:Pancake Stack

From Esolang
Jump to navigation Jump to search

Does the "Give me a pancake!" command input an ascii character or a numeric value? OriginalOldMan (talk) 23:38, 25 October 2013 (UTC)

Numeric value. I'll just quick add an ASCII value if you want to use it. --JWinslow23 (talk) 00:25, 26 October 2013 (UTC)

Interpreter

Here is my interpreter in Ruby for Pancake Stack:

stack = []
labels = {}
print "#{Dir.pwd} filepath> "
program = File.open(gets.delete("\n"),"r").read.split("\n")
counter = 0
while counter < program.count
toks = program[counter].split(" ")
if toks[0..1].join(" ") == "Put this" and toks[3..5].join(" ") == "pancake on top!" 
stack << toks[2].length
elsif toks.join(" ") == "Eat the pancake on top!"
stack.pop
elsif toks.join(" ") == "Put the top pancakes together!"
if stack.count < 2
puts "Error: 'Put the top pancakes together!' called when there were less than two pancakes in the stack"
else
stack << stack.pop + stack.pop
end
elsif toks.join(" ") == "Give me a pancake!"
stack << gets.delete("\n").to_i
elsif toks.join(" ") == "How about a hotcake?"
stack << gets.delete("\n")[0].ord
elsif toks.join(" ") == "Show me a pancake!"
print stack[stack.count-1].chr
elsif toks.join(" ") == "Take from the top pancakes!"
stack << stack.pop - stack.pop
elsif toks.join(" ") == "Flip the pancakes on top!"
temp1 = stack.pop
temp2 = stack.pop
stack << temp1
stack << temp2
elsif toks.join(" ") == "Put another pancake on top!"
stack << stack[stack.count-1]
elsif toks[0][0] == ?[.ord
labels[toks[0].gsub(/[\[|\]]/,"")] = counter
elsif toks[0..7].join(" ") == "If the pancake isn't tasty, go over to"
(stack[stack.count-1] == 0 ? counter = labels[toks[8].delete('"').delete(".")] : counter=counter)
elsif toks[0..7].join(" ") == "If the pancake is tasty, go over to"
(stack[stack.count-1] != 0 ? counter = labels[toks[8].delete('"').delete(".")] : counter=counter)
elsif toks.join(" ") == "Put syrup on the pancakes!"
stack.count.times {|x| stack[x]+=1}
elsif toks.join(" ") == "Put butter on the pancakes!"
stack[stack.count-1]+=1
elsif toks.join(" ") == "Take off the syrup!"
stack.count.times {|x| stack[x]-=1}
elsif toks.join(" ") == "Take off the butter!"
stack[stack.count-1]-=1
elsif toks.join(" ") == "Eat all of the pancakes!"
exit
end
counter+=1
end

Tell me if you find any errors. OriginalOldMan (talk) 21:01, 26 October 2013 (UTC)

I ran it under the command shell, and for both examples, I entered

C:\Users\Owner\Desktop\Pancake Stack>ruby pancakestack.rb [Whatever the program name is]

However, I got this when I entered it in:

C:/Users/Owner/Desktop/Pancake Stack filepath> pancakestack.rb:4:in 'initialize'
: No such file or directory - [Whatever the first line of code is] (Errno::ENOENT)
        from pancakestack.rb:4:in 'open'
        from pancakestack.rb:4:in '<main>'

How can this be fixed? --JWinslow23 (talk) 22:09, 26 October 2013 (UTC)

Also, it seems you are missing an interpretation for "Eat all of the pancakes!".

Also, the program should automatically end if all stack values are popped.

Ruby seems to do strange things with command line arguments, so instead of passing the program file as an argument, just run the program and then type the filename when the prompt comes up. I will add an interpretation for "Eat all of the pancakes!". How can the program end when all values are popped from the stack? Doesn't the stack start out empty? OriginalOldMan (talk) 22:24, 26 October 2013 (UTC)

OK, have it end only if "Eat all of the pancakes" comes up, and learn my name is JWinslow23, not 32.














Please? --JWinslow23 (talk) 22:42, 26 October 2013 (UTC)

Also, the cat program works fine, but the Hello World program says this:

pancakestack.rb:13:in '+': nil can't be coerced into Fixnum (TypeError)
        from pancakestack.rb:13:in '<main>'

How can THAT be fixed? --JWinslow23 (talk) 22:47, 26 October 2013 (UTC)

The only thing I can think of for that error is that the stack had only one pancake on it when the "Put the top pancakes together!" command was called. I will add an error message when this happens to see if this is the case. Sorry about the 32, it was a typo. OriginalOldMan (talk) 23:05, 26 October 2013 (UTC)

I'll fix that. --65.30.52.254 23:21, 26 October 2013 (UTC)