Skip to content

Instantly share code, notes, and snippets.

@antonijn
Last active August 29, 2015 14:05
Show Gist options
  • Save antonijn/d5c67c34be8f9ff84e03 to your computer and use it in GitHub Desktop.
Save antonijn/d5c67c34be8f9ff84e03 to your computer and use it in GitHub Desktop.
Concept for a more readable functional programming language
# declaring putc as an external function with implicit io
int putchar(io $, char c):
implio cimport "putchar"
# print function
none print(io $, char ch):
putchar($, ch); nothing
none print(io $, [char] []): nothing
none print(io $, [char] ch:str):
print($, ch);
print($, str)
none print(io $, integer 0): print($, '0')
none print(io $, integer i):
if i < 0
print($, '-');
print($, -i)
print($, i / 10);
print($, char((i % 10) + '0'))
# factorial function
integer fact(integer 0): 1
integer fact(integer n): n * fact(n - 1)
# main function
none main(io $):
print($, "The factorial of 10 is: ");
print($, fact(10))
digit:
0123456789
number:
digit
digit number
number . number
idchar:
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
$_
idcont:
digit
idchar
digit idcont
idchar idcont
symbol:
idchar
idchar idcont
string:
char
char string
escchar:
abfnrtv\'"
char:
digit
idchar
whitespace
\ escchar
expression:
let symdef expression
if expression expression expression
number
" string "
' char '
symbol
expression ( expression-list )
expression-list:
expression
expression , expression-list
vardecl:
type symbol
funcdecl:
type symbol ( param-list )
symdecl:
vardecl
funcdecl
vardef:
vardecl = expression
funcdef:
funcdecl : expression
symdef:
vardef
funcdef
param-list:
symdecl
symdecl , param-list
file:
funcdef
funcdef file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment