This repository has been archived by the owner on Nov 10, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Initial commit
- Loading branch information
asterite
committed
Jun 21, 2011
0 parents
commit 50db229
Showing
8 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| rvm use 1.9.2@crystal |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| source :rubygems | ||
|
|
||
| gem 'ruby-llvm' | ||
| gem 'rltk', '1.0.0', :path => 'vendor/gems' | ||
| gem 'rspec' |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| PATH | ||
| remote: vendor/gems | ||
| specs: | ||
| rltk (1.0.0) | ||
|
|
||
| GEM | ||
| remote: http://rubygems.org/ | ||
| specs: | ||
| diff-lcs (1.1.2) | ||
| ffi (1.0.9) | ||
| rspec (2.6.0) | ||
| rspec-core (~> 2.6.0) | ||
| rspec-expectations (~> 2.6.0) | ||
| rspec-mocks (~> 2.6.0) | ||
| rspec-core (2.6.4) | ||
| rspec-expectations (2.6.0) | ||
| diff-lcs (~> 1.1.2) | ||
| rspec-mocks (2.6.0) | ||
| ruby-llvm (2.9.1) | ||
| ffi (>= 1.0.0) | ||
|
|
||
| PLATFORMS | ||
| ruby | ||
|
|
||
| DEPENDENCIES | ||
| rltk (= 1.0.0)! | ||
| rspec | ||
| ruby-llvm |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| Joy | ||
| === | ||
|
|
||
| Joy is a programming language that compiles to native code. | ||
| It has a syntax strongly inspired by Ruby: | ||
| * No need to declare types: everything is inferred. | ||
| * Classes and Modules can be opened: at compile time everything is mixed together | ||
| * String interpolation | ||
| * Regular expression interpolation | ||
| * Instance variables start with @ | ||
| * Global variables start with $ | ||
| * Constants start with Capital Letters | ||
| * Functions can be evaluated at compile time as long as they are assigned to a Constant. | ||
|
|
||
| Examples: | ||
|
|
||
| 1. Hello World | ||
|
|
||
| puts "Hello World" | ||
|
|
||
| 2. Fibbonacci | ||
|
|
||
| def fib n | ||
| if n <= 2 | ||
| 1 | ||
| else | ||
| fib(n - 1) + fib(n - 2) | ||
| end | ||
| end | ||
|
|
||
| Value = fib 6 | ||
| puts Value | ||
|
|
||
| # Compiles to... | ||
| # puts 8 | ||
|
|
||
| 3. Constants as arguments | ||
|
|
||
| def static N, x | ||
| if N == 1 | ||
| 2 * x | ||
| else | ||
| 3 * x | ||
| end | ||
| end | ||
|
|
||
| puts static(2, 6) | ||
|
|
||
| # Compiles to... | ||
| def static_2 x | ||
| 3 * x | ||
| end | ||
|
|
||
| puts static_2(6) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| require 'rubygems' | ||
| ['lexer'].each do |filename| | ||
| require(File.expand_path("../#{filename}", __FILE__)) | ||
| end | ||
|
|
||
| p Lexer.lex('def').map(&:type) |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| require 'rltk/lexer' | ||
|
|
||
| class Lexer < RLTK::Lexer | ||
| rule(/\s/) | ||
| rule(/def/) { [:IDENT, :def] } | ||
| rule(/\w+/) { |id| [:IDENT, id] } | ||
| end |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| require 'test/unit' | ||
| require(File.expand_path("../../lib/lexer", __FILE__)) | ||
|
|
||
| describe Lexer do | ||
| it "lexes def" do | ||
| token = Lexer.lex('def').first | ||
| token.type.should eq(:IDENT) | ||
| token.value.should eq(:def) | ||
| end | ||
| end |
Binary file not shown.