#!/usr/bin/env ruby require 'optparse' require File.join(File.expand_path(File.dirname(__FILE__)), '/../lib/p-lang') options = OptionParser.new do|opts| opts.banner = "Usage: p-lang [option]" opts.version = "0.2.0" opts.on("-e", "-e 'COMMAND'", "interp one line of script.") do |command| sa = PLang::Parser::SyntaxAnalyser.new(command) vm = PLang::VM::Interpreter.new(sa.parse) vm.execute! end opts.on("-i", "-i FILE", "interp a script file.") do |file| begin program = File.readlines(file).join("") rescue puts "No such file (LoadError)" exit end begin sa = PLang::Parser::SyntaxAnalyser.new program vm = PLang::VM::Interpreter.new(sa.parse) vm.execute! rescue Exception => e puts "#{file}:#{e}" end end end argv = ARGV begin if ARGV.length > 0 if options.parse!(ARGV).length > 0 options.parse!(["-h"]) end else options.parse!(["-h"]) end rescue puts "p-lang: unrecognized option" end