Skip to content

Commit

Permalink
minor additions
Browse files Browse the repository at this point in the history
  • Loading branch information
tk744 committed Dec 17, 2020
1 parent 9015ef2 commit 2ac9c37
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 9 deletions.
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ clean:

test: crispy
./run-tests.sh

env:
eval $(opam env)
Binary file modified crispy
Binary file not shown.
2 changes: 1 addition & 1 deletion run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ for f in tests/*.crspy tests/**/*.crspy; do

done

printf "\n%d/%d tests passed" $tests_passed $tests_total
printf "%d/%d tests passed" $tests_passed $tests_total
1 change: 1 addition & 0 deletions src/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ rule token = parse
| "int" { T_INT }
| "bool" { T_BOOL }
| "str" { T_STR }
| ">>" { T_FN }

| "f" { F }
| "assert" { ASSERT }
Expand Down
3 changes: 1 addition & 2 deletions src/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let syntax_error_msg lexbuf =
print_string post_error

let eval_error_msg error =
Format.printf "Evaluation Error unimplemented";
Format.printf "%s" error;
Format.print_flush ()
let file_error_msg filename =
Format.printf "%s not found" filename;
Expand Down Expand Up @@ -97,7 +97,6 @@ let interpret lexbuf (verbose: bool) =
(* TODO: better handling *)
error_msg ();
eval_error_msg err;
print_string err;
exit 2
in
good_msg ();
Expand Down
21 changes: 15 additions & 6 deletions src/parser.mly
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
%token <int> INT
%token <bool> BOOL
%token <string> STR ID
%token T_INT T_BOOL T_STR
%token T_INT T_BOOL T_STR T_FN
%token LPAREN RPAREN LSQUARE RSQUARE LCURLY RCURLY
%token ADD SUB MUL DIV EXP MOD
%token EQ NE GT GE LT LE NOT AND OR
Expand Down Expand Up @@ -140,19 +140,28 @@ tuple:
;

/* functions */
vallist:
| v { [$1] }
| v COMMA vallist { $1::$3 }

arglist:
| var { [$1] }
| var COMMA arglist { $1::$3 }
;

vallist:
| v { [$1] }
| v COMMA vallist { $1::$3 }


/* types */
typ:
| t_base { $1 }
| t_function { $1 }
/* | t_tuple { $1 } */
;

t_base:
| T_INT { T_int }
| T_BOOL { T_bool }
| T_STR { T_str }
;

t_function:
| typ T_FN typ { $1 }
;
6 changes: 6 additions & 0 deletions tests/functions/exp-args.crspy
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

foo = f(x) {
x + 10
};

foo(20 + 30);

0 comments on commit 2ac9c37

Please sign in to comment.