# HG changeset patch # User Christian Urban # Date 1539697230 -3600 # Node ID 19de761b69e918c10f13c890afe636922c7fb52b # Parent dbb0f7d2a33d34ade96567ca0ebda38cfb9b1ee9 updated diff -r dbb0f7d2a33d -r 19de761b69e9 progs/token.scala --- a/progs/token.scala Tue Oct 16 08:29:49 2018 +0100 +++ b/progs/token.scala Tue Oct 16 14:40:30 2018 +0100 @@ -1,3 +1,5 @@ +// Simple Tokenizer according to Sulzmann & Lu + import scala.language.implicitConversions import scala.language.reflectiveCalls @@ -9,7 +11,7 @@ case class SEQ(r1: Rexp, r2: Rexp) extends Rexp case class STAR(r: Rexp) extends Rexp case class RECD(x: String, r: Rexp) extends Rexp - + abstract class Val case object Empty extends Val case class Chr(c: Char) extends Val @@ -25,7 +27,8 @@ case c::Nil => CHAR(c) case c::s => SEQ(CHAR(c), charlist2rexp(s)) } -implicit def string2rexp(s : String) : Rexp = charlist2rexp(s.toList) +implicit def string2rexp(s : String) : Rexp = + charlist2rexp(s.toList) implicit def RexpOps(r: Rexp) = new { def | (s: Rexp) = ALT(r, s) @@ -42,6 +45,9 @@ def $ (r: Rexp) = RECD(s, r) } +// A test for more conveninet syntax +val re : Rexp = ("ab" | "a") ~ ("b" | ONE) + // nullable function: tests whether the regular // expression can recognise the empty string def nullable (r: Rexp) : Boolean = r match { @@ -85,6 +91,7 @@ } // extracts an environment from a value +// used for tokenise a string def env(v: Val) : List[(String, String)] = v match { case Empty => Nil case Chr(c) => Nil @@ -126,8 +133,9 @@ def lexing(r: Rexp, s: String) : Val = lex(r, s.toList) - -lexing(("ab" | "a") ~ ("b" | ONE), "ab") +// a simple test for extracting an environment +val re1 : Rexp = ("first" $ ("a" | "ab")) ~ ("second" $ ("b" | ONE)) +env(lexing(re1, "ab")) // some "rectification" functions for simplification def F_ID(v: Val): Val = v @@ -243,7 +251,7 @@ //======================== println("prog0 test") -val prog0 = """read n""" +val prog0 = """read if""" println(env(lexing_simp(WHILE_REGS, prog0))) println("prog1 test") diff -r dbb0f7d2a33d -r 19de761b69e9 slides/slides04.pdf Binary file slides/slides04.pdf has changed diff -r dbb0f7d2a33d -r 19de761b69e9 slides/slides04.tex --- a/slides/slides04.tex Tue Oct 16 08:29:49 2018 +0100 +++ b/slides/slides04.tex Tue Oct 16 14:40:30 2018 +0100 @@ -665,7 +665,7 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[c] -\frametitle{Sulzmann Matcher} +\frametitle{Sulzmann \& Lu Matcher} We want to match the string \bl{$abc$} using \bl{$r_1$}: