RU beehive logo ITEC dept promo banner
ITEC 380
2014fall
ibarland

homelecturesrecipeexamshwsD2Lbreeze (snow day)

P0
Interpreting P

The language P0

  Expr      ::= Num | ParenExpr | BinExpr | WhenZExpr
  ParenExpr ::= < Expr > 
  BinExpr   ::= (: Expr BinOp Expr :)
  WhenZExpr ::= whenz Expr then Expr otherwise Expr !
  BinOp     ::= +++ | --- | *** 
where Num is any numeric literal (as written in either Java or Racket, your choice1). For the provided parsers to work, whitespace is required between all terminals with the exception of non-binary-operator punctuation.

Here is a Racket interpreter for P0 along with a scanner for racket (with an a scanner demo) and expr-test-P0.rkt (which requires the latest student-extras.rkt).
Here is a java interpreter for P0 (P0-java.jar or browse); it includes unit tests, and helpful Java parsing functions.


1

This is so we can just use our language's built-in number-parsing functions, without getting bogged down in tokening input. So racket implementations will allow exactly those strings recognized by number?, (including +nan.0, -inf.0, and 2+3i).

Similarly, if using Java, the semantics of P0's arithmetic will be similar to IEEE floating point arithmetic (rather than perfectly-correct arithmetic).

Don't confuse P0's class Num (which extends Expr) with the existing java.lang.Number, which doesn't extend Expr.

     

homelecturesrecipeexamshwsD2Lbreeze (snow day)


©2014, Ian Barland, Radford University
Last modified 2014.Nov.09 (Sun)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.