| @@ -6,12 +6,18 @@ fun finish :: "string \<Rightarrow> string list \<Rightarrow> string list" where |
| 6 | 6 | "finish [] out = out" |
| 7 | 7 | | "finish word out = rev word # out" |
| 8 | 8 | |
| 9 | | -fun lex :: "string \<Rightarrow> string \<Rightarrow> string list \<Rightarrow> string list" where |
| 10 | | - "lex [] word out = rev (finish word out)" |
| 11 | | -| "lex (c # cs) word out = (if c = CHR '' '' \<or> c = CHR 0x09 \<or> c = CHR 0x0A \<or> c = CHR 0x0D |
| 12 | | - then lex cs [] (finish word out) |
| 13 | | - else if c = CHR ''('' \<or> c = CHR '')'' then lex cs [] ([c] # finish word out) |
| 14 | | - else lex cs (c # word) out)" |
| 9 | +fun scan :: "string \<Rightarrow> string \<Rightarrow> string list \<Rightarrow> bool \<Rightarrow> string list" where |
| 10 | + "scan [] word out comment = rev (finish word out)" |
| 11 | +| "scan (c # cs) word out comment = (if comment then |
| 12 | + scan cs [] out (c \<noteq> CHR 0x0A \<and> c \<noteq> CHR 0x0D) |
| 13 | + else if c = CHR '';'' then scan cs [] (finish word out) True |
| 14 | + else if c = CHR '' '' \<or> c = CHR 0x09 \<or> c = CHR 0x0A \<or> c = CHR 0x0D |
| 15 | + then scan cs [] (finish word out) False |
| 16 | + else if c = CHR ''('' \<or> c = CHR '')'' then scan cs [] ([c] # finish word out) False |
| 17 | + else scan cs (c # word) out False)" |
| 18 | + |
| 19 | +definition lex :: "string \<Rightarrow> string \<Rightarrow> string list \<Rightarrow> string list" where |
| 20 | + "lex s word out = scan s word out False" |
| 15 | 21 | |
| 16 | 22 | fun digit :: "char \<Rightarrow> nat" where |
| 17 | 23 | "digit c = (let n = nat_of_char c in |