Modify tokenizer to parse notes

This commit is contained in:
Bartłomiej Pluta
2019-07-05 18:36:12 +02:00
parent ad19e851ec
commit 425d23eb5f
9 changed files with 70 additions and 101 deletions

74
grammar
View File

@@ -1,42 +1,42 @@
integer := ...
string := ...
note := ...
identifier := ...
# Tokenizer
DIGIT = [0-9]
ID = [a-zA-Z_]
CHAR = ... \ '"'
PITCH = 'c' | 'd' | 'e' | 'f' | 'g' | 'a' | 'h'
PITCH_MODIFIER = 'b' | '#'
expr := integer
expr := string
expr := note
expr := identifier
expr := access
expr := assignment
expr := functionCall
integer := '-' DIGIT+ | DIGIT+
string := '"' CHAR* '"'
note := '@' PITCH PITCH_MODIFIER? DIGIT? ['.' DIGIT+ 'd'?]?
identifier := ID [ID|DIGIT]*
percent := DIGIT+ '%'
# left associative
access := expr '.' expr
# right associative
asterisk := expr '*' stmt
stmt := asterisk
stmt := block
stmt := return
stmt := functionDefinition
# right associative
assignment := identifier '=' expr
list := '(' ')'
list := '(' expr listTail
listTail := expr ', ' listTail
listTail := ')'
percent := integer '%'
return := 'return' expr
block := '{' stmt* '}'
# Parser
expr := integer accessTail | integer
expr := percent accessTail | percent
expr := string accessTail | string
expr := note accessTail | note
expr := identifier accessTail | identifier '=' expr | functionCall | identifier
expr := list accessTail | list
expr := functionCall accessTail | functionCall
functionCall := identifier list
functionDefinition := 'function' identifier list block
accessTail := '.' expr accessTail | e
list := '[' ']' | '[' expr listTail
listTail := expr ', ' listTail | ']'
argList := '(' ')' | '(' expr argListTail
argListTail := expr ', ' argListTail | ')'
block := '{' stmt* '}'
stmt := expr asteriskTail | expr #nie wiem czy zamiast 'expr asteriskTail' nie powinno być wprost co może wyprodukować iterator dla asterisk
asteriskTail := '*' stmt | e
stmt := block
stmt := 'return' expr
stmt := 'function' identifier list block
program := stmt*