broken code, but added attempt at writing grammar

This commit is contained in:
Ellen Arvidsson 2025-04-14 17:40:22 +02:00
parent fb95e5d026
commit 20e3757f44
18 changed files with 1145 additions and 142 deletions

93
src/msph/README.md Normal file
View file

@ -0,0 +1,93 @@
# msph/micro sappho
Micro sappho is a minimalistic language for demonstration of the SPHO type
system. It is implemented using a simple parser and lexer that implements the
grammar below. The indended use is to allow experimentation and familiarization
with the SPHO types and subtyping.
## Grammar
Grammar in pseudo-bnf
```
MSph ::= Body
Body ::= Dirs
Dir ::= Typedef (directives, with lack of a better name)
| Memberdef
| Nominaldecl
| Checkdir
Typedef ::= 'type' Name '=' TExpr (type definition/binding)
| 'type' Name '[' Names ']' '=' TExpr
| 'type' Name (declaration, donno if useful)
Memberdef ::= 'member' Name ':' TExpr
Nominaldecl ::= 'nominal' Name
Checkdir ::= 'check' TExpr '<:' TExpr
TExpr ::= 'True'
| 'False'
| Var
| Nominal
| Trait
| TExpr '&' TExpr
| TExpr '|' TExpr
| TExpr '=>' TExpr
| TExpr '->' TExpr
| 'box' TExpr
| 'forall' Name '.' TExpr
| '(' TExpr ')'
Trait ::= '{' Body '}' (trait, this introduces scoping)
Var ::= Name (type variables)
Nominal ::= Name (nominal type)
Name ::= '[a-zA-Z0-9_]+' & !Reserved (name/identifier)
Reserved ::= 'type' (reserved/keywords)
| 'member'
| 'nominal'
| 'check'
| 'forall'
| 'box'
| 'True'
| 'False'
```
Precedence of binary operators:
'&' <
'|' <
'->' <
'=>'
< means "binds closer"
## Example
A simple example msph program
```
nominal ExampleN
type ExampleDecl
type ExampleDecl2
type Example = {
member example_m : C -> C
type FA = forall X. X -> X
type b = forall X. (box X => ExampleDecl) => ExampleDecl2
}
member example_global : Example & ExampleN
type TripleConj[X, Y, Z] = X & Y & Z
```