progs/lexer/lexer.sc
changeset 827 67c8a6e6a305
parent 826 b0352633bf48
child 846 3a535de22816
equal deleted inserted replaced
826:b0352633bf48 827:67c8a6e6a305
   221 
   221 
   222 
   222 
   223 // Two Simple While Tests
   223 // Two Simple While Tests
   224 //========================
   224 //========================
   225 
   225 
   226 @doc("small tests")
   226 @arg(doc = "small tests")
   227 @main
   227 @main
   228 def small() = {
   228 def small() = {
   229 
   229 
   230   val prog0 = """read n"""
   230   val prog0 = """read n"""
   231   println(s"test: $prog0")
   231   println(s"test: $prog0")
   262 };
   262 };
   263 write "Result";
   263 write "Result";
   264 write minus2
   264 write minus2
   265 """
   265 """
   266 
   266 
   267 @doc("Fibonacci test")
   267 @arg(doc = "Fibonacci test")
   268 @main
   268 @main
   269 def fib() = {
   269 def fib() = {
   270   println("lexing fib program")
   270   println("lexing fib program")
   271   println(escape(lexing_simp(WHILE_REGS, prog2)).mkString("\n"))
   271   println(escape(lexing_simp(WHILE_REGS, prog2)).mkString("\n"))
   272 }
   272 }
   288  y := start;
   288  y := start;
   289  x := x - 1
   289  x := x - 1
   290 }
   290 }
   291 """
   291 """
   292 
   292 
   293 @doc("Loops test")
   293 @arg(doc = "Loops test")
   294 @main
   294 @main
   295 def loops() = {
   295 def loops() = {
   296   println("lexing Loops")
   296   println("lexing Loops")
   297   println(escape(lexing_simp(WHILE_REGS, prog3)).mkString("\n"))
   297   println(escape(lexing_simp(WHILE_REGS, prog3)).mkString("\n"))
   298 }
   298 }
   299 
   299 
   300 @doc("Email Test")
   300 @arg(doc = "Email Test")
   301 @main
   301 @main
   302 def email() = {
   302 def email() = {
   303   val lower = "abcdefghijklmnopqrstuvwxyz"
   303   val lower = "abcdefghijklmnopqrstuvwxyz"
   304 
   304 
   305   val NAME = RECD("name", PLUS(RANGE(lower ++ "_.-")))
   305   val NAME = RECD("name", PLUS(RANGE(lower ++ "_.-")))
   315 
   315 
   316   println(lexing_simp(EMAIL, "christian.urban@kcl.ac.uk"))
   316   println(lexing_simp(EMAIL, "christian.urban@kcl.ac.uk"))
   317 }
   317 }
   318 
   318 
   319 
   319 
   320 @doc("All tests.")
   320 @arg(doc = "All tests.")
   321 @main
   321 @main
   322 def all() = { small(); fib() ; loops() ; email() } 
   322 def all() = { small(); fib() ; loops() ; email() } 
   323 
   323 
   324 
   324 
   325 
   325 
   326 
   326 
       
   327 // runs with amm2 and amm3
       
   328 
       
   329 
       
   330