equal
deleted
inserted
replaced
113 case c::s => ders(s, der(c, r)) |
113 case c::s => ders(s, der(c, r)) |
114 } |
114 } |
115 |
115 |
116 |
116 |
117 // regular expressions for the While language |
117 // regular expressions for the While language |
118 val SYM = RANGE("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_") |
118 val SYM = RANGE("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_".toList) |
119 val DIGIT = RANGE("0123456789") |
119 val DIGIT = RANGE("0123456789".toList) |
120 val ID = SYM ~ (SYM | DIGIT).% |
120 val ID = SYM ~ (SYM | DIGIT).% |
121 val NUM = PLUS(DIGIT) |
121 val NUM = PLUS(DIGIT) |
122 val KEYWORD : Rexp = "if" | "then" | "else" | "write" | "def" |
122 val KEYWORD : Rexp = "if" | "then" | "else" | "write" | "def" |
123 val SEMI: Rexp = ";" |
123 val SEMI: Rexp = ";" |
124 val COMMA: Rexp = "," |
124 val COMMA: Rexp = "," |
484 |
484 |
485 |
485 |
486 //examples |
486 //examples |
487 compile_run("defs.rec") |
487 compile_run("defs.rec") |
488 //compile_run("fact.rec") |
488 //compile_run("fact.rec") |
|
489 |
|
490 |
|
491 |
|
492 |
|
493 |
|
494 // a problem with the parser |
|
495 val text = "(((((1)))))" |
|
496 val tokens = tokenizer(text) |
|
497 println(tokens) |
|
498 val ast = Prog.parse_single(tokens) |
|
499 println(ast) |
|
500 |
|
501 Exp.parse_single(tokens) |
|
502 |
|
503 |
|
504 |
|
505 val text = "((((1))))" |
|
506 val tokens = tokenizer(text) |
|
507 println(tokens) |
|
508 Exp.parse(tokens) |