# HG changeset patch # User Christian Urban # Date 1573082225 0 # Node ID c6c79d21f8a8ea5c1cc530f4885bcef2ddc709c6 # Parent 553b4d4e37196ec703b00b2795df4b4e6aed66e0 updated diff -r 553b4d4e3719 -r c6c79d21f8a8 coursework/cw03.pdf Binary file coursework/cw03.pdf has changed diff -r 553b4d4e3719 -r c6c79d21f8a8 coursework/cw03.tex --- 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 diff -r 553b4d4e3719 -r c6c79d21f8a8 progs/comb1.scala --- 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") diff -r 553b4d4e3719 -r c6c79d21f8a8 progs/comb1a.scala --- 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 } diff -r 553b4d4e3719 -r c6c79d21f8a8 progs/comb2.scala --- 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] = diff -r 553b4d4e3719 -r c6c79d21f8a8 slides/slides06.pdf Binary file slides/slides06.pdf has changed diff -r 553b4d4e3719 -r c6c79d21f8a8 slides/slides06.tex --- 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.