# HG changeset patch # User Christian Urban # Date 1546079427 0 # Node ID f7de0915fff202798f0a607c7412a010356b7ad8 # Parent 24bbe4e4b37b7bb72baae1474cbc8f7712e4c0d9 updated diff -r 24bbe4e4b37b -r f7de0915fff2 hws/hw02.pdf Binary file hws/hw02.pdf has changed diff -r 24bbe4e4b37b -r f7de0915fff2 hws/hw02.tex --- a/hws/hw02.tex Tue Dec 04 00:33:26 2018 +0000 +++ b/hws/hw02.tex Sat Dec 29 10:30:27 2018 +0000 @@ -35,9 +35,10 @@ expressions $r_1^*$, $r_2^*$ and $r_3^*$ each match? \item Give regular expressions for (a) decimal numbers and for - (b) binary numbers. (Hint: Observe that the empty string + (b) binary numbers. Hint: Observe that the empty string is not a number. Also observe that leading 0s are - normally not written.) + normally not written---for example the JSON format for numbers + explicitly forbids this. \item Decide whether the following two regular expressions are equivalent $(\ONE + a)^* \equiv^? a^*$ and $(a \cdot diff -r 24bbe4e4b37b -r f7de0915fff2 progs/fib.j --- a/progs/fib.j Tue Dec 04 00:33:26 2018 +0000 +++ b/progs/fib.j Sat Dec 29 10:30:27 2018 +0000 @@ -13,11 +13,55 @@ .limit stack 2 getstatic java/lang/System/out Ljava/io/PrintStream; iload 0 - i2c - invokevirtual java/io/PrintStream/print(C)V + invokevirtual java/io/PrintStream/println(I)V return .end method +.method public static writes(Ljava/lang/String;)V + .limit stack 2 + .limit locals 1 + getstatic java/lang/System/out Ljava/io/PrintStream; + aload 0 + invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V + return +.end method + +.method public static read()I + .limit locals 10 + .limit stack 10 + + ldc 0 + istore 1 ; this will hold our final integer + +Label1: + getstatic java/lang/System/in Ljava/io/InputStream; + invokevirtual java/io/InputStream/read()I + istore 2 + iload 2 + ldc 10 ; the newline delimiter + isub + ifeq Label2 + iload 2 + ldc 32 ; the space delimiter + isub + ifeq Label2 + + iload 2 + ldc 48 ; we have our digit in ASCII, have to subtract it from 48 + isub + ldc 10 + iload 1 + imul + iadd + istore 1 + goto Label2 + goto Label1 + +Label2: + iload 1 ; when we come here we have our integer computed in local variable 1 + ireturn +.end method + .method public static main([Ljava/lang/String;)V .limit locals 200 .limit stack 200 diff -r 24bbe4e4b37b -r f7de0915fff2 progs/token.scala --- a/progs/token.scala Tue Dec 04 00:33:26 2018 +0000 +++ b/progs/token.scala Sat Dec 29 10:30:27 2018 +0000 @@ -291,3 +291,19 @@ } +val fib = """ +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(env(lexing_simp(WHILE_REGS, prog2)).filterNot{_._1 == "w"}) diff -r 24bbe4e4b37b -r f7de0915fff2 slides/slides10.pdf Binary file slides/slides10.pdf has changed diff -r 24bbe4e4b37b -r f7de0915fff2 slides/slides10.tex --- a/slides/slides10.tex Tue Dec 04 00:33:26 2018 +0000 +++ b/slides/slides10.tex Sat Dec 29 10:30:27 2018 +0000 @@ -63,8 +63,8 @@ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \begin{frame}[c] - \Large\bf Are there more strings in \bf{$L(a^*)$} or - \bf{$L((a + b)^*)$}? + \Large\bf Are there more strings in \bl{$L(a^*)$} or + \bl{$L((a + b)^*)$}? \end{frame} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%