initial commit, finished 1a 1b
This commit is contained in:
106
index.typ
Normal file
106
index.typ
Normal file
@@ -0,0 +1,106 @@
|
|||||||
|
#import "@preview/codly:1.3.0": *
|
||||||
|
#import "@preview/codly-languages:0.1.1": *
|
||||||
|
#import "@preview/catppuccin:1.0.1": catppuccin, flavors
|
||||||
|
|
||||||
|
#show: codly-init.with()
|
||||||
|
#show: catppuccin.with(flavors.latte)
|
||||||
|
|
||||||
|
#codly(languages: codly-languages)
|
||||||
|
|
||||||
|
= Exercise 01
|
||||||
|
|
||||||
|
#let question(body) = block(
|
||||||
|
fill: luma(240),
|
||||||
|
inset: 8pt,
|
||||||
|
radius: 4pt
|
||||||
|
)[
|
||||||
|
#body
|
||||||
|
]
|
||||||
|
|
||||||
|
== 01 Grundbegriffe
|
||||||
|
|
||||||
|
=== Task a
|
||||||
|
|
||||||
|
#question[
|
||||||
|
Wie lang (in Terminalsymbolen) ist der kürzeste Satz in MicroJava, der mindestens ein Tilde (“∼”)
|
||||||
|
enthält? Geben Sie ein Beispiel für einen Satz dieser Länge an. Der Satz muss nur syntaktisch korrekt
|
||||||
|
(entspricht der Grammatik) sein, nicht semantisch (hält alle Kontextbedingungen der Sprache ein). Bei-
|
||||||
|
spielsweise ist x = x + 1, ohne x zuvor zu definieren, eine syntaktisch korrekte Zuweisung, semantisch
|
||||||
|
korrekt ist sie aber nicht.
|
||||||
|
]
|
||||||
|
|
||||||
|
```java
|
||||||
|
x[~1]++;
|
||||||
|
```
|
||||||
|
|
||||||
|
The statement above contains the following tokens:
|
||||||
|
|
||||||
|
- x (iden, terminal)
|
||||||
|
- "\[" (literal, terminal)
|
||||||
|
- "~" (literall, terminal)
|
||||||
|
- 1 (number, terminal)
|
||||||
|
- "\]" (literal, terminal)
|
||||||
|
- "++" (literal, terminal)
|
||||||
|
- ";" (literal, terminal)
|
||||||
|
|
||||||
|
To sum it up the statement has a `~` and has a terminal symbol count of 7.
|
||||||
|
|
||||||
|
=== Task b
|
||||||
|
|
||||||
|
#question[
|
||||||
|
Sind die Nonterminalsymbole Statement und ActPars rekursiv? Wenn ja, geben Sie alle Rekursionen-
|
||||||
|
arten an (Transitivität: direkt, indirekt; Orientierung: links, rechts, zentral). Beispiele für Rekursionsarten
|
||||||
|
sind direkt zentralrekursiv, indirekt linksrekursiv, . . . Pro NT kann es mehrere Rekursionsarten geben.
|
||||||
|
Geben Sie bei indirekten Rekursionen einen möglichen Pfad an (Beispiel: Factor ist indirekt zentralre-
|
||||||
|
kursiv über Factor -> Expr -> Term -> Factor).
|
||||||
|
]
|
||||||
|
|
||||||
|
==== Statement
|
||||||
|
|
||||||
|
The relevant Productions for the Statement Symbol are:
|
||||||
|
|
||||||
|
```
|
||||||
|
Statement = Designator ( Assignop Expr | ActPars | "++" | "--" ) ";"
|
||||||
|
| "if" "(" Condition ")" Statement [ "else" Statement ]
|
||||||
|
| "while" "(" Condition ")" Statement
|
||||||
|
| "break" ";"
|
||||||
|
| "return" [ Expr ] ";"
|
||||||
|
| "read" "(" Designator ")" ";"
|
||||||
|
| "print" "(" Expr [ "," number ] ")" ";"
|
||||||
|
| Block
|
||||||
|
| ";".
|
||||||
|
|
||||||
|
Block = "{" { Statement } "}".
|
||||||
|
```
|
||||||
|
|
||||||
|
We have the following Recursions:
|
||||||
|
|
||||||
|
- line 2: Statement is directly central recursive
|
||||||
|
- line 3: Statement is directly right recursive
|
||||||
|
- line 8: Block is indirectly central recursive
|
||||||
|
|
||||||
|
|
||||||
|
==== ActPars
|
||||||
|
|
||||||
|
The relevant Productions for the ActPars Symbol are:
|
||||||
|
|
||||||
|
```
|
||||||
|
ActPars = "(" [ Expr { "," Expr } ] ")".
|
||||||
|
|
||||||
|
Expr = [ "–" ] Term { Addop Term }.
|
||||||
|
|
||||||
|
Term = Factor { Mulop Factor }.
|
||||||
|
|
||||||
|
Factor = Designator [ ActPars ]
|
||||||
|
| number
|
||||||
|
| charConst
|
||||||
|
| "new" ident [ "[" Expr "]" ]
|
||||||
|
| "(" Expr ")".
|
||||||
|
```
|
||||||
|
|
||||||
|
We have the following Recursion:
|
||||||
|
|
||||||
|
- line 1: Factor is indirectly central recursive
|
||||||
|
|
||||||
|
=== Task c
|
||||||
|
|
||||||
Reference in New Issue
Block a user