use ABNF for the grammar specification instead
ABNF has a more accepted standard than EBNF.
This commit is contained in:
parent
527561000f
commit
3836492ba2
1 changed files with 52 additions and 0 deletions
52
docs/grammar.abnf
Normal file
52
docs/grammar.abnf
Normal file
|
@ -0,0 +1,52 @@
|
||||||
|
; Rutile's grammar formal definition in ABNF
|
||||||
|
; NOTE: terminal strings are case sensitive here
|
||||||
|
|
||||||
|
function_kind = "proc" / "iter"
|
||||||
|
proc_decl = function_kind "(" [proc_decl_args] ")" [ident] *stmt 'end'
|
||||||
|
proc_decl_args = symbol_type_pair *("," symbol_type_pair)
|
||||||
|
symbol_type_pair = ident ":" ident
|
||||||
|
|
||||||
|
symbol_decl = ("var" / "let" / "const") ident_type_expr ; "Variable" declaration
|
||||||
|
ident_type_expr = ident [":" ident] ["=" expr]
|
||||||
|
|
||||||
|
function_call = ident_qualified "(" [funcargs] ")"
|
||||||
|
funcargs = expr_list
|
||||||
|
|
||||||
|
array_literal = "[" expr_list "]"
|
||||||
|
|
||||||
|
expr_list = expr *("," expr) [","] ; Allows a trailling comma
|
||||||
|
expr = number
|
||||||
|
expr =/ array_literal
|
||||||
|
expr =/ function_call
|
||||||
|
|
||||||
|
pragma = "#" "[" "]" ; TODO
|
||||||
|
decorated_decl = pragma (proc_decl / symbol_decl)
|
||||||
|
|
||||||
|
; Statements
|
||||||
|
while_stmt = "while" expr *stmt "end"
|
||||||
|
if_expr = "if" expr *stmt "end"
|
||||||
|
break_expr = "break" *expr
|
||||||
|
return_stmt = "return" *expr
|
||||||
|
yield_stmt = "yield" *expr
|
||||||
|
loop_control = "next" / break_expr
|
||||||
|
stmt = proc_decl
|
||||||
|
stmt =/ expr
|
||||||
|
stmt =/ loop_control
|
||||||
|
stmt =/ if_expr
|
||||||
|
stmt =/ while_stmt
|
||||||
|
stmt =/ return_stmt
|
||||||
|
stmt =/ yield_stmt
|
||||||
|
|
||||||
|
ident = (ALPHA / "_") *(ALPHA / DIGIT / "_" / "?" / "!")
|
||||||
|
; Identifier accounting for namespacing: std:io.print, aaa:bbb:ccc
|
||||||
|
ident_qualified = (ALPHA / "_") *(ALPHA / DIGIT / "_" / "?" / "!" / ":" / ".")
|
||||||
|
|
||||||
|
number = 1*DIGIT ; Decimal
|
||||||
|
/ "0b" 1*("0" / "1") ; Binary
|
||||||
|
/ "0o" 1*(0-8) ; Octal
|
||||||
|
/ "0x" 1*HEXDIGIT ; Hexadecimal
|
||||||
|
|
||||||
|
byte = %x00-FF
|
||||||
|
escape = "\" ("\" / DQUOTE / "0" / "a" / "b" / "n" / "r" / "t" / ("x" 1*2HEXDIGIT))
|
||||||
|
character = byte / escape
|
||||||
|
string_literal = DQUOTE *character DQUOTE
|
Loading…
Add table
Reference in a new issue