develop syntax spec

This commit is contained in:
2025-11-17 09:38:37 +09:00
parent 682cbdc216
commit 2abfa54890
2 changed files with 21 additions and 7 deletions

View File

@@ -22,13 +22,15 @@
## Syntax Spec ## Syntax Spec
``` ```spec
program := defn* program := defn*
defn := VAL type ID ; defn := VAL type ID ;
| VAL type ID expr ; | VAL type ID expr ;
type := ID | [] | [type] | [ type* ARROW type? ] type := ID | type STAR
| LBRACK RBRACK | LBRACK type RBRACK
| LBRACK type* ARROW type? RBRACK
expr := atom atom* expr := atom atom*
@@ -37,13 +39,19 @@ atom := ID
| STR | STR
| lambda | lambda
| compound | compound
| reference | STAR
| dereference | ANDREF
stmt := defn stmt := defn
| expr ; // expr statement | expr ; // expr statement
| return expr ; // return statement | return expr ; // return statement
| $ ID expr ; // assignment statement | DOLLAR ID expr ; // assignment statement
| if expr compound ; // if statement | if expr compound ; // if statement
| if expr compound else compound ; // if-else statement | if expr compound else compound ; // if-else statement
```
param_list := LPAREN (type ID)* RPAREN
lambda := param_list compound
compound := LCURLY (stmt)* expr? RCURLY
```

View File

@@ -18,4 +18,10 @@ val [->int] main {
fib n fib n
}; };
} }
}; };
val [char * int->char]get_char_of(char* s int index) {
return * {
add s index
};
}