Top Level Namespace
Defined Under Namespace
Classes: Scratch, ScratchLexer, String
Constant Summary collapse
- PrintingWords =
{ "PRINT" => Proc.new do |terp| raise "Not enough items on the stack" if terp.stack.length < 1 tos = terp.stack.pop puts tos end, "PSTACK" => Proc.new do |terp| puts terp.stack end }
- MathWords =
{ "+" => Proc.new do |terp| raise "Not enough items on the stack" if terp.stack.length < 2 tos = terp.stack.pop tos2 = terp.stack.pop terp.stack.push tos+tos2 end, "-" => Proc.new do |terp| raise "Not enough items on the stack" if terp.stack.length < 2 tos = terp.stack.pop tos2 = terp.stack.pop terp.stack.push tos-tos2 end, "*" => Proc.new do |terp| raise "Not enough items on the stack" if terp.stack.length < 2 tos = terp.stack.pop tos2 = terp.stack.pop terp.stack.push tos*tos2 end, "/" => Proc.new do |terp| raise "Not enough items on the stack" if terp.stack.length < 2 tos = terp.stack.pop tos2 = terp.stack.pop terp.stack.push tos/tos2 end, "SQRT" => Proc.new do |terp| raise "Not enough items on the stack" if terp.stack.length < 1 tos = terp.stack.pop terp.stack.push Math.sqrt(tos) end }