Created
May 19, 2010 21:11
-
-
Save francescoagati/406841 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'v8' | |
require 'johnson' | |
require 'ruby_parser' | |
sexp=Johnson::Parser.parse %{ | |
var sum=function sum (x,y) { | |
return x+y | |
}; | |
sum(1,1); | |
} | |
V8::Context.open do |context| | |
context["sexp"]=Johnson::Parser.parse %{ | |
var sum=function sum (x,y) { | |
return x+y | |
}; | |
sum(1,1); | |
} | |
puts context.eval %{ | |
sexp | |
} | |
end | |
#risultato sexp javascript | |
#[[:var, [[:assign, [:name, "sum"], [:func_expr, "sum", ["x", "y"], [[:return, [:op_add, [:name, "x"], [:name, "y"]]]]]]]], [:function_call, [[:name, "sum"], [:lit, 1], [:lit, 1]]]] | |
puts "-----------------------" | |
p RubyParser.new.parse %{ | |
def sum(x,y) | |
x.length | |
return x + y | |
end | |
sum(1,1) | |
} | |
#risultato sexp ruby | |
#s(:block, s(:defn, :sum, s(:args, :x, :y), s(:scope, s(:block, s(:call, s(:lvar, :x), :length, s(:arglist)), s(:return, s(:call, s(:lvar, :x), :+, s(:arglist, s(:lvar, :y))))))), s(:call, nil, :sum, s(:arglist, s(:lit, 1), s(:lit, 1)))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
and the result:
3
[[:var, [[:assign, [:name, "sum"], [:func_expr, "sum", ["x", "y"], [[:return, [:op_add, [:name, "x"], [:name, "y"]]]]]]]], [:function_call, [[:name, "sum"], [:lit, 1], [:lit, 1]]]]
s(:block, s(:defn, :sum, s(:args, :x, :y), s(:scope, s(:block, s(:call, s(:lvar, :x), :length, s(:arglist)), s(:return, s(:call, s(:lvar, :x), :+, s(:arglist, s(:lvar, :y))))))), s(:call, nil, :sum, s(:arglist, s(:lit, 1), s(:lit, 1))))