2013-08-01から1ヶ月間の記事一覧
昨日のエントリの続き。サブクラスを定義する。 calc.tt grammar Arithmetic rule additive multitive r:( op:[+-] multitive )* <Additive> end rule multitive primary r:( op:[*/%] primary )* <Multitive> end rule primary '(' additive ')' <Parenthesized> / number end rule number '-'? </parenthesized></multitive></additive>…
http://treetop.rubyforge.org/index.html https://github.com/nathansobo/treetop calc.tt grammar Arithmetic rule additive multitive r:( op:[+-] multitive )* { def to_i r.elements.reduce(multitive.to_i) do |s, e| s.send(e.op.text_value, e.mult…