equal
deleted
inserted
replaced
212 val WHITESPACE = PLUS(" " | "\n" | "\t") |
212 val WHITESPACE = PLUS(" " | "\n" | "\t") |
213 val RPAREN: Rexp = ")" |
213 val RPAREN: Rexp = ")" |
214 val LPAREN: Rexp = "(" |
214 val LPAREN: Rexp = "(" |
215 val BEGIN: Rexp = "{" |
215 val BEGIN: Rexp = "{" |
216 val END: Rexp = "}" |
216 val END: Rexp = "}" |
|
217 val STRING: Rexp = "\"" ~ SYM.% ~ "\"" |
217 |
218 |
218 |
219 |
219 val WHILE_REGS = (("k" $ KEYWORD) | |
220 val WHILE_REGS = (("k" $ KEYWORD) | |
220 ("i" $ ID) | |
221 ("i" $ ID) | |
221 ("o" $ OP) | |
222 ("o" $ OP) | |
222 ("n" $ NUM) | |
223 ("n" $ NUM) | |
223 ("s" $ SEMI) | |
224 ("s" $ SEMI) | |
|
225 ("str" $ STRING) | |
224 ("p" $ (LPAREN | RPAREN)) | |
226 ("p" $ (LPAREN | RPAREN)) | |
225 ("b" $ (BEGIN | END)) | |
227 ("b" $ (BEGIN | END)) | |
226 ("w" $ WHITESPACE)).% |
228 ("w" $ WHITESPACE)).% |
227 |
229 |
228 /* |
230 /* |
260 println(env(lexing_simp(WHILE_REGS, prog1))) |
262 println(env(lexing_simp(WHILE_REGS, prog1))) |
261 |
263 |
262 |
264 |
263 // Big Test |
265 // Big Test |
264 //========== |
266 //========== |
|
267 /* |
265 val prog2 = """ |
268 val prog2 = """ |
266 i := 2; |
269 i := 2; |
267 max := 100; |
270 max := 100; |
268 while i < max do { |
271 while i < max do { |
269 isprime := 1; |
272 isprime := 1; |
273 j := j + 1 |
276 j := j + 1 |
274 }; |
277 }; |
275 if isprime == 1 then write i else skip; |
278 if isprime == 1 then write i else skip; |
276 i := i + 1 |
279 i := i + 1 |
277 }""" |
280 }""" |
|
281 */ |
|
282 val prog2 = """ |
|
283 write "fib"; |
|
284 read n; |
|
285 minus1 := 0; |
|
286 minus2 := 1; |
|
287 while n > 0 do { |
|
288 temp := minus2; |
|
289 minus2 := minus1 + minus2; |
|
290 minus1 := temp; |
|
291 n := n - 1 |
|
292 }; |
|
293 write "result"; |
|
294 write minus2 |
|
295 """ |
278 |
296 |
279 println("Tokens") |
297 println("Tokens") |
280 println(env(lexing_simp(WHILE_REGS, prog2))) |
298 println(env(lexing_simp(WHILE_REGS, prog2))) |
281 |
299 |
282 for (i <- 1 to 80) { |
300 for (i <- 1 to 80) { |