update
authorChristian Urban <christian.urban@kcl.ac.uk>
Fri, 29 Nov 2024 18:58:18 +0000
changeset 975 ae5c03560d4d
parent 974 0cb4bf2469d1
child 976 e9eac62928f5
update
progs/fun/fun.sc
progs/fun/fun_parser.sc
progs/fun/fun_tokens.sc
progs/while-arrays/compile_arrays.sc
progs/while-arrays/compile_bfc.sc
slides/slides09.pdf
slides/slides09.tex
--- a/progs/fun/fun.sc	Fri Nov 22 12:42:07 2024 +0000
+++ b/progs/fun/fun.sc	Fri Nov 29 18:58:18 2024 +0000
@@ -162,7 +162,7 @@
 // the main compilation function
 def compile(prog: List[Decl], class_name: String) : String = {
   val instructions = prog.map(compile_decl).mkString
-  (library + instructions).replaceAllLiterally("XXX", class_name)
+  (library + instructions).replace("XXX", class_name)
 }
 
 
--- a/progs/fun/fun_parser.sc	Fri Nov 22 12:42:07 2024 +0000
+++ b/progs/fun/fun_parser.sc	Fri Nov 29 18:58:18 2024 +0000
@@ -10,15 +10,14 @@
 // this will generate a parse-tree from a list
 // of tokens
 
-//> using toolkit 0.5.0
-// > using file fun_tokens.scala
 
+import $file.fun_tokens, fun_tokens._ 
 
 import scala.language.implicitConversions    
 import scala.language.reflectiveCalls
 
 
-//import $file.fun_tokens, fun_tokens._ 
+
 
 
 // Parser combinators
@@ -26,16 +25,6 @@
 //
 type IsSeq[I] = I => Seq[?]
 
-/*
-abstract class Parser[I, T](using is: I => Seq[_])  {
-  def parse(in: I): Set[(T, I)]  
-
-  def parse_all(in: I) : Set[T] =
-    for ((hd, tl) <- parse(in); 
-        if is(tl).isEmpty) yield hd
-}
-*/
-
 
 abstract class Parser[I, T](using is: I => Seq[?]) {
   def parse(ts: I): Set[(T, I)]
@@ -179,17 +168,11 @@
 
 // Reading tokens and Writing parse trees
 
-// pre-2.5.0 ammonite 
-// import ammonite.ops._
-
-// post 2.5.0 ammonite
-// import os._
-
 def parse_tks(tks: List[Token]) : List[Decl] = 
   Prog.parse_single(tks)
 
-//@doc("Parses a file.")
-//@main
+
+@main
 def main(fname: String) : Unit = {
   val tks = tokenise(os.read(os.pwd / fname))
   println(parse_tks(tks))
--- a/progs/fun/fun_tokens.sc	Fri Nov 22 12:42:07 2024 +0000
+++ b/progs/fun/fun_tokens.sc	Fri Nov 29 18:58:18 2024 +0000
@@ -8,8 +8,6 @@
 //     amm fun_tokens.sc defs.fun
 //
 
-//> using toolkit 0.5.0
- 
 
 import scala.language.implicitConversions    
 import scala.language.reflectiveCalls 
@@ -246,14 +244,8 @@
   else { println (s"Tokenise Error") ; sys.exit(-1) }     
 }
 
-// pre-2.5.0 ammonite 
-// import ammonite.ops._
 
-// post 2.5.0 ammonite
-// import os._
-
-//@doc("Tokenising a file.")
-//@main
+@main
 def main(fname: String) = {
   println(tokenise(os.read(os.pwd / fname)))
 }
--- a/progs/while-arrays/compile_arrays.sc	Fri Nov 22 12:42:07 2024 +0000
+++ b/progs/while-arrays/compile_arrays.sc	Fri Nov 29 18:58:18 2024 +0000
@@ -221,8 +221,9 @@
 
 import os.*
 
-def compile_to_file(bl: Block, class_name: String) : Unit = 
-  write.over(pwd / s"$class_name.j", compile(bl, class_name))  
+def compile_to_file(bl: Block, class_name: String) : Unit = {
+  write.over(pwd / s"$class_name.j", compile(bl, class_name))
+}    
 
 def compile_and_run(bl: Block, class_name: String) : Unit = {
   println(s"Start of compilation")
--- a/progs/while-arrays/compile_bfc.sc	Fri Nov 22 12:42:07 2024 +0000
+++ b/progs/while-arrays/compile_bfc.sc	Fri Nov 29 18:58:18 2024 +0000
@@ -71,10 +71,12 @@
 import os.*
 
 
-def compile_to_file(bl: Block, class_name: String) : Unit = 
-  os.write.over(os.pwd / s"$class_name.j", compile(bl, class_name))  
+def compile_to_file(bl: Block, class_name: String) : Unit = { 
+  write.over(pwd / s"$class_name.while", bl.toString)  // maybe we should pretty-print the AST
+  write.over(pwd / s"$class_name.j", compile(bl, class_name))  
+}
 
-def compile_and_run(bl: Block, class_name: String) : Unit = {
+def compile_and_run(bl: Block, class_name: String) : Unit = { 
   println(s"Start of compilation")
   compile_to_file(bl, class_name)
   println(s"generated $class_name.j file")
Binary file slides/slides09.pdf has changed
--- a/slides/slides09.tex	Fri Nov 22 12:42:07 2024 +0000
+++ b/slides/slides09.tex	Fri Nov 29 18:58:18 2024 +0000
@@ -20,6 +20,10 @@
     #1}
 
 
+\usepackage{tcolorbox}
+\newtcolorbox{mybox}{colback=red!5!white,colframe=red!75!black}
+\newtcolorbox{mybox2}[1]{colback=red!5!white,colframe=red!75!black,fonttitle=\bfseries,title=#1}
+\newtcolorbox{mybox3}[1]{colback=Cyan!5!white,colframe=Cyan!75!black,fonttitle=\bfseries,title=#1}
 
 
 % beamer stuff
@@ -42,7 +46,7 @@
   \begin{center}
   \begin{tabular}{ll}
     Email:  & christian.urban at kcl.ac.uk\\
-Office Hour: & Thurdays 15 -- 16\\  
+Office Hour: & Fridays 12 -- 14\\  
   Location: & N7.07 (North Wing, Bush House)\\
   Slides \& Progs: & KEATS\\
   Pollev: & \texttt{\alert{https://pollev.com/cfltutoratki576}}\\  
@@ -1126,6 +1130,54 @@
 \begin{frame}<1-20>[c]
 \end{frame}
 
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+
+\begin{mybox3}{Random Email}\it
+  I would like to ask a question regarding CW4. When I run my file, I
+  can see the output display in fib.j but I'm receiving the
+  Java.lang.Verifyerror. What might be causing this error?
+\end{mybox3}
+
+
+\begin{textblock}{7}(0.5,14)
+\begin{minipage}{14cm}\small
+Error: Unable to initialize main class fib.fib
+Caused by: java.lang.VerifyError: (class: fib/fib, method: main signature: ([Ljava/lang/String;)V) Illegal type in constant pool
+\end{minipage}
+\end{textblock}
+
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+
+\begin{textblock}{8}(1,4)
+\begin{minipage}{14cm}
+\bf\huge\textcolor{red}{Send some running code!!!!!}
+\end{minipage}
+\end{textblock}
+  
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{And and Or}
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\begin{frame}[c]
+\frametitle{Break}
+\end{frame}
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+
+  
 \end{document}
 
 %%% Local Variables: