From cacb35ddb269a12e16c70fa13bd5c4d181aa3324 Mon Sep 17 00:00:00 2001 From: yenru0 Date: Tue, 4 Nov 2025 12:57:40 +0900 Subject: [PATCH] initial commit --- Makefile | 0 README.md | 18 ++++++++++++++++++ include/globals.h | 0 include/lex.h | 0 src/lex.c | 0 test.cval | 19 +++++++++++++++++++ 6 files changed, 37 insertions(+) create mode 100644 Makefile create mode 100644 README.md create mode 100644 include/globals.h create mode 100644 include/lex.h create mode 100644 src/lex.c create mode 100644 test.cval diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..e69de29 diff --git a/README.md b/README.md new file mode 100644 index 0000000..28bcc0b --- /dev/null +++ b/README.md @@ -0,0 +1,18 @@ +# C-val Compiler + +## Lexical Spec + +* LBRACK `[` +* RBRACK `]` +* LCURLY `{` +* RCURLY `}` +* ID `[all]` +* SEMI `;` +* COMMA `,` +* ARROW `->` +* COMMENT `#` +* NUM `[0-9]*(.[0-9]+)?` +* RETURN `return` +* IF `if` +* ELSE `else` +* STRING "{any}" \ No newline at end of file diff --git a/include/globals.h b/include/globals.h new file mode 100644 index 0000000..e69de29 diff --git a/include/lex.h b/include/lex.h new file mode 100644 index 0000000..e69de29 diff --git a/src/lex.c b/src/lex.c new file mode 100644 index 0000000..e69de29 diff --git a/test.cval b/test.cval new file mode 100644 index 0000000..85ab1ea --- /dev/null +++ b/test.cval @@ -0,0 +1,19 @@ +val int s 3; # global + +val [int->int] fib int n { + return if == n 0 { + 1 + } else { + n * fib + }; +}; + +val [->int] main { + val str line input; + val int n to_int line,; + if < n 0 { + print "ILLEGAL" + } else { + print to_str fib n,; + } +}; \ No newline at end of file