Permalink
Browse files

Initial commit of files harvested from old min-koi project.

  • Loading branch information...
0 parents commit 504d7934da84e2dbde476ac319ae9fc6c093b79d @aarongough committed Aug 30, 2010
@@ -0,0 +1,20 @@
+Copyright (c) 2010 Aaron Gough (http://thingsaaronmade.com/)
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,83 @@
+= MinKoi
+
+MinKoi is a small programming language that is designed to be easy to use, easy to understand and easy to implement.
+
+=== Example
+
+This is an old-school 'Blast Off!' program written in MinKoi:
+
+ countdown = function( count )
+ print( to_string( count ))
+ print( ", " )
+ if( count == 0 )
+ return()
+ end
+ count = count - 1
+ call( countdown, count )
+ end
+
+ call( countdown, 10 )
+
+ print( "Blast Off!" )
+
+ #=> 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, Blast Off!
+
+
+=== More Info
+
+MinKoi was conceived as an intermediate language in which it would be possible to implement higher-level languages and their object models, to this end flexibility is one of it's primary goals.
+
+MinKoi is an imperative, dynamic, weakly-typed language with first-class functions. MinKoi's syntax is influenced by JavaScript, Lua and Ruby, but works very hard to be unambiguous so that it is easy to write parsers for (in stark contrast with Ruby).
+
+=== Goals
+
+* Ease of use
+* Ease of implementation
+* Ease of modification
+* Flexibility
+* Speed
+
+=== Data types
+
+MinKoi features a full set of basic data types including:
+
+* Nil
+* Boolean
+* Integer
+* Float
+* String
+* Function
+
+(array and hash coming soon!)
+
+=== Flow control
+
+MinKoi currently only implements a minimal set of flow control operators:
+
+ if( expression )
+ call( do_work )
+ endif
+
+ unless( expression )
+ call( do_other_work )
+ endunless
+
+=== Built-in functions
+
+print( string ):: Writes a string to STDOUT.
+gets():: Fetches a newline delimited string from STDIN.
+call( identifier [, parameter]):: Calls the function that is stored in 'identifier'.
+tailcall( identifier[, parameter]):: Performs a 'tailcall' to the function stored in 'identifier'. This type of call is used when recursing heavily to improve performance and to facilitate the use of functions as iterators.
+return( [value] ):: Return a value from a function.
+to_string( value/identifier ):: Converts the given value to a representative string.
+type_of( value ):: Returns a string representing the type of the value given, eg: "integer".
+
+=== Reserved words
+
+if, endif, unless, endunless, function, endfunction, call, tailcall, print, gets, return, to_string, type_of, nil, true, false
+
+=== Author & Credits
+
+Author:: {Aaron Gough}[mailto:aaron@aarongough.com]
+
+Copyright (c) 2010 {Aaron Gough}[http://thingsaaronmade.com/] ({thingsaaronmade.com}[http://thingsaaronmade.com/]), released under the MIT license
@@ -0,0 +1,45 @@
+require 'rake'
+require 'rake/testtask'
+require 'rake/rdoctask'
+
+desc 'Default: run unit tests.'
+task :default => :test
+
+begin
+ require 'jeweler'
+ Jeweler::Tasks.new do |gemspec|
+ gemspec.name = "min-koi"
+ gemspec.summary = "A Parser and compiler for the MinKoi language."
+ gemspec.description = "A modular compilation toolchain for the MinKoi language."
+ gemspec.email = "aaron@aarongough.com"
+ gemspec.homepage = "http://github.com/aarongough/min-koi"
+ gemspec.authors = ["Aaron Gough"]
+ gemspec.rdoc_options << '--line-numbers' << '--inline-source'
+ gemspec.extra_rdoc_files = ['README.rdoc', 'MIT-LICENSE']
+ gemspec.add_dependency('treetop')
+ gemspec.add_dependency('koi-vm')
+ gemspec.executables << 'minkoi'
+ end
+rescue LoadError
+ puts "Jeweler not available. Install it with: gem install jeweler"
+end
+
+
+desc 'Test MinKoi.'
+Rake::TestTask.new(:test) do |t|
+ t.libs << 'lib/*.rb'
+ t.libs << 'test'
+ t.pattern = 'test/**/*_test.rb'
+ t.verbose = true
+end
+
+
+desc 'Generate documentation for MinKoi.'
+Rake::RDocTask.new(:rdoc) do |rdoc|
+ rdoc.rdoc_dir = 'rdoc'
+ rdoc.title = 'MinKoi'
+ rdoc.options << '--line-numbers' << '--inline-source'
+ rdoc.rdoc_files.include('README.rdoc')
+ rdoc.rdoc_files.include('lib/**/*.rb')
+ rdoc.rdoc_files.include('app/**/*.rb')
+end
@@ -0,0 +1,9 @@
+require 'rubygems'
+
+require_files = []
+require_files.concat Dir[File.join(File.dirname(__FILE__), 'parser', '**', '*.rb')]
+require_files.concat Dir[File.join(File.dirname(__FILE__), 'compiler', '**', '*.rb')]
+
+require_files.each do |file|
+ require File.expand_path(file)
+end
@@ -0,0 +1,2 @@
+class ParseError < Exception
+end
@@ -0,0 +1,197 @@
+grammar MinKoi
+
+ rule block
+ statement+ <Block>
+ end
+
+ rule statement
+ space? ( hash_assignment / assignment / if / unless / function_call ) ';'? space? <Statement>
+ end
+
+ rule nil
+ "nil" <NilLiteral>
+ end
+
+ rule true
+ "true" <TrueLiteral>
+ end
+
+ rule false
+ "false" <FalseLiteral>
+ end
+
+ rule integer
+ ('+' / '-')? [0-9]+ <IntegerLiteral>
+ end
+
+ rule float
+ ('+' / '-')? [0-9]+ '.' [0-9]+ <FloatLiteral>
+ end
+
+ rule string
+ '"' ([^"\\] / "\\" . )* '"' <StringLiteral>
+ end
+
+ rule identifier
+ '$'? [a-zA-Z] [a-zA-Z0-9_]* <Identifier>
+ end
+
+ rule hash_assignment
+ identifier hash_accessor_list space? assignment_operator space? ( hash / function_definition / expression ) <HashAssignment>
+ end
+
+ rule assignment
+ identifier space? assignment_operator space? ( hash / function_definition / expression ) <Assignment>
+ end
+
+ ##################
+ # Flow control
+
+ rule if
+ 'if(' space? expression space? ')' space
+ block
+ space? 'end' space? <If>
+ end
+
+ rule unless
+ 'unless(' space? expression space? ')' space
+ block
+ space? 'end' space? <Unless>
+ end
+
+ ##################
+ # Functions
+
+ rule function_call
+ identifier space? '(' space? expression? space? ','? expression? space? ')' <FunctionCall>
+ end
+
+ rule function_definition
+ 'function(' space? identifier space? ')'
+ block
+ space? 'end' <FunctionDefinition>
+ end
+
+ ##################
+ # Whitespace
+
+ rule space
+ [\s]+ <Whitespace>
+ end
+
+ ##################
+ # Hashes
+
+ rule hash_accessor_list
+ hash_accessor+ <HashAccessorList>
+ end
+
+ rule hash_accessor
+ '[' expression ']' <HashAccessor>
+ end
+
+ rule hash
+ '{' key_value_list? '}' <HashLiteral>
+ end
+
+ rule key_value_list
+ key_value+ <KeyValueList>
+ end
+
+ rule key_value
+ space? expression space? '=>' space? expression space? ','? <KeyValue>
+ end
+
+ rule key
+ space? expression space? <Key>
+ end
+
+ rule value
+ space? expression space? <Value>
+ end
+
+ ##################
+ # Expressions
+
+ rule expression
+ space? (hash_access / comparative / additive) <Expression>
+ end
+
+ rule hash_access
+ identifier hash_accessor_list <HashAccess>
+ end
+
+ rule comparative
+ additive space? (equality_operator / inequality_operator / greater_than_operator / less_than_operator) space? additive <ComparativeExpression>
+ end
+
+ rule additive
+ multitive space? additive_operator space? additive <AdditiveExpression>
+ /
+ multitive
+ end
+
+ rule additive_operator
+ addition_operator
+ /
+ subtraction_operator
+ end
+
+ rule multitive
+ primary space? multitive_operator space? multitive <MultitiveExpression>
+ /
+ primary
+ end
+
+ rule multitive_operator
+ multiplication_operator
+ /
+ division_operator
+ end
+
+ rule primary
+ function_call / nil / false / true / identifier / float / integer / string
+ /
+ '(' space? expression space? ')' <Expression>
+ end
+
+ ##################
+ # Operators
+
+ rule assignment_operator
+ '=' <AssignmentOperator>
+ end
+
+ rule addition_operator
+ '+' <AdditionOperator>
+ end
+
+ rule subtraction_operator
+ '-' <SubtractionOperator>
+ end
+
+ rule multiplication_operator
+ '*' <MultiplicationOperator>
+ end
+
+ rule division_operator
+ '/' <DivisionOperator>
+ end
+
+ rule equality_operator
+ '==' <EqualityOperator>
+ end
+
+ rule inequality_operator
+ '!=' <InequalityOperator>
+ end
+
+ rule greater_than_operator
+ '>' <GreaterThanOperator>
+ end
+
+ rule less_than_operator
+ '<' <LessThanOperator>
+ end
+
+end
Oops, something went wrong.

0 comments on commit 504d793

Please sign in to comment.