Skip to content
Browse files

first commit. what an afternoonn

  • Loading branch information...
0 parents commit add31a8b5a615376c90c5bc38fd356908b30a447 @txus committed Sep 11, 2011
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in noscript.gemspec
+gemspec
21 Rakefile
@@ -0,0 +1,21 @@
+# encoding: utf-8
+require 'bundler'
+Bundler::GemHelper.install_tasks
+
+desc "Regenerate Noscript's lexer and parser."
+task :regenerate do
+ has_rex = `which rex`
+ has_racc = `which racc`
+
+ if has_rex && has_racc
+ `rex lib/noscript/parser/noscript.rex`
+ `racc lib/noscript/parser/noscript.racc`
+ else
+ puts "You need both Rexical and Racc to do that. Install them by doing:"
+ puts
+ puts "\t\tgem install rexical"
+ puts "\t\tgem install racc"
+ puts
+ puts "Or just type `bundle install`."
+ end
+end
23 Readme.md
@@ -0,0 +1,23 @@
+# noscript
+
+Noscript is an object-oriented scripting language written in pure Ruby.
+
+It's basically a way for me to learn about language design in a practical way.
+In the future this language will run on the [Rubinius VM](http://rubini.us),
+but for now I prefer to deal as much as possible with implementation detail,
+learn as much as I can, and then go for the kick-ass Rubinius VM :)
+
+Feel free to criticize and give advice, I'm happy to hear it!
+
+## Install
+
+Although for now it's in a **SUPER ALPHA** stage, you can try and run some
+example scripts doing this:
+
+ git clone git://github.com/txus/noscript
+ cd noscript
+ ./bin/noscript examples/hello_world.ns
+
+## Copyright
+
+Copyright (c) 2011 Josep M. Bach. See LICENSE for details.
44 bin/noscript
@@ -0,0 +1,44 @@
+#!/usr/bin/env ruby
+
+begin
+ require 'noscript'
+rescue LoadError
+ require_relative '../lib/noscript'
+end
+
+require 'pp'
+
+parser = Noscript::Parser.new
+
+filename = ARGV.shift
+if filename && code = File.read(filename)
+ code.strip!
+else
+ puts "No input file provided. Bye!"
+ exit(1)
+end
+
+args = ARGV
+
+ast = parser.scan_str(code)
+
+if args.any?{|a| a =~ '--tokens'}
+ puts "-----TOKENS-----"
+ lexer = Noscript::Parser.new
+ lexer.load_file filename
+ while token = rex.next_token
+ p token
+ end
+end
+
+if args.any?{|a| a =~ '--ast'}
+ puts "-----AST-----"
+ pp ast
+end
+
+result = ast.compile(Noscript::Context.generate)
+
+if args.any?{|a| a =~ '--return'}
+ puts "-----RETURN VALUE-----"
+ pp result
+end
22 examples/hello_world.ns
@@ -0,0 +1,22 @@
+myvar = 'hello world'
+johnny = 4000
+
+def foo(johnny=3)
+ 34 + johnny * 3
+end
+
+def bar(johnny=3)
+ (34 + johnny) * 3
+end
+
+print('Negative johnny is', -johnny)
+
+print(foo())
+print(foo(242))
+
+print(bar())
+print(bar(242))
+
+print('Johnny is still', johnny)
+
+print(myvar)
8 lib/noscript.rb
@@ -0,0 +1,8 @@
+require_relative 'noscript/ast'
+require_relative 'noscript/parser'
+
+require_relative 'noscript/context'
+require_relative 'noscript/method'
+
+module Noscript
+end
127 lib/noscript/ast.rb
@@ -0,0 +1,127 @@
+module Noscript
+ module AST
+ class Nodes < Struct.new(:nodes)
+ def compile(context)
+ nodes.map do |node|
+ node.compile(context)
+ end.last
+ end
+ end
+
+ class AssignNode < Struct.new(:lhs, :rhs)
+ def compile(context)
+ context.store_var(lhs, rhs)
+ rhs
+ end
+ end
+
+ class Identifier < Struct.new(:name)
+ def compile(context)
+ context.lookup_var(name) || raise("Undefined local variable: #{name}")
+ end
+ def to_s
+ name
+ end
+ end
+
+ class DefaultParameter < Struct.new(:name, :value)
+ def compile(context)
+ value
+ end
+ def to_s
+ name
+ end
+ end
+
+ class String < Struct.new(:val)
+ def compile(context)
+ val.to_s
+ end
+ def to_s
+ "'#{val.to_s}'"
+ end
+ end
+
+ class DefMethod < Struct.new(:name, :params, :body)
+ def compile(context)
+ context.store_method(name, params, body)
+ end
+ end
+
+ class MethodCall < Struct.new(:name, :args)
+ def compile(context)
+ if method = context.lookup_method(name)
+ method.call(context, *args)
+ else
+ raise "Undefined procedure: #{name}"
+ end
+ end
+ end
+
+ ## ARITHMETIC
+
+ class Digit < Struct.new(:val)
+ def -@
+ Digit.new(-to_i)
+ end
+
+ def +(num)
+ Digit.new num.to_i + to_i
+ end
+
+ def -(num)
+ Digit.new to_i - num.to_i
+ end
+
+ def *(num)
+ Digit.new to_i * num.to_i
+ end
+
+ def /(num)
+ Digit.new to_i / num.to_i
+ end
+
+ def compile(context)
+ self
+ end
+
+ def to_s
+ val.to_s
+ end
+
+ def to_i
+ val.to_i
+ end
+ end
+
+ class AddNode < Struct.new(:lhs, :rhs)
+ def compile(context)
+ lhs.compile(context) + rhs.compile(context)
+ end
+ end
+
+ class SubtractNode < Struct.new(:lhs, :rhs)
+ def compile(context)
+ lhs.compile(context) - rhs.compile(context)
+ end
+ end
+
+ class MultiplicationNode < Struct.new(:lhs, :rhs)
+ def compile(context)
+ lhs.compile(context) * rhs.compile(context)
+ end
+ end
+
+ class DivisionNode < Struct.new(:lhs, :rhs)
+ def compile(context)
+ lhs.compile(context) / rhs.compile(context)
+ end
+ end
+
+ class UnaryMinus < Struct.new(:val)
+ def compile(context)
+ -(val.compile(context))
+ end
+ end
+ end
+end
47 lib/noscript/context.rb
@@ -0,0 +1,47 @@
+module Noscript
+ class Context
+ def self.generate
+ ctx = new
+
+ # Define native ruby methods
+ ctx.store_ruby_method('print') do |context, *args|
+ puts *(args.map! {|a| a.compile(context).to_s })
+ end
+
+ ctx
+ end
+
+ attr_accessor :lvars, :functions
+
+ def initialize(parent_context = nil)
+ @parent = parent_context
+ @lvars = {}
+ @functions = {}
+ end
+
+ def lookup_var(symbol)
+ result = @lvars[symbol.to_s] ||
+ (@parent.lookup_var(symbol.to_s) if @parent)
+ return result || raise("Undefined local variable: #{symbol}")
+ end
+
+ def store_var(symbol, value)
+ @lvars[symbol.to_s] = value
+ end
+
+ def lookup_method(symbol)
+ result = @functions[symbol.to_s] ||
+ (@parent.lookup_method(symbol.to_s) if @parent)
+ return result || raise("Undefined procedure: #{symbol}")
+ end
+
+ def store_method(symbol, params, body)
+ @functions[symbol.to_s] = Method.new(params, body)
+ end
+
+ def store_ruby_method(symbol, &body)
+ raise "Body must be a ruby proc" unless body.is_a?(Proc)
+ @functions[symbol.to_s] = body
+ end
+ end
+end
22 lib/noscript/method.rb
@@ -0,0 +1,22 @@
+module Noscript
+ class Method
+ def initialize(params, body)
+ @params = params
+ @body = body
+ end
+
+ def call(context, *args)
+ ctx = Context.new(context)
+ @params.each_with_index do |param, idx|
+ if passed_value = args[idx]
+ ctx.store_var(param.name, passed_value.compile(ctx))
+ elsif param.is_a?(AST::DefaultParameter)
+ ctx.store_var(param.name, param.value)
+ else
+ raise "This method expected #{@params.size} arguments, not #{args.size}"
+ end
+ end
+ @body.compile(ctx)
+ end
+ end
+end
1 lib/noscript/parser.rb
@@ -0,0 +1 @@
+require_relative 'parser/noscript.tab'
85 lib/noscript/parser/noscript.racc
@@ -0,0 +1,85 @@
+#
+# Noscript grammar.
+#
+
+class Noscript::Parser
+
+prechigh
+ nonassoc UMINUS
+ left '*' '/'
+ left '+' '-'
+preclow
+
+rule
+ target : statements { result = AST::Nodes.new(val[0]) }
+ | /* none */ { 0 }
+
+ assignment : IDENTIFIER ASSIGN statement { result = AST::AssignNode.new(val[0], val[2]) }
+
+ method_definition : DEF IDENTIFIER LPAREN parameter_list RPAREN end_of_statement statements END { result = AST::DefMethod.new(val[1], val[3], AST::Nodes.new(val[6])) }
+
+ identifier : IDENTIFIER { result = AST::Identifier.new(val[0]) }
+
+ digit : DIGIT { result = AST::Digit.new(val[0]) }
+ string : STRING { result = AST::String.new(val[0]) }
+
+ literal : digit
+ | string
+ | operation
+
+ argument : identifier
+ | literal
+ | method_call
+
+ argument_list : { result = [] }
+ | argument { result = [val[0]] }
+ | argument_list COMMA argument { result.push(val[2]) }
+
+ parameter : identifier ASSIGN argument { result = AST::DefaultParameter.new(val[0], val[2])}
+ | identifier
+
+ parameter_list : { result = [] }
+ | parameter { result = [val[0]] }
+ | parameter_list COMMA parameter { result.push(val[2]) }
+
+ statement : assignment
+ | operation
+ | method_call
+ | digit
+ | string
+ | method_definition
+ | statement end_of_statement
+
+ op_member : digit
+ | identifier
+ | method_call
+ | operation
+
+ operation : op_member '+' op_member { result = AST::AddNode.new(val[0], val[2]) }
+ | op_member '-' op_member { result = AST::SubtractNode.new(val[0], val[2]) }
+ | op_member '*' op_member { result = AST::MultiplicationNode.new(val[0], val[2]) }
+ | op_member '/' op_member { result = AST::DivisionNode.new(val[0], val[2]) }
+ | LPAREN op_member RPAREN { result = val[1] }
+ | '-' op_member =UMINUS { result = AST::UnaryMinus.new(val[1]) }
+
+ statements : { result = [] }
+ | statement { result = [val[0]] }
+ | statements statement { result.push(val[1]) }
+
+ end_of_statement : SEMICOLON | NEWLINE
+
+ method_call : IDENTIFIER LPAREN argument_list RPAREN
+ {
+ result = AST::MethodCall.new(val[0], val[2])
+ }
+
+
+---- header ----
+#
+# generated by racc
+#
+require_relative 'noscript.rex'
+
+---- inner ----
+
+---- footer ----
24 lib/noscript/parser/noscript.rex
@@ -0,0 +1,24 @@
+#
+# noscript.rex
+#
+# Noscript Lexer
+#
+module Noscript
+class Parser
+rule
+ [\n]+[\s]* { [:NEWLINE, text] }
+ \s
+ \d+ { [:DIGIT, text.to_i] }
+ = { [:ASSIGN, text] }
+ , { [:COMMA, text] }
+ ; { [:SEMICOLON, text] }
+ '[^']*' { [:STRING, text[1..-2]] }
+ def { [:DEF, text] }
+ \( { [:LPAREN, text] }
+ \) { [:RPAREN, text] }
+ end { [:END, text] }
+
+ \w+ { [:IDENTIFIER, text] }
+ . { [text, text] }
+end
+end
117 lib/noscript/parser/noscript.rex.rb
@@ -0,0 +1,117 @@
+#--
+# DO NOT MODIFY!!!!
+# This file is automatically generated by rex 1.0.5
+# from lexical definition file "lib/noscript/parser/noscript.rex".
+#++
+
+require 'racc/parser'
+#
+# noscript.rex
+#
+# Noscript Lexer
+#
+module Noscript
+class Parser < Racc::Parser
+ require 'strscan'
+
+ class ScanError < StandardError ; end
+
+ attr_reader :lineno
+ attr_reader :filename
+ attr_accessor :state
+
+ def scan_setup(str)
+ @ss = StringScanner.new(str)
+ @lineno = 1
+ @state = nil
+ end
+
+ def action
+ yield
+ end
+
+ def scan_str(str)
+ scan_setup(str)
+ do_parse
+ end
+ alias :scan :scan_str
+
+ def load_file( filename )
+ @filename = filename
+ open(filename, "r") do |f|
+ scan_setup(f.read)
+ end
+ end
+
+ def scan_file( filename )
+ load_file(filename)
+ do_parse
+ end
+
+
+ def next_token
+ return if @ss.eos?
+
+ # skips empty actions
+ until token = _next_token or @ss.eos?; end
+ token
+ end
+
+ def _next_token
+ text = @ss.peek(1)
+ @lineno += 1 if text == "\n"
+ token = case @state
+ when nil
+ case
+ when (text = @ss.scan(/[\n]+[\s]*/))
+ action { [:NEWLINE, text] }
+
+ when (text = @ss.scan(/\s/))
+ ;
+
+ when (text = @ss.scan(/\d+/))
+ action { [:DIGIT, text.to_i] }
+
+ when (text = @ss.scan(/=/))
+ action { [:ASSIGN, text] }
+
+ when (text = @ss.scan(/,/))
+ action { [:COMMA, text] }
+
+ when (text = @ss.scan(/;/))
+ action { [:SEMICOLON, text] }
+
+ when (text = @ss.scan(/'[^']*'/))
+ action { [:STRING, text[1..-2]] }
+
+ when (text = @ss.scan(/def/))
+ action { [:DEF, text] }
+
+ when (text = @ss.scan(/\(/))
+ action { [:LPAREN, text] }
+
+ when (text = @ss.scan(/\)/))
+ action { [:RPAREN, text] }
+
+ when (text = @ss.scan(/end/))
+ action { [:END, text] }
+
+ when (text = @ss.scan(/\w+/))
+ action { [:IDENTIFIER, text] }
+
+ when (text = @ss.scan(/./))
+ action { [text, text] }
+
+ else
+ text = @ss.string[@ss.pos .. -1]
+ raise ScanError, "can not match: '" + text + "'"
+ end # if
+
+ else
+ raise ScanError, "undefined state: '" + state.to_s + "'"
+ end # case state
+ token
+ end # def _next_token
+
+end # class
+end
451 lib/noscript/parser/noscript.tab.rb
@@ -0,0 +1,451 @@
+#
+# DO NOT MODIFY!!!!
+# This file is automatically generated by Racc 1.4.6
+# from Racc grammer file "".
+#
+
+require 'racc/parser.rb'
+
+#
+# generated by racc
+#
+require_relative 'noscript.rex'
+
+module Noscript
+ class Parser < Racc::Parser
+
+module_eval(<<'...end noscript.racc/module_eval...', 'noscript.racc', 84)
+
+...end noscript.racc/module_eval...
+##### State transition tables begin ###
+
+racc_action_table = [
+ 17, 3, -11, 4, 16, 22, -11, 5, 6, 17,
+ 3, -10, 4, 16, 36, -10, 5, 6, 17, 3,
+ 61, 4, 16, 17, 30, 5, 6, 16, 17, 30,
+ 5, 6, 16, 24, 25, 5, 6, 28, 29, 26,
+ 27, 24, 25, 17, 3, 51, 4, 16, 17, 30,
+ 5, 6, 16, 24, 25, 5, 6, 17, 3, 55,
+ 4, 16, 55, 66, 5, 6, 17, 30, 17, 30,
+ 16, 46, 16, 5, 18, 5, 17, 30, 17, 30,
+ 16, 21, 16, 5, nil, 5, 17, 30, 17, 30,
+ 16, nil, 16, 5, 53, 5, 59, -13, 52, -8,
+ 60, -13, nil, -8, 28, 29, 26, 27, -32, -32,
+ -32, 20, nil, 21, -31, -31, -31, -29, -29, -29,
+ 24, 25, 28, 29, 28, 29 ]
+
+racc_action_check = [
+ 0, 0, 41, 0, 0, 4, 41, 0, 0, 62,
+ 62, 40, 62, 62, 18, 40, 62, 62, 2, 2,
+ 56, 2, 2, 61, 61, 2, 2, 61, 52, 52,
+ 61, 61, 52, 37, 37, 52, 52, 34, 34, 34,
+ 34, 13, 13, 20, 20, 34, 20, 20, 21, 21,
+ 20, 20, 21, 19, 19, 21, 21, 65, 65, 46,
+ 65, 65, 60, 65, 65, 65, 29, 29, 16, 16,
+ 29, 22, 16, 29, 1, 16, 17, 17, 27, 27,
+ 17, 30, 27, 17, nil, 27, 26, 26, 28, 28,
+ 26, nil, 28, 26, 45, 28, 54, 43, 45, 38,
+ 54, 43, nil, 38, 15, 15, 15, 15, 8, 8,
+ 8, 3, nil, 3, 9, 9, 9, 10, 10, 10,
+ 59, 59, 48, 48, 47, 47 ]
+
+racc_action_pointer = [
+ -6, 74, 12, 103, -2, nil, nil, nil, 105, 111,
+ 114, nil, nil, 25, nil, 101, 62, 70, 14, 37,
+ 37, 42, 61, nil, nil, nil, 80, 72, 82, 60,
+ 71, nil, nil, nil, 34, nil, nil, 17, 88, nil,
+ 0, -9, nil, 86, nil, 83, 52, 121, 119, nil,
+ nil, nil, 22, nil, 85, nil, 12, nil, nil, 104,
+ 55, 17, 3, nil, nil, 51, nil ]
+
+racc_action_default = [
+ -2, -45, -1, -5, -45, -6, -7, -22, -23, -24,
+ -25, -26, -27, -40, -30, -45, -45, -45, -45, -41,
+ -45, -14, -45, -28, -42, -43, -45, -45, -45, -45,
+ -5, -29, -31, -32, -45, -38, 67, -3, -29, -9,
+ -32, -30, -12, -31, -15, -45, -19, -33, -34, -35,
+ -36, -37, -45, -44, -45, -5, -18, -20, -16, -45,
+ -45, -45, -39, -21, -17, -45, -4 ]
+
+racc_goto_table = [
+ 8, 19, 8, 41, 44, 10, 2, 10, 39, 57,
+ 62, 9, 45, 9, 54, 1, nil, nil, nil, 37,
+ 8, 40, nil, 63, nil, 10, 38, nil, 56, nil,
+ nil, 9, 43, nil, 41, 58, nil, nil, nil, 39,
+ nil, nil, 56, 41, 64, nil, nil, nil, 39, nil,
+ nil, nil, 40, nil, nil, nil, nil, 38, nil, nil,
+ nil, 40, 8, 43, 19, 8, 38, 10, 65, nil,
+ 10, nil, 43, 9, 34, 35, 9, nil, nil, nil,
+ nil, nil, nil, nil, 47, 48, 49, 50 ]
+
+racc_goto_check = [
+ 12, 4, 12, 8, 13, 9, 2, 9, 10, 16,
+ 7, 14, 15, 14, 6, 1, nil, nil, nil, 4,
+ 12, 12, nil, 16, nil, 9, 9, nil, 8, nil,
+ nil, 14, 14, nil, 8, 13, nil, nil, nil, 10,
+ nil, nil, 8, 8, 13, nil, nil, nil, 10, nil,
+ nil, nil, 12, nil, nil, nil, nil, 9, nil, nil,
+ nil, 12, 12, 14, 4, 12, 9, 9, 2, nil,
+ 9, nil, 14, 14, 17, 17, 14, nil, nil, nil,
+ nil, nil, nil, nil, 17, 17, 17, 17 ]
+
+racc_goto_pointer = [
+ nil, 15, 6, nil, -1, nil, -32, -49, -18, 5,
+ -13, nil, 0, -17, 11, -9, -37, 58 ]
+
+racc_goto_default = [
+ nil, nil, nil, 7, 13, 12, nil, 23, 14, 31,
+ 11, 42, 33, nil, 32, nil, nil, 15 ]
+
+racc_reduce_table = [
+ 0, 0, :racc_error,
+ 1, 19, :_reduce_1,
+ 0, 19, :_reduce_2,
+ 3, 21, :_reduce_3,
+ 8, 23, :_reduce_4,
+ 1, 26, :_reduce_5,
+ 1, 27, :_reduce_6,
+ 1, 28, :_reduce_7,
+ 1, 29, :_reduce_none,
+ 1, 29, :_reduce_none,
+ 1, 29, :_reduce_none,
+ 1, 31, :_reduce_none,
+ 1, 31, :_reduce_none,
+ 1, 31, :_reduce_none,
+ 0, 33, :_reduce_14,
+ 1, 33, :_reduce_15,
+ 3, 33, :_reduce_16,
+ 3, 34, :_reduce_17,
+ 1, 34, :_reduce_none,
+ 0, 24, :_reduce_19,
+ 1, 24, :_reduce_20,
+ 3, 24, :_reduce_21,
+ 1, 22, :_reduce_none,
+ 1, 22, :_reduce_none,
+ 1, 22, :_reduce_none,
+ 1, 22, :_reduce_none,
+ 1, 22, :_reduce_none,
+ 1, 22, :_reduce_none,
+ 2, 22, :_reduce_none,
+ 1, 35, :_reduce_none,
+ 1, 35, :_reduce_none,
+ 1, 35, :_reduce_none,
+ 1, 35, :_reduce_none,
+ 3, 30, :_reduce_33,
+ 3, 30, :_reduce_34,
+ 3, 30, :_reduce_35,
+ 3, 30, :_reduce_36,
+ 3, 30, :_reduce_37,
+ 2, 30, :_reduce_38,
+ 0, 20, :_reduce_39,
+ 1, 20, :_reduce_40,
+ 2, 20, :_reduce_41,
+ 1, 25, :_reduce_none,
+ 1, 25, :_reduce_none,
+ 4, 32, :_reduce_44 ]
+
+racc_reduce_n = 45
+
+racc_shift_n = 67
+
+racc_token_table = {
+ false => 0,
+ :error => 1,
+ :UMINUS => 2,
+ "*" => 3,
+ "/" => 4,
+ "+" => 5,
+ "-" => 6,
+ :IDENTIFIER => 7,
+ :ASSIGN => 8,
+ :DEF => 9,
+ :LPAREN => 10,
+ :RPAREN => 11,
+ :END => 12,
+ :DIGIT => 13,
+ :STRING => 14,
+ :COMMA => 15,
+ :SEMICOLON => 16,
+ :NEWLINE => 17 }
+
+racc_nt_base = 18
+
+racc_use_result_var = true
+
+Racc_arg = [
+ racc_action_table,
+ racc_action_check,
+ racc_action_default,
+ racc_action_pointer,
+ racc_goto_table,
+ racc_goto_check,
+ racc_goto_default,
+ racc_goto_pointer,
+ racc_nt_base,
+ racc_reduce_table,
+ racc_token_table,
+ racc_shift_n,
+ racc_reduce_n,
+ racc_use_result_var ]
+
+Racc_token_to_s_table = [
+ "$end",
+ "error",
+ "UMINUS",
+ "\"*\"",
+ "\"/\"",
+ "\"+\"",
+ "\"-\"",
+ "IDENTIFIER",
+ "ASSIGN",
+ "DEF",
+ "LPAREN",
+ "RPAREN",
+ "END",
+ "DIGIT",
+ "STRING",
+ "COMMA",
+ "SEMICOLON",
+ "NEWLINE",
+ "$start",
+ "target",
+ "statements",
+ "assignment",
+ "statement",
+ "method_definition",
+ "parameter_list",
+ "end_of_statement",
+ "identifier",
+ "digit",
+ "string",
+ "literal",
+ "operation",
+ "argument",
+ "method_call",
+ "argument_list",
+ "parameter",
+ "op_member" ]
+
+Racc_debug_parser = false
+
+##### State transition tables end #####
+
+# reduce 0 omitted
+
+module_eval(<<'.,.,', 'noscript.racc', 13)
+ def _reduce_1(val, _values, result)
+ result = AST::Nodes.new(val[0])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 14)
+ def _reduce_2(val, _values, result)
+ 0
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 16)
+ def _reduce_3(val, _values, result)
+ result = AST::AssignNode.new(val[0], val[2])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 18)
+ def _reduce_4(val, _values, result)
+ result = AST::DefMethod.new(val[1], val[3], AST::Nodes.new(val[6]))
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 20)
+ def _reduce_5(val, _values, result)
+ result = AST::Identifier.new(val[0])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 22)
+ def _reduce_6(val, _values, result)
+ result = AST::Digit.new(val[0])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 23)
+ def _reduce_7(val, _values, result)
+ result = AST::String.new(val[0])
+ result
+ end
+.,.,
+
+# reduce 8 omitted
+
+# reduce 9 omitted
+
+# reduce 10 omitted
+
+# reduce 11 omitted
+
+# reduce 12 omitted
+
+# reduce 13 omitted
+
+module_eval(<<'.,.,', 'noscript.racc', 33)
+ def _reduce_14(val, _values, result)
+ result = []
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 34)
+ def _reduce_15(val, _values, result)
+ result = [val[0]]
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 35)
+ def _reduce_16(val, _values, result)
+ result.push(val[2])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 37)
+ def _reduce_17(val, _values, result)
+ result = AST::DefaultParameter.new(val[0], val[2])
+ result
+ end
+.,.,
+
+# reduce 18 omitted
+
+module_eval(<<'.,.,', 'noscript.racc', 40)
+ def _reduce_19(val, _values, result)
+ result = []
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 41)
+ def _reduce_20(val, _values, result)
+ result = [val[0]]
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 42)
+ def _reduce_21(val, _values, result)
+ result.push(val[2])
+ result
+ end
+.,.,
+
+# reduce 22 omitted
+
+# reduce 23 omitted
+
+# reduce 24 omitted
+
+# reduce 25 omitted
+
+# reduce 26 omitted
+
+# reduce 27 omitted
+
+# reduce 28 omitted
+
+# reduce 29 omitted
+
+# reduce 30 omitted
+
+# reduce 31 omitted
+
+# reduce 32 omitted
+
+module_eval(<<'.,.,', 'noscript.racc', 57)
+ def _reduce_33(val, _values, result)
+ result = AST::AddNode.new(val[0], val[2])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 58)
+ def _reduce_34(val, _values, result)
+ result = AST::SubtractNode.new(val[0], val[2])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 59)
+ def _reduce_35(val, _values, result)
+ result = AST::MultiplicationNode.new(val[0], val[2])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 60)
+ def _reduce_36(val, _values, result)
+ result = AST::DivisionNode.new(val[0], val[2])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 61)
+ def _reduce_37(val, _values, result)
+ result = val[1]
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 62)
+ def _reduce_38(val, _values, result)
+ result = AST::UnaryMinus.new(val[1])
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 64)
+ def _reduce_39(val, _values, result)
+ result = []
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 65)
+ def _reduce_40(val, _values, result)
+ result = [val[0]]
+ result
+ end
+.,.,
+
+module_eval(<<'.,.,', 'noscript.racc', 66)
+ def _reduce_41(val, _values, result)
+ result.push(val[1])
+ result
+ end
+.,.,
+
+# reduce 42 omitted
+
+# reduce 43 omitted
+
+module_eval(<<'.,.,', 'noscript.racc', 72)
+ def _reduce_44(val, _values, result)
+ result = AST::MethodCall.new(val[0], val[2])
+
+ result
+ end
+.,.,
+
+def _reduce_none(val, _values, result)
+ val[0]
+end
+
+ end # class Parser
+ end # module Noscript
+
+
3 lib/noscript/version.rb
@@ -0,0 +1,3 @@
+module Noscript
+ VERSION = "0.0.1"
+end
24 noscript.gemspec
@@ -0,0 +1,24 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "noscript/version"
+
+Gem::Specification.new do |s|
+ s.name = "noscript"
+ s.version = Noscript::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Josep M. Bach"]
+ s.email = ["josep.m.bach@gmail.com"]
+ s.homepage = "http://github.com/txus/noscript"
+ s.summary = %q{An object-oriented scripting language written in pure Ruby.}
+ s.description = %q{An object-oriented scripting language written in pure Ruby.}
+
+ s.rubyforge_project = "noscript"
+
+ s.add_development_dependency 'rexical'
+ s.add_development_dependency 'racc'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end

0 comments on commit add31a8

Please sign in to comment.
Something went wrong with that request. Please try again.