progs/funt.scala
changeset 548 c6ba1d17aaf3
parent 541 885cf83ebce3
child 609 e33545bb2eba
equal deleted inserted replaced
547:81eb43c41416 548:c6ba1d17aaf3
   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)