updated
authorChristian Urban <urbanc@in.tum.de>
Wed, 06 Nov 2019 23:17:05 +0000
changeset 683 c6c79d21f8a8
parent 682 553b4d4e3719
child 684 1ee523c4f098
updated
coursework/cw03.pdf
coursework/cw03.tex
progs/comb1.scala
progs/comb1a.scala
progs/comb2.scala
slides/slides06.pdf
slides/slides06.tex
Binary file coursework/cw03.pdf has changed
--- a/coursework/cw03.tex	Wed Nov 06 21:52:42 2019 +0000
+++ b/coursework/cw03.tex	Wed Nov 06 23:17:05 2019 +0000
@@ -41,6 +41,9 @@
 \item blocks which are enclosed in curly parentheses
 \end{itemize}
 
+\noindent
+Make sure the grammar is not left-recursive.
+
 \subsection*{Question 2}
 
 You should implement a parser for the WHILE language using
--- a/progs/comb1.scala	Wed Nov 06 21:52:42 2019 +0000
+++ b/progs/comb1.scala	Wed Nov 06 23:17:05 2019 +0000
@@ -12,7 +12,7 @@
 
   def parse_all(ts: I) : Set[T] =
     for ((head, tail) <- parse(ts); 
-        if (tail.isEmpty)) yield head
+        if tail.isEmpty) yield head
 }
 
 class SeqParser[I : IsSeq, T, S](p: => Parser[I, T], 
@@ -162,8 +162,6 @@
 //println(EL.parse_all("1+2+3"))
 
 
-
-
 // non-ambiguous vs ambiguous grammars
 
 // ambiguous
@@ -207,8 +205,6 @@
 (One || Two).parse("111")
 
 
-
-
 // a problem with the arithmetic expression parser -> gets 
 // slow with deep nestedness
 E.parse("1")
--- a/progs/comb1a.scala	Wed Nov 06 21:52:42 2019 +0000
+++ b/progs/comb1a.scala	Wed Nov 06 23:17:05 2019 +0000
@@ -16,7 +16,7 @@
 
   def parse_all(ts: I) : Set[T] =
     for ((head, tail) <- parse(ts); 
-        if (tail.isEmpty)) yield head
+        if tail.isEmpty) yield head
 }
 
 
--- a/progs/comb2.scala	Wed Nov 06 21:52:42 2019 +0000
+++ b/progs/comb2.scala	Wed Nov 06 23:17:05 2019 +0000
@@ -14,7 +14,7 @@
   def parse(ts: I): Set[(T, I)]
 
   def parse_all(ts: I) : Set[T] =
-    for ((head, tail) <- parse(ts); if (tail.isEmpty)) yield head
+    for ((head, tail) <- parse(ts); if tail.isEmpty) yield head
 }
 
 class SeqParser[I : IsSeq, T, S](p: => Parser[I, T], q: => Parser[I, S]) extends Parser[I, ~[T, S]] {
@@ -123,7 +123,7 @@
    ("(" ~ BExp ~ ")" ~ "||" ~ BExp) ==> { case x ~ y ~ z ~ u ~ v => Or(y, v): BExp } ||
    ("true" ==> (_ => True: BExp )) || 
    ("false" ==> (_ => False: BExp )) ||
-   ("(" ~ BExp ~ ")") ==> { case x ~ y ~ z => y}
+   ("(" ~ BExp ~ ")") ==> { case _ ~ x ~ _ => x }
 
 // statement / statements
 lazy val Stmt: Parser[String, Stmt] =
Binary file slides/slides06.pdf has changed
--- a/slides/slides06.tex	Wed Nov 06 21:52:42 2019 +0000
+++ b/slides/slides06.tex	Wed Nov 06 23:17:05 2019 +0000
@@ -28,9 +28,10 @@
   \normalsize
   \begin{center}
   \begin{tabular}{ll}
-  Email:  & christian.urban at kcl.ac.uk\\
-  Office: & N\liningnums{7.07} (North Wing, Bush House)\\
-  Slides: & KEATS (also homework is there)\\
+    Email:  & christian.urban at kcl.ac.uk\\
+    Office Hours: & Thursdays 12 -- 14\\
+    Location: & N7.07 (North Wing, Bush House)\\
+    Slides \& Progs: & KEATS (also homework is there)\\  
   \end{tabular}
   \end{center}
 
@@ -86,8 +87,23 @@
 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[t]
+\frametitle{Starting Symbol}
+
+\bl{\begin{plstx}[margin=1cm]
+  : \meta{S} ::= \meta{A}\cdot\meta{S}\cdot\meta{B} |
+                 \meta{B}\cdot\meta{S}\cdot\meta{A} | \epsilon\\
+  : \meta{A} ::= a | \epsilon\\
+  : \meta{B} ::= b\\  
+\end{plstx}}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 \begin{frame}[c]
-\frametitle{\begin{tabular}{c}Hierarchy of Languages\end{tabular}}
+\frametitle{Hierarchy of Languages}
 
 Recall that languages are sets of strings.