Skip to content

hmc-cs111-fall2014/variables-and-functions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Garden

Garden is a small, garden-variety language to demonstrate how to implement variables and functions. (Note, this is only one way of implementing these language features. Another good resource is the book Language Implementation Patterns).

Syntax

Garden supports expressions, printing, sequencing, conditionals, variable declarations, assignment, function definitions, and function calls.

The abstract syntax for Garden is:

         n ∈ ℤ  x,f ∈ Name

s ∈ Stmt ::= print e | s ; s
          |  if0 (e) then {s} else {s}
          |  var x := e | x := e
          |  def f(x) := {s} | f(e)

e ∈ Expr ::= n | x | e op e | ( e )

op ∈ Operator ::= + | - | * | /

Semantics and Prolog Implementation

The language includes a formal semantics, specified as comments in a Prolog file. The file also includes a Prolog implementation of the semantics.

Scala Implementation

The bulk of this repository contains a Scala implementation of Garden. You can start a read-eval-print loop for Garden by executing

sbt run

from the top-level directory (i.e., the one that contains this file).

You can run the included test suite by executing

sbt test

from the top-level directory (i.e., the one that contains this file).

The Scala implementation adds some syntactic sugar to the language:

  • It supports blocks of statements (i.e., sequencing of an arbitrary number of statements).
  • It supports functions with multiple parameters

Growing a Garden

The repository has several tags, which correspond to different versions of Garden, as it grows from the expression language to its full syntax. The tags are

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors