Presentation is loading. Please wait.

Presentation is loading. Please wait.

Parsing Lisp Expressions

Similar presentations


Presentation on theme: "Parsing Lisp Expressions"— Presentation transcript:

1 Parsing Lisp Expressions

2 Comments These are the slides that I showed in class. My apologies for not getting them up sooner; but in the meantime I tested them (by writing the actual Java), and they are correct. My biggest debugging problems came in keeping track of where I was in the sequence of input tokens. Using a queue would have eliminated these problems.

3 parse(String) public Sexpr parse(string) { turn string into tokens
return parseOneSexpr(tokens) }

4 parseOneSexpr(tokens)
public Sexpr parseOneSexpr(tokens) { if next == integer or variable, return it else if next == '(' return parseOpenList(rest of tokens) }

5 parseOpenList(tokens)
public Sexpr parseOpenList(tokens) { if next == ')' return NIL else { Sexpr car = parseOneSexpr(some tokens) Sexpr cdr = parseOpenList(more tokens) return new Sexpr(car, cdr) }

6 The End


Download ppt "Parsing Lisp Expressions"

Similar presentations


Ads by Google