In this example I use my Babel Bridge parser-generator gem: homepage / github
Here is the 70-line-source-code from the screencast.
We continue to need fresh minds and new approaches to programming. There are many great challenges facing us in improving programmer productivity and supporting programming in our massively parallel age. I hope this screencast wets your appetite to pick up a parser-generator and play around with your own language. Maybe you'll invent the next Ruby, Java or Javascript!
I just realized the linked source code is 78 LOC. It's 70 if you remove the comments... :)
ReplyDeleteNice work! I have an issue when I am trying to run for: if 1<2 then 3 end. I receive a message error that it tells me that I don't have the evaluate method undefined. Could you help me resolving this problem? The code is the same with yours. Thanks!
ReplyDeleterequire "babel_bridge"
class TuringParser , :>=, :==]] do
def evaluate
#res = left.evaluate.send operator, right.evaluate
case operator
when :<, :<=, :>, :>=, :==
(left.evaluate.send operator, right.evaluate) ? 1 : nil
#res ? 1 : nil
else
left.evaluate.send operator, right.evaluate
#res
end
end
end
rule :operand, "(", :statement, ")"
rule :operand, /[-]?[0-9]+/ do
def evaluate
to_s.to_i
end
end
end
BabelBridge::Shell.new(TuringParser.new).start
You have no if statement in your code you pasted but that may be a typo I made a comment about this exact problem my self the solution is statment[0] and statment[1] in the if dec not match[1] and match[3]
DeleteFrom your article, and video students can learn easily. We have the skills to legally and efficiently collect evidence and solve the case. With our Private Investigators Irvine CA, desired assistance remains 100% guaranteed.
ReplyDeleteThe tutorial is so nice. You tried to explain everything. For long distance moving services in Philadelphia PA, get our valuable services.
ReplyDeleteTop Paving Contractor in North Hollywood CA
ReplyDelete