start new project

This commit is contained in:
2026-05-05 06:56:45 +01:00
parent 9520f683db
commit c2c854a937
2 changed files with 29 additions and 0 deletions

28
compiler/scanner.sml Normal file
View File

@@ -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

1
compiler/uses.sml Normal file
View File

@@ -0,0 +1 @@
use "../dfa-gen/dfa-gen.sml";