---
# System prepended metadata

title: SPO Exercises Lecture 7

---

# SPO Exercises Lecture 7

## Exercise 9 p. 175
![](https://i.imgur.com/KfeJBPt.png)

``` java 
public static String code = "fancy code"
public static String currentTerminal = "", nextTerminal = "";
public static int currentTerminalIndex = 0;
    
public static void main(String[] args) {
    
}

public AST parseStmt() {
    if(currentTerminal == "id" && nextTerminal == ";") {
        accept("id");
        accept(";");
    } else if(currentTerminal == "id" && nextTerminal == "(") {
        accept("id");
        accept("(");
        parseIdList();
        accept(")");
        accept(";");
    } else {
        error();
    }
}
public AST parseIdList() {
    if(currentTerminal == "id") {
        if(nextTerminal == ",") {
            accept("id");
            accept(",");
            parseIdList();
        } else {
            accept("id");
        }
    } else {
        error();
    }
}

public AST accept(String token) {
    
}
public void error() {
    System.out.println("Fuck you");
}

class AST {
    private AST subtrees;
    public AST(AST[] subtrees) {
        this.subtrees = subtrees;
    }
}
```

## Exercise 10 p. 175
![](https://i.imgur.com/KSMEEoQ.png)
![](https://i.imgur.com/DrMVq4p.png)

