GithubHelp home page GithubHelp logo

external-lab's Introduction

External DSLs

Running the initial version of the code

You should be able to do sbt run to run an initial version of the calculator interpreter. You should also be able to do sbt test to run some auto-generated tests of the initial parser and interpreter.

Working with ScalaIDE

You should be able to do sbt eclipse to generate a ScalaIDE project. Then, you can import the project in the usual way. Once in ScalaIDE, you can run the interpreter by opening the file src/main/scala/calculator/calc.scala and running it.

Running tests in ScalaIDE: The ScalaCheck testing library doesn't seem to work well with Eclipse yet. You'll probably want to run the tests outside of Eclipse, using sbt.

Extend the calculator language to add new features

Extend the code to implement the following grammar:

        n โˆˆ ๐’ต 
e โˆˆ Expr ::= e + t | e - t | t
t โˆˆ Term ::= t * f | t / f | f
f โˆˆ Fact ::= n | ( e )

It's best to add features in the following order:

  1. subtraction
  2. multiplication
  3. division
  4. parenthetical expressions

When you add a new feature to a language, extend the implemention in the following order:

  1. Intermediate representation
    1. Data structures
    2. Sugar (if you want)
  2. Parser
    1. Tests
    2. Implementation
  3. Semantics
    1. Tests
    2. Implementation

Bonus

If you finish (or just want to explore things more), here are some options.

Better error-checking

Can you give better error-checking and error messages for the parser? For the read-eval-print loop? You could also write one or more semantic checks: a pass over the AST to check for errors, e.g., divide by literal 0.

More features

You could add more features to the language, including

  • comparisons, e.g., <, >, =, etc.
  • constants, e.g., built-in names such as ฯ€ or e
  • variables: assignment and use
  • functions (either with or without recursion)

external-lab's People

Contributors

bwiedermann avatar

Watchers

James Cloos avatar Robin Pollak avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.