RU beehive logo promo banner for Computing & Info Sciences
CS 380
2024fall
ibarland

Interpreting OG

OG0 Implementations

The language OG0 syntax

OG0:

<Expr> <Num> | <Paren> | <BinOp> | <IfZero> | <Nop> <Paren> bruh <Expr> slaps Interpretation: a parenthesized expression <BinOp> finna <Op> <Expr> <Expr> Interpretation: apply a binary operator <Op> rizz | drip | glow up Interpretation: addition, subtraction, multiplication (resp.) <IfZero> no cap? <Expr> ong <Expr> bet <Expr> Interpretation: if 1st-expr is 0 (within 1e-6?), eval to 2nd-expr, else 3rd-expr.

OG1:see OG2.html for details

<Op> | cancel Interpretation: “remainder1 <Expr> | <IfGE> Interpretation: “if less-than” <IfGE> vibe check <Expr> low-key <Expr> ong <Expr> bet <Expr> Interpretation: if 1st Expr is >= 2nd, result is the 3rd Expr else the 4th.

OG2:see OG2.html for details

<Expr> | <Id> | <LetExpr> Interpretation: identifier; let <LetExpr> iykyk <Id> irl <Expr> wya <Expr> Interpretation: bind Id to result of 1st Expr (the right-hand-side); then eval 2nd body Expr w/ that binding

OG4:see OG4.html for details

<Expr> | <FuncExpr> | <FuncApplyExpr> <FuncExpr> iso <Id> wya <Expr> Interpretation: a function-value, with parameter <Id> and body-<Expr>. <FuncApplyExpr> ohio <Expr> swoop <Expr> Interpretation: apply a function (1st expr) to an argument (2nd expr)

Further Details:

<Num> is any numeric literal (as written in either Java or Racket, your choice2). We'll assume that <Id>s are not one of our OG0 reserved words (like vibe checki.e. a terminal in the above grammar); you don't need to check/enforce that in your code.

Some similar(??) languages: Implementing one's own language (including let-expressions and functions) is a fairly standard exercise. For example, see Brown University's Programming Languages and Interpretation (Shriram Krishnamurthi), and Virginia Tech's OpenDSA Programming Languages textbook. Feel free to skim or read those books, esp. if wanting a different explanation from the notes in this class & its assignments.
Some similar(??) languages:

Discussion


Where we're headed


Discuss the implementation

Once we've talked in class about internal-representation (and given examples of the W programs and corresponding internal-data), then we can discuss the provided-implementation, including recursive-descent parsing:

2018 version: The videos below are based on 2018fall's language, T0. So details of the syntax are different than this semester, and some statements might have different semantics, but overall the content is extremely similar to this semester's language.


1 Like remainder, except working for negative and fractional amounts. See homework for details.      
2 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 OG0's arithmetic will be similar to IEEE floating point arithmetic (rather than perfectly-correct arithmetic).

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

     

logo for creative commons by-attribution license
This page licensed CC-BY 4.0 Ian Barland
Page last generated
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Rendered by Racket.