From c2c854a9372efefc5d2304b29d8ec309d7b1a7cd Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Tue, 5 May 2026 06:56:45 +0100 Subject: [PATCH] start new project --- compiler/scanner.sml | 28 ++++++++++++++++++++++++++++ compiler/uses.sml | 1 + 2 files changed, 29 insertions(+) create mode 100644 compiler/scanner.sml create mode 100644 compiler/uses.sml diff --git a/compiler/scanner.sml b/compiler/scanner.sml new file mode 100644 index 0000000..1eff882 --- /dev/null +++ b/compiler/scanner.sml @@ -0,0 +1,28 @@ +structure Scanner = +struct + structure Dfa = CaseSesitiveDfa + + val intDfa = Dfa.fromString "[0-9]+" + val wordDfa = Dfa.fromString "0w[0-9]+" + val realDfa = "[0-9]+.[0-9]+" + val idDfa = Dfa.fromString "[a-zA-Z][a-zA-Z0-9_']*" + + fun helpExtractString (pos, str, acc) = + if pos >= String.size str then + raise Fail ("unterminated string: [" ^ acc ^ "]\n") + else + case String.sub (str, pos) of + #"\"" => (pos + 1, acc) + | #"\\" => + if pos + 1 >= String.size str then + raise Fail ("unterminated string: [" ^ acc ^ "\\]\n") + else + ( + case String.sub (str, pos + 1) of + + ) + | chr => + helpExtractString (pos + 1, str, acc ^ String.implode [chr]) + + fun extractString (pos, str) = helpExtractString (pos. str, "") +end diff --git a/compiler/uses.sml b/compiler/uses.sml new file mode 100644 index 0000000..ea7a5e2 --- /dev/null +++ b/compiler/uses.sml @@ -0,0 +1 @@ +use "../dfa-gen/dfa-gen.sml";