Files
smnp-py/grammar
Bartłomiej Pluta fd9f240ce5 Update grammar
2019-07-07 12:43:45 +02:00

57 lines
1.8 KiB
Plaintext

# Tokenizer
DIGIT = [0-9]
ID = [a-zA-Z_]
CHAR = ... \ '"'
PITCH = 'c' | 'd' | 'e' | 'f' | 'g' | 'a' | 'h'
PITCH_MODIFIER = 'b' | '#'
<integer> ::= '-' DIGIT+ | DIGIT+
<string> ::= '"' CHAR* '"'
<note> ::= '@' PITCH PITCH_MODIFIER? DIGIT? [':' DIGIT+ 'd'?]?
<identifier> ::= ID [ID|DIGIT]*
<type> ::= 'integer' | 'string' | 'note' | 'list' | 'void'
# Parser
<expr> ::= <integer> <access> | <integer>
<expr> ::= <string> <access> | <string>
<expr> ::= <note> <access> | <note>
<expr> ::= <identifier> <access> | <identifier> '=' <expr> | <functionCall> | <identifier>
<expr> ::= <list> <access> | <list>
<expr> ::= <expr> '.' <identifier> | <expr> '.' <functionCall>
<expr> ::= <asteriskExpr> '*' <expr>
<asteriskExpr> ::= <integer> | <string> | <note> | <identifier> | <list>
<functionCall> ::= <identifier> <arglist>
<list> ::= '[' ']' | '[' <expr> <listTail>
<listTail> ::= <expr> ', ' <listTail> | ']'
<arglist> ::= '(' ')' | '(' <expr> <arglistTail>
<arglistTail> ::= <expr> ', ' <arglistTail> | ')'
<argdeflist> ::= '(' ')' | '(' <typedVariable> <argdeflist>
<argdeflist> ::= <typedVariable> ', ' <argdeflist> | ')'
<typedVariable> ::= <type> <typeSpecifier>? <identifier>
<typeSpecifier> ::= '<' '>' | '<' <typeSpecifierItem> <typeSpecifierTail>
<typeSpecifierTail> ::= <typeSpecifierItem> ', ' <typeSpecifierTail> | '>'
<typeSpecifierItem> ::= <type> | <type> <typeSpecifier>
<block> ::= '{' <stmt>* '}'
<stmt> ::= <block>
<stmt> ::= 'return' <expr>
<stmt> ::= <expr>
<functionDefinition> ::= 'function' <identifier> <list> <block>
<extend> ::= 'extend' <type> 'as' <identifier> '{' <functionDefinition> '}'
<import> ::= 'import' <string> | 'import' <type> 'from' <string> 'as' <identifier>
<programItem> ::= <stmt> | <expr> | <import> | <functionDefinition> | <extend>
<program> ::= <programItem>*