Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dankolesnikov/simplelanguage
Programming language - Scala subset
https://github.com/dankolesnikov/simplelanguage
interpreters parsing scala
Last synced: 1 day ago
JSON representation
Programming language - Scala subset
- Host: GitHub
- URL: https://github.com/dankolesnikov/simplelanguage
- Owner: dankolesnikov
- Created: 2018-04-09T03:49:36.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-04-09T10:24:19.000Z (over 6 years ago)
- Last Synced: 2024-12-14T07:30:22.995Z (20 days ago)
- Topics: interpreters, parsing, scala
- Language: Scala
- Homepage:
- Size: 2.93 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simple Language
> Programming language interpreter, similar to Scala subset## Description
A programming language interpreter developed in a Programming Paradigms class with Professor Cay Horstmann at SJSU.
Simple Language is similar to Scala subset but differs in several ways:* Only two types: integer and functions
* Defs end with semicolons
* Block has a single expression
* Function literals have syntax `{ ident, ident, ... => block }`
* `if` fakes `Boolean` similar to C: > 0 is true, <= 0 is false## Grammar
block ::= (valdef | fundef)* expr
expr ::= expr2 | "if" "(" expr ")" block "else" block
expr2 ::= term (( "+" | "-" ) term)*
term ::= factor (( "*" | "/" ) factor)*
factor ::= wholeNumber | "(" expr ")" | ident | funcall | funliteral
funcall ::= ident "(" (expr ("," expr)*)? ")"
funliteral ::= "{" (ident ("," ident)*)? "=>" block "}"
valdef ::= "val" ident "=" expr ";"
fundef ::= "def" ident "=" funliteral ";"## Examples
Simple addition and multiplication
val a = 1;
val b = 6;
a * a + b * b
Function literalval max = { x, y => if (x - y) x else y };
Higher-order function
val twoTimes = { f, x => f(f(x)) };
twoTimes({x => x * x}, 2)
Recursiondef fac = { x => if (x) x * fac(x - 1) else 1 };
**Curry**
Multiplication
val multiply = { x => { y => x * y } } ;
multiply(3)(4)Lists:
val list = 1 :: 2 :: Nil;
val y = isEmpty(list);
val x = head(1 :: Nil);### Credits
[Cay Horstmann](http://horstmann.com/), SJSU