Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Commit

Permalink
Change object syntax from (|| ... ) to [...]!
Browse files Browse the repository at this point in the history
  • Loading branch information
munificent committed Dec 24, 2011
1 parent 70a0a21 commit 75c5ce0
Show file tree
Hide file tree
Showing 25 changed files with 296 additions and 309 deletions.
30 changes: 14 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ inspired by Smalltalk, Self, and Javascript.
It is written in C++ with a hand-written lexer and parser. It has
minimal dependencies. I want Finch to be:

* Syntactically expressive yet minimal. Your code should look
beautiful and do what you want.
* Syntactically expressive yet minimal. Your code should look beautiful and
do what you want.

* An example of a small, clean C++ codebase for an interpreter. If you
can read C++ and want to learn more about programming languages, I
hope Finch's code will be a good primer.
* An example of a small, clean C++ codebase for an interpreter. If you can
read C++ and want to learn more about programming languages, I hope Finch's
code will be a good primer.

* A language in the Smalltalk family that's friendly to people coming
from a text file and curly brace background.
* A language in the Smalltalk family that's friendly to people coming from a
text file and curly brace background.

* A minimal prototype-based dynamic language. I think prototypes are a
really cool paradigm, but Self is too complex (and mostly dead), and
Javascript is... well... Javascript.
* A minimal prototype-based dynamic language. I think prototypes are a really
cool paradigm, but Self goes too far, and Javascript doesn't go far enough.

* Easily embeddable in other applications. I don't know if Finch ever
will have real use, but if it does, it will likely be as a
configuration or scripting language within a larger application,
much like Lua.
* Easily embeddable in other applications. I don't know if Finch ever will
have real use, but if it does, it will likely be as a configuration or
scripting language within a larger application, much like Lua.


A Taste of the Language
Expand All @@ -32,7 +30,7 @@ Here's a little example to get you going. This little program doesn't
draw, but it will tell you what turns to make to draw a dragon curve:

// create an object and put it in a variable "dragon"
dragon <- (||
dragon <- [
// define a "trace:" method for outputting the series of left and
// right turns needed to draw a dragon curve.
trace: depth {
Expand All @@ -48,7 +46,7 @@ draw, but it will tell you what turns to make to draw a dragon curve:
self traceDepth: n - 1 turn: "L"
}
}
)
]

// now lets try it
dragon trace: 5
Expand Down
4 changes: 2 additions & 2 deletions benchmark/fib.fin
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
Fib <- (||
Fib <- [
calc: n {
if: n < 2 then: {
n
} else: {
(self calc: n - 2) + (self calc: n - 1)
}
}
)
]

write-line: (Fib calc: 25) = 75025
42 changes: 21 additions & 21 deletions benchmark/lexer.fin
Original file line number Diff line number Diff line change
Expand Up @@ -25,45 +25,45 @@ Token/IgnoreLine <- "ignore line"
Token/Eof <- "eof"
Token/Error <- "error"

Token <- (||
Token <- [
new: type text: text span: span {
(|Tokens| _type <- type, _text <- text, _span <- span )
[|Tokens| _type <- type, _text <- text, _span <- span ]
}
)
]

Tokens <- (||
Tokens <- [
type { _type }
text { _text }
span { _span }

to-string { "'" + _text + "' (" + _type + ") " + _span }
)
]

SourceSpan <- (||
SourceSpan <- [
new-file: file start: start end: end {
(|SourceSpans| _file <- file, _start <- start, _end <- end)
[|SourceSpans| _file <- file, _start <- start, _end <- end ]
}
)
]

SourceSpans <- (||
SourceSpans <- [
file <- { _file <- it }
file { _file }
start { _start }
end { _end }

to-string { _file path + ":" + _start + ":" + _end }
)
]

SourceFile <- (||
SourceFile <- [
new-path: path source: source {
(|SourceFiles| _path <- path, _source <- source)
[|SourceFiles| _path <- path, _source <- source ]
}
)
]

SourceFiles <- (||
SourceFiles <- [
path { _path }
source { _source }
)
]

Strings :: (
alpha? {
Expand All @@ -83,19 +83,19 @@ Strings :: (
}
)

Lexer <- (||
Lexer <- [
new-path: path source: source {
(|Lexers|
[|Lexers|
_file <- SourceFile new-path: path source: source
_source <- source
_pos <- 0
_start <- 0
_eat-newlines? <- true
)
]
}
)
]

Lexers <- (||
Lexers <- [
each: block {
token <- self next-token
while: { token != nil } do: {
Expand Down Expand Up @@ -300,7 +300,7 @@ Lexers <- (||
span <- SourceSpan new-file: _file start: _start end: _pos
Token new: type text: text span: span
}
)
]

file <- Io read-file: "../../benchmark/lexer.fin"
tokens <- 0
Expand Down
18 changes: 9 additions & 9 deletions doc/markdown/expressions.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ A series of one or more punctuation characters is an *operator*. You can define

:::finch
// valid punctuation characters
+ - ! @ # $ % ^ & * = < > / ? ~
+ - ! $ % ^ & * = < > / ? ~

// can also be combined
-- ?! ---@ <=/=> @*#%&#$@&!
Expand Down Expand Up @@ -241,18 +241,18 @@ One way you can think of this is that short assignment always means "declare a n

## Arrays

Finch has built-in support for resizable arrays. Most of the things you can do with arrays use normal message syntax, but there's also a little special sauce for creating arrays. If you surround a series of expressions with square brackets, it creates an array with an element for the value of each expression. Elements are separated with commas (or newlines) like a normal sequence. Enough talk:
Finch has built-in support for resizable arrays. Most of the things you can do with arrays use normal message syntax, but there's also a little special sauce for creating arrays. A hash (`#`) followed a series of expressions in square brackets creates an array with an element for the value of each expression. Elements are separated with commas (or newlines) like a normal sequence. Enough talk:

:::finch
[] // creates an empty array
[1, 2, 3] // a three-element array
[123, "text"] // arrays can have elements of different types
[1 + 2, 3 neg] // expressions are fine too
#[] // creates an empty array
#[1, 2, 3] // a three-element array
#[123, "text"] // arrays can have elements of different types
#[1 + 2, 3 neg] // expressions are fine too

// newlines can separate elements too
["first"
"second"
"third"]
#["first"
"second"
"third"]

Arrays are objects like everything else, so they can be stored in variables, passed to methods, etc.

Expand Down
38 changes: 18 additions & 20 deletions doc/markdown/index.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ Welcome and thanks for coming. You're here because, for some reason, you're inte

## What is Finch?

[Finch](http://bitbucket.org/munificent/finch/) is a simple [bytecode](http://en.wikipedia.org/wiki/Bytecode) [interpreted](http://en.wikipedia.org/wiki/Interpreted_language), purely [object-oriented](http://en.wikipedia.org/wiki/Object-oriented_programming), [prototype-based](http://en.wikipedia.org/wiki/Prototype-based_programming), [dynamically-typed](http://en.wikipedia.org/wiki/Dynamic_programming_language) programming language. It's mostly inspired by [Smalltalk](http://www.smalltalk.org/main/), [Self](http://selflanguage.org/), and [Javascript](https://developer.mozilla.org/en/About_JavaScript).
[Finch](http://github.com/munificent/finch/) is a simple [bytecode](http://en.wikipedia.org/wiki/Bytecode) [interpreted](http://en.wikipedia.org/wiki/Interpreted_language), purely [object-oriented](http://en.wikipedia.org/wiki/Object-oriented_programming), [prototype-based](http://en.wikipedia.org/wiki/Prototype-based_programming), [dynamically-typed](http://en.wikipedia.org/wiki/Dynamic_programming_language) programming language. It's mostly inspired by [Smalltalk](http://www.smalltalk.org/main/), [Self](http://selflanguage.org/), and [Javascript](https://developer.mozilla.org/en/About_JavaScript).

It is written in C++ with a hand-written [lexer](http://bitbucket.org/munificent/finch/src/tip/src/Syntax/Lexer.h) and [parser](http://bitbucket.org/munificent/finch/src/tip/src/Syntax/FinchParser.h). It has minimal dependencies. I want Finch to be:
It is written in C++ with a hand-written [lexer](https://github.com/munificent/finch/blob/master/src/Syntax/Lexer.h) and [parser](https://github.com/munificent/finch/blob/master/src/Syntax/FinchParser.h). It has minimal dependencies. I want Finch to be:

* Syntactically expressive yet minimal. Your code should look beautiful and
do what you want.
Expand All @@ -31,7 +31,7 @@ Here's a little example to get you going. This little program doesn't draw, but

:::finch
// create an object and put it in a variable "dragon"
dragon <- (||
dragon <- [
// define a "trace:" method for outputting the series of left and
// right turns needed to draw a dragon curve.
trace: depth {
Expand All @@ -47,33 +47,31 @@ Here's a little example to get you going. This little program doesn't draw, but
self trace-depth: n - 1 turn: "L"
}
}
)
]

// now let's try it
dragon trace: 5

## Getting Started

**TODO: This is out of date. Finch uses gyp now.**
Finch lives on github here: https://github.com/munificent/finch

Finch lives on github here: [https://github.com/munificent/finch](https://github.com/munificent/finch)
To play around with it, sync it down. Finch uses [GYP][] to generate projects or
makefiles for your platform, which you then build to get an executable.

To play around with it, sync it down. There is both an XCode project and a makefile. Use whichever you prefer. I don't have anything set up for Windows yet, but I'm keen if someone wants to throw a VS solution at me.
1. Download GYP from: http://code.google.com/p/gyp/
2. Clone the finch repo from github.
3. In a terminal/command prompt, navigate to the root finch/ directory.
4. Run GYP on this file: `<path to gyp>/gyp --depth=1`
Where `<path to gyp>` is wherever you downloaded GYP to in step 1.
This should spit out a project/makefile in the root directory for your
platform.
5. Open that project in XCode or VS and build, or build the makefile.
6. Ta-da! You should now have a Finch executable under a build/ directory.

### Building on Mac OS X with XCode
Let me know if you run into any problems.

I mostly work on it in XCode. If you like that, here's how to get going:

1. Open the XCode project at: `src/finch.xcodeproject`
2. Build and run. Ta-da!

### Building with make

Thanks to [Steve Folta](http://www.folta.net/steve/), there is also a makefile for *nix users:

1. `cd` to the root `finch` directory.
2. `make`
3. `./finch`
[gyp]: http://code.google.com/p/gyp/

### Running Finch

Expand Down
Loading

0 comments on commit 75c5ce0

Please sign in to comment.