-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlitzMax-NG.abnf
105 lines (72 loc) · 2.75 KB
/
BlitzMax-NG.abnf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
; Status: 23/JUL/2021, Incomplete
; Please refer to ABNF definitions in RFC 5234
; CONTROL CODES
HTAB = %x09
LF = %x0A
CR = %x0D
EOL = (CR LF) / CR
; WHITESPACE
SP = %x20
WSP = HTAB / SP
LWSP = *( WSP / CR / LF )
; SYMBOLS
ALPHA = %x41-5A / %x61-7A
DIGIT = %x30-39
DOT = "."
DQUOTE = %x22
HEXDIGIT = DIGIT / "A" / "B" / "C" / "D" / "E" / "F"
VCHAR = %x21-7E
FILENAME = DIGIT / ALPHA / ("/" / "\" ) / "." / "$" / "_" / "!"
UNDERSCORE = "_"
; PROGRAM/MODULE HEADER
Program = [ Application | Module ]
Application = [Strictmode] [Framework] [*Import] [*Extern] [*Include] ApplicationBody
Module = [Strictmode] ModuleDef [*Import] [*Extern] [*Include] Block
StrictMode = "superstrict" / "strict" EOL
Framework = "framework" ModuleIdentifier EOL
Import = "import" DQUOTE FILENAME DQUOTE EOL
Include = "include" DQUOTE FILENAME DQUOTE EOL
ModuleDef = "module" ModuleIdentifier
ModuleInfo = *( "moduleinfo" string )
Extern = "extern" ["C"] *ExternStatement "endextern" / ( "end" "extern" )
ExternStatement = VarDecl / FunctionHeader "=" string EOL
ApplicationBody = Local / Global / Function / Struct / Type / BlockBody
; CONSTRUCTS
Function = FunctionHeader Block "endfunction" / ("end" "function")
FunctionHeader = "function" string [ ":" VarType ["ptr"] ] "(" Params ")"
Method = MethodHeader Block "endmethod" / ("end" "method")
MethodHeader = "method" string [ ":" VarType ["ptr"] ] "(" Params ")"
Struct = "struct" EOL *(Field VarDecl) "endstruct" / ("end" "struct")
Type = "type" string [ "extends" string ] EOL
*(Field / Const / Global / "private" / "public" / Method / Function )
"endtype" / ("end" "type")
VarType = "byte" / "int" / "string" / "double" / "float" / "size_t"
Comment = "'" *( WSP / string ) EOL
Remark = "rem" *( WSP / VCHAR / EOL ) "endrem" / ( "end" "rem")
For = "for" ["local"] Name ":" VarType "=" ( "eachin" Name ) / ( Number ("to"/"until"/"downto") Number ) EOL Block "next" EOL
Repeat = "repeat" EOL Block ("until" Condition) / "forever" EOL
While = "while" Condition EOL Block "wend" EOL
; VARIABLE DECLARATION
Local = "local" VarDeclarations
Field = "field" VarDeclarations
Global = "global" VarDeclarations
VarDeclarations = VarDecl *[ "," VarDecl ]
; SOURCE CODE BODY
BlockBody = *VCHAR
; NOT SURE WHAT TO CALL THESE
boolean = "true" / "false"
double = *DIGIT "." *DIGIT
float = *DIGIT "." *DIGIT
integer = *DIGIT
string = DQUOTE *( ALPHA / DIGIT / SP ) DQUOTE
ModuleIdentifier = Name DOT Name
Name = ALPHA *(ALPHA / DIGIT / UNDERSCORE )
Number = double / float / integer
VarDecl = Name ":" VarType [ "=" Expression ]
; Define Tokens identified by Lexer
; Status: Incomplete and not implemented
TOKENS = [ RESERVED ]
RESERVED = ["superstrict"/"strict"/"framework"/"import"/"include"]
lbrace = "("
rbrace = ")"
comma = ","