Skip to content

Commit

Permalink
Repeat statement
Browse files Browse the repository at this point in the history
  • Loading branch information
rtoal committed Oct 9, 2024
1 parent 7d2a357 commit fba5834
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/ekko.ohm
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ Ekko {
Program = Actor+
Actor = actor id Locals? Block
Locals = "[" ListOf<id, ","> "]"
Block = "{" Stmt+"}"
Block = "{" Stmt* "}"
Stmt = id "=" Exp ";" -- assign
| print Exp ";" -- print
| while Exp Block -- while
| loop (Exp times)? Block -- for
| repeat Exp Block -- repeat
| if Exp Block (else (Stmt_if | Block))? -- if
| send Exp to id ";" -- send
| receive id ";" -- receive
Expand Down Expand Up @@ -36,11 +36,10 @@ Ekko {
| id -- id
| "(" Exp ")" -- parens

actor = "actor" ~idchar
actor = "actor" ~idchar
print = "print" ~idchar
while = "while" ~idchar
loop = "loop" ~idchar
times = "times" ~idchar
repeat = "repeat" ~idchar
if = "if" ~idchar
else = "else" ~idchar
send = "send" ~idchar
Expand All @@ -53,7 +52,7 @@ Ekko {
true = "true" ~idchar
false = "false" ~idchar
nil = "nil" ~idchar
keyword = actor | print | while | loop | times | if | else
keyword = actor | print | while | repeat | if | else
| send | to | receive | back | forward | commit | abort
| true | false | nil
num = digit+ ("." digit+)? (("E" | "e") ("+" | "-")? digit+)?
Expand Down
6 changes: 6 additions & 0 deletions test/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ import assert from "node:assert/strict"
import parse from "../src/parser.js"

const syntaxChecks = [
["short if", "if true { print(1); }"],
["longer if", "if true { print(1); } else { print(1); }"],
["even longer if", "if true { print(1); } else if false { print(1);}"],
["while with empty block", "while true {}"],
["while with one statement block", "while true { x = 1; }"],
["repeat with long block", "repeat 2 { print(1);\nprint(2);print(3); }"],
["all numeric literal forms", "print(8 * 89.123);"],
["complex expressions", "print(83 * ((((-((((13 / 21)))))))) + 1 - 0);"],
["all unary operators", "print (-3); print (!false);"],
Expand Down

0 comments on commit fba5834

Please sign in to comment.