Some fixes in the spec.
This commit is contained in:
parent
436d3ba048
commit
70fc762c4d
1 changed files with 31 additions and 25 deletions
56
spec/v0.1.md
56
spec/v0.1.md
|
|
@ -31,12 +31,18 @@ Reserved words cannot be redefined:
|
|||
### Comments
|
||||
|
||||
- Single-line:
|
||||
|
||||
```fun
|
||||
// This is a comment
|
||||
```
|
||||
- Multi-line:
|
||||
|
||||
```fun
|
||||
/*
|
||||
This is
|
||||
a multi-line comment
|
||||
This is a
|
||||
multi-line comment
|
||||
*/
|
||||
```
|
||||
|
||||
### Whitespace
|
||||
|
||||
|
|
@ -50,7 +56,7 @@ Reserved words cannot be redefined:
|
|||
|
||||
- 64-bit signed integer.
|
||||
|
||||
```
|
||||
```fun
|
||||
number n = 42
|
||||
```
|
||||
|
||||
|
|
@ -58,7 +64,7 @@ number n = 42
|
|||
|
||||
- 64-bit IEEE floating point.
|
||||
|
||||
```
|
||||
```fun
|
||||
float pi = 3.14159
|
||||
```
|
||||
|
||||
|
|
@ -68,10 +74,10 @@ float pi = 3.14159
|
|||
- ' has higher priority, so " can appear unescaped inside '...'.
|
||||
- To include ' inside '...', escape with \'.
|
||||
|
||||
```
|
||||
```fun
|
||||
string s1 = "Hello"
|
||||
string s2 = 'World'
|
||||
string s3 = "He said: 'Fun!'"
|
||||
string s3 = 'He said: "Fun!"'
|
||||
```
|
||||
|
||||
### Boolean
|
||||
|
|
@ -79,7 +85,7 @@ string s3 = "He said: 'Fun!'"
|
|||
- Canonical values: true, false.
|
||||
- 1 and 0 are accepted in conditionals.
|
||||
|
||||
```
|
||||
```fun
|
||||
boolean flag = true
|
||||
```
|
||||
|
||||
|
|
@ -87,7 +93,7 @@ boolean flag = true
|
|||
|
||||
- Raw byte value.
|
||||
|
||||
```
|
||||
```fun
|
||||
byte b1 = 0x23
|
||||
byte b2 = "A"
|
||||
```
|
||||
|
|
@ -96,7 +102,7 @@ byte b2 = "A"
|
|||
|
||||
- Declared using [ ... ].
|
||||
|
||||
```
|
||||
```fun
|
||||
array nums = [1, 2, 3]
|
||||
```
|
||||
|
||||
|
|
@ -106,7 +112,7 @@ array nums = [1, 2, 3]
|
|||
- Private variables: file-local, cannot be used outside the file.
|
||||
- Redefining globals or shadowing names is forbidden.
|
||||
|
||||
```
|
||||
```fun
|
||||
global string message = "Hello"
|
||||
private number count = 42
|
||||
```
|
||||
|
|
@ -122,7 +128,7 @@ private number count = 42
|
|||
|
||||
### If/Else
|
||||
|
||||
```
|
||||
```fun
|
||||
if(x != y)
|
||||
print x
|
||||
else if(a == b || h != i)
|
||||
|
|
@ -136,14 +142,14 @@ fi
|
|||
|
||||
### For Loops
|
||||
|
||||
```
|
||||
```fun
|
||||
for i in range(1, 10)
|
||||
print i
|
||||
```
|
||||
|
||||
### While Loops
|
||||
|
||||
```
|
||||
```fun
|
||||
while x < 10
|
||||
print x
|
||||
x = x + 1
|
||||
|
|
@ -156,7 +162,7 @@ while x < 10
|
|||
Provided by the runtime (cannot be redefined). Examples:
|
||||
print, range, system, exec.
|
||||
|
||||
```
|
||||
```fun
|
||||
print "Hello, Fun!"
|
||||
```
|
||||
|
||||
|
|
@ -164,7 +170,7 @@ print "Hello, Fun!"
|
|||
|
||||
Must be declared with the f prefix.
|
||||
|
||||
```
|
||||
```fun
|
||||
f add(a, b)
|
||||
return a + b
|
||||
```
|
||||
|
|
@ -180,7 +186,7 @@ f add(a, b)
|
|||
|
||||
Looked up in /var/lib/fun/, supporting .so (native) and .fun (Fun code).
|
||||
|
||||
```
|
||||
```fun
|
||||
#include crypt/md5
|
||||
#include date
|
||||
#include math
|
||||
|
|
@ -190,7 +196,7 @@ Looked up in /var/lib/fun/, supporting .so (native) and .fun (Fun code).
|
|||
|
||||
From the current working directory:
|
||||
|
||||
```
|
||||
```fun
|
||||
#include utils/file.fun
|
||||
```
|
||||
|
||||
|
|
@ -198,7 +204,7 @@ From the current working directory:
|
|||
|
||||
Full path:
|
||||
|
||||
```
|
||||
```fun
|
||||
#include /home/user/project/lib.fun
|
||||
```
|
||||
|
||||
|
|
@ -208,7 +214,7 @@ Full path:
|
|||
|
||||
Executes a command, returns exit code.
|
||||
|
||||
```
|
||||
```fun
|
||||
system("ls -l")
|
||||
```
|
||||
|
||||
|
|
@ -216,7 +222,7 @@ system("ls -l")
|
|||
|
||||
Executes a command, returns stdout.
|
||||
|
||||
```
|
||||
```fun
|
||||
string result = exec("date")
|
||||
```
|
||||
|
||||
|
|
@ -224,7 +230,7 @@ string result = exec("date")
|
|||
|
||||
Executes a command asynchronously, returns process ID.
|
||||
|
||||
```
|
||||
```fun
|
||||
number pid = spawn("sleep 10")
|
||||
```
|
||||
|
||||
|
|
@ -239,20 +245,20 @@ number pid = spawn("sleep 10")
|
|||
|
||||
### Hello World
|
||||
|
||||
```
|
||||
```fun
|
||||
print "Hello, World!"
|
||||
```
|
||||
|
||||
### Loop with Range
|
||||
|
||||
```
|
||||
```fun
|
||||
for i in range(1, 5)
|
||||
print i
|
||||
```
|
||||
|
||||
### User Function
|
||||
|
||||
```
|
||||
```fun
|
||||
f greet(name)
|
||||
return "Hello " + name
|
||||
|
||||
|
|
@ -261,7 +267,7 @@ print greet("Fun")
|
|||
|
||||
### System Call
|
||||
|
||||
```
|
||||
```fun
|
||||
string now = exec("date")
|
||||
print "Current time: " + now
|
||||
```
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue