progs/scala/re.scala
changeset 41 4f8a9ed0f26d
parent 38 b48939cca0cf
child 48 652861c9473f
--- a/progs/scala/re.scala	Tue Nov 04 19:51:39 2014 +0000
+++ b/progs/scala/re.scala	Thu Nov 06 20:08:39 2014 +0000
@@ -214,6 +214,7 @@
 val LPAREN: Rexp = "("
 val BEGIN: Rexp = "{"
 val END: Rexp = "}"
+val STRING: Rexp = "\"" ~ SYM.% ~ "\""
 
 
 val WHILE_REGS = (("k" $ KEYWORD) | 
@@ -221,6 +222,7 @@
                   ("o" $ OP) | 
                   ("n" $ NUM) | 
                   ("s" $ SEMI) | 
+                  ("str" $ STRING) |
                   ("p" $ (LPAREN | RPAREN)) | 
                   ("b" $ (BEGIN | END)) | 
                   ("w" $ WHITESPACE)).%
@@ -262,6 +264,7 @@
 
 // Big Test
 //==========
+/*
 val prog2 = """
 i := 2;
 max := 100;
@@ -275,6 +278,21 @@
   if isprime == 1 then write i else skip;
   i := i + 1
 }"""
+*/
+val prog2 = """
+write "fib";
+read n;
+minus1 := 0;
+minus2 := 1;
+while n > 0 do {
+  temp := minus2;
+  minus2 := minus1 + minus2;
+  minus1 := temp;
+  n := n - 1
+};
+write "result";
+write minus2
+"""
 
 println("Tokens")
 println(env(lexing_simp(WHILE_REGS, prog2)))