Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit 8d14a1804426947b8abf758db69ae6b9d71014a9 @meh committed Dec 11, 2011
@@ -0,0 +1,4 @@
+**PREMISE, THIS IS A TOY, I DON'T KNOW ANYTHING ABOUT LISP, THIS IS JUST A TEST TO WRITE A COMPILER AND USING ORGASM AS BACKEND**
+
+ciccio - it's not C, it's not LISP, it's shit.
+==============================================
@@ -0,0 +1,22 @@
+Kernel.load 'lib/ciccio/version.rb'
+
+Gem::Specification.new {|s|
+ s.name = 'ciccio'
+ s.version = Ciccio.version
+ s.author = 'meh.'
+ s.email = 'meh@paranoici.org'
+ s.homepage = 'http://github.com/meh/ciccio'
+ s.platform = Gem::Platform::RUBY
+ s.summary = 'A toy "LISP" with ABI compatibility with C'
+
+ s.files = `git ls-files`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.require_paths = ['lib']
+
+ s.add_dependency 'parslet'
+ s.add_dependency 'orgasm'
+
+ s.add_development_dependency 'rake'
+ s.add_development_dependency 'rspec'
+}
@@ -0,0 +1,12 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+require 'ciccio/version'
+require 'ciccio/ciccio'
@@ -0,0 +1,18 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+require 'ciccio/parser'
+require 'ciccio/transform'
+
+module Ciccio
+ def self.parse (text)
+ Transform.new.apply(Parser.new.parse_with_debug(text))
+ end
+end
@@ -0,0 +1,61 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+require 'parslet'
+require 'parslet/convenience'
+
+module Ciccio
+
+class Parser < Parslet::Parser
+ root :expression
+ rule(:expression) {
+ space? >> str('(') >> space? >> body >> space? >> str(')') >> space?
+ }
+
+ rule(:body) {
+ (expression | identifier | float | integer | string).repeat.as(:expression)
+ }
+
+ rule(:identifier) {
+ (match('[^:()[0-9]\-+"\s]') >> match('[^()\s]').repeat).as(:identifier) >> space?
+ }
+
+ rule(:float) { (
+ integer >> (
+ str('.') >> match('[0-9]').repeat(1) |
+ str('e') >> match('[0-9]').repeat(1)
+ ).as(:e)
+ ).as(:float) >> space? }
+
+ rule(:integer) {
+ ((str('+') | str('-')).maybe >> match("[0-9]").repeat(1)).as(:integer) >> space?
+ }
+
+ rule(:string) {
+ str('"') >> (
+ str('\\') >> any |
+ str('"').absent? >> any
+ ).repeat.as(:string) >> str('"') >> space?
+ }
+
+ rule(:symbol) {
+ (str(':') >> match('[^()\s]').repeat).as(:symbol) >> space?
+ }
+
+ rule(:space) {
+ match('\s').repeat(1)
+ }
+
+ rule(:space?) {
+ space.maybe
+ }
+end
+
+end
@@ -0,0 +1,35 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+require 'ciccio/sexp/identifier'
+require 'ciccio/sexp/string'
+require 'ciccio/sexp/integer'
+require 'ciccio/sexp/float'
+require 'ciccio/sexp/symbol'
+
+module Ciccio
+
+class Sexp < Array
+ def type
+ self[0]
+ end
+
+ def body
+ self[1 .. -1]
+ end
+
+ def to_s
+ '(' << map(&:inspect).join(' ') << ')'
+ end
+
+ alias inspect to_s
+end
+
+end
@@ -0,0 +1,27 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+module Ciccio; class Sexp < Array
+
+class Float
+ def initialize (value)
+ @internal = Float(value)
+ end
+
+ def to_f
+ @internal
+ end
+
+ def inspect
+ to_f.inspect
+ end
+end
+
+end; end
@@ -0,0 +1,27 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+module Ciccio; class Sexp < Array
+
+class Identifier
+ def initialize (name)
+ @internal = name.to_s
+ end
+
+ def to_s
+ @internal
+ end
+
+ def inspect
+ to_s
+ end
+end
+
+end; end
@@ -0,0 +1,27 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+module Ciccio; class Sexp < Array
+
+class Integer
+ def initialize (value)
+ @internal = Integer(value)
+ end
+
+ def to_i
+ @internal
+ end
+
+ def inspect
+ to_i.inspect
+ end
+end
+
+end; end
@@ -0,0 +1,27 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+module Ciccio; class Sexp < Array
+
+class String
+ def initialize (string)
+ @internal = string.to_s
+ end
+
+ def to_s
+ @internal
+ end
+
+ def inspect
+ @internal.inspect
+ end
+end
+
+end; end
@@ -0,0 +1,27 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+module Ciccio; class Sexp < Array
+
+class Symbol
+ def initialize (value)
+ @internal = (value.start_with?(?:) ? value[1 .. -1] : value).to_sym
+ end
+
+ def to_sym
+ @internal
+ end
+
+ def inspect
+ to_sym.inspect
+ end
+end
+
+end; end
@@ -0,0 +1,32 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+require 'parslet'
+require 'parslet/convenience'
+
+require 'ciccio/sexp'
+
+module Ciccio
+
+class Transform < Parslet::Transform
+ rule(identifier: simple(:i)) { Sexp::Identifier.new(i) }
+
+ rule(string: simple(:s)) { Sexp::String.new(s) }
+
+ rule(symbol: simple(:s)) { Sexp::Symbol.new(s) }
+
+ rule(integer: simple(:i)) { Sexp::Integer.new(i) }
+
+ rule(float: { integer: simple(:a), e: simple(:b) }) { Sexp::Float.new(a + b) }
+
+ rule(expression: subtree(:e)) { Sexp[*e] }
+end
+
+end
@@ -0,0 +1,15 @@
+#--
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# Version 2, December 2004
+#
+# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
+# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+#
+# 0. You just DO WHAT THE FUCK YOU WANT TO.
+#++
+
+module Ciccio
+ def self.version
+ '0.0.1'
+ end
+end

0 comments on commit 8d14a18

Please sign in to comment.