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";