This document was automatically generated by the BNF-Converter. It was generated together with the lexer, the parser, and the abstract syntax module, which guarantees that the document matches with the implementation of the language (provided no hand-hacking has taken place).
Identifiers Ident are unquoted strings beginning with a letter,
followed by any combination of letters, digits, and the characters _ '
reserved words excluded.
Integer literals Integer are nonempty sequences of digits.
Character literals Char have the form
'
c'
, where c is any single character.
Double-precision float literals Double have the structure
indicated by the regular expression digit+ '.' digit+ ('e' ('-')? digit+)?
i.e.\
two sequences of digits separated by a decimal point, optionally
followed by an unsigned or negative exponent.
String literals String have the form
"
x"
}, where x is any sequence of any characters
except "
unless preceded by \
.
The set of reserved words is the set of terminals appearing in the grammar. Those reserved words that consist of non-letter characters are called symbols, and they are treated in a different way from those that are similar to identifiers. The lexer follows rules familiar from languages like Haskell, C, and Java, including longest match and spacing conventions.
The reserved words used in StarsepLang are the following:
assert |
auto |
bool |
char |
elif |
else |
false |
float |
fn |
for |
if |
in |
int |
let |
list |
loop |
print |
return |
string |
true |
void |
while |
The symbols used in StarsepLang are the following:
( | ) | , | { |
} | = | ++ | -- |
; | < | > | -> |
[ | ] | - | ! |
$ | && | | | ? | |
: | + | * | / |
% | <= | >= | == |
!= | += | -= | *= |
/= | %= |
Single-line comments begin with #, //.Multiple-line comments are enclosed with /* and */.
Non-terminals are enclosed between < and >. The symbols -> (production), | (union) and eps (empty rule) belong to the BNF notation. All other symbols are terminals.
Program | -> | [FnDef] |
FnDef | -> | Type Ident ( [Arg] ) Block |
[FnDef] | -> | FnDef |
| | FnDef [FnDef] | |
Arg | -> | Type Ident |
[Arg] | -> | eps |
| | Arg | |
| | Arg , [Arg] |
|
FunExec | -> | Ident ( [Expr] ) |
Block | -> | { [Stmt] } |
Stmt | -> | Block |
| | Oper ; |
|
| | while Expr Block |
|
| | for Oper ; Expr ; Oper Block |
|
| | for Ident in Expr Block |
|
| | loop Block |
|
| | IfStmt | |
| | IfElseStmt | |
[Stmt] | -> | eps |
| | Stmt [Stmt] | |
Oper | -> | Type [Item] |
| | let [Item] |
|
| | auto [Item] |
|
| | Ident AssOp Expr | |
| | Ident ++ |
|
| | Ident -- |
|
| | return Expr |
|
| | return |
|
| | FunExec | |
| | print ( Expr ) |
|
| | assert ( Expr ) |
|
Item | -> | Ident |
| | Ident = Expr |
|
[Item] | -> | Item |
| | Item , [Item] |
|
IfStmt | -> | IfStmt elif Expr Block |
| | if Expr Block |
|
IfElseStmt | -> | IfStmt else Block |
Type | -> | int |
| | char |
|
| | string |
|
| | bool |
|
| | float |
|
| | void |
|
| | fn < [Type] > |
|
| | list < Type > |
|
[Type] | -> | Type |
| | Type -> [Type] |
|
Expr8 | -> | FunExec |
| | Type [ [Expr] ] |
|
| | Ident | |
| | Integer | |
| | Char | |
| | Double | |
| | String | |
| | false |
|
| | true |
|
| | ( Expr ) |
|
Expr7 | -> | - Expr8 |
| | ! Expr8 |
|
| | Expr8 | |
Expr6 | -> | Expr6 MulOp Expr7 |
| | Expr7 | |
Expr5 | -> | Expr5 AddOp Expr6 |
| | Expr6 | |
Expr4 | -> | Expr5 ++ Expr4 |
| | Expr5 $ Expr4 |
|
| | Expr5 | |
Expr3 | -> | Expr3 RelOp Expr4 |
| | Expr4 | |
Expr2 | -> | Expr3 && Expr2 |
| | Expr3 | |
Expr1 | -> | Expr2 || Expr1 |
| | Expr2 | |
Expr | -> | Expr1 ? Expr1 : Expr1 |
| | Expr1 | |
[Expr] | -> | eps |
| | Expr | |
| | Expr , [Expr] |
|
AddOp | -> | + |
| | - |
|
MulOp | -> | * |
| | / |
|
| | % |
|
RelOp | -> | < |
| | <= |
|
| | > |
|
| | >= |
|
| | == |
|
| | != |
|
AssOp | -> | = |
| | += |
|
| | -= |
|
| | *= |
|
| | /= |
|
| | %= |