-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparseed_grammar.txt
78 lines (46 loc) · 3.19 KB
/
parseed_grammar.txt
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
; this file will be updated throughout the developpement of parseed
<statements> ::= <statement>+
<statement> ::= <bitfield_stmt> | <struct_stmt>
; bitfield
<bitfield_stmt> ::= <endian>+ "bitfield" <identifier> "{" <bitfield_member_def>+ "}"
| <endian>+ "bitfield" <identifier> "(" <no_identifier_expr> ")" "{" <bitfield_member_def>+ "}"
<bitfield_member_def> ::= <identifier> "(" <no_identifier_expr> ")"? ","
; struct
<struct_stmt> ::= <endian>+ "struct" <identifier> "{" (<struct_member_def> | <match_stmt>)+ "}"
<struct_member_type> ::= (<endian> | <ternary_endian>)+ (<data_type> | <ternary_data_type> | <identifier>)
| (<endian> | <ternary_endian>)+ (<data_type> | <ternary_data_type> | <identifier>) "[" <expr> "]"
| (<endian> | <ternary_endian>)+ (<data_type> | <ternary_data_type> | <identifier>) "[" <comparison> "]" ;; repeat until the comparison is false
| (<endian> | <ternary_endian>)+ (<data_type> | <ternary_data_type> | <identifier>) "[]" ;; repeat this member as much as possible
<struct_member_def> ::= <struct_member_type> <identifier> ","
<match_stmt> ::= "match (" <expr> ") {" (<expr> ":" <struct_member_type> ",")+ "}" <identifier> ","
| "match (" <expr> ") {" (<expr> ": {" <struct_member_def>+ "},")+ "}," ;; multiple members in the match case
; expressions
<expr> ::= <term> (("+" | "-" | <logical_operator>) <term>)*
<term> ::= <factor> (("*" | "/") <factor>)*
<factor> ::= <num_int> | <num_float>
| ("+" | "-" | <logical_operator>) <factor>
| "(" <expr> ")"
| <identifier> ("." <identifier>)*
<no_identifier_expr> ::= <no_identifier_term> (("+" | "-" | <logical_operator>) <no_identifier_term>)*
<no_identifier_term> ::= <no_identifier_factor> (("*" | "/") <no_identifier_factor>)*
<no_identifier_factor> ::= <num_int> | <num_float>
| ("+" | "-" | <logical_operator>) <no_identifier_factor>
| "(" <no_identifier_expr> ")"
<logical_operator> ::= "&" | "|" | "^" | "<<" | ">>" | "~"
; comparisons
<comparison> ::= <expr> <comparison_operator> <expr>
<comparison_operator> ::= "<=" | "<" | "==" | ">" | ">=" | "!=" | "&&" | "||"
; endianness
<endian> ::= "LE" | "BE"
<ternary_endian> ::= "(" <comparison> "?" <endian> ":" <endian> ")"
; data-types
<data_type> ::= <string_data_type> | <bytes_data_type> | "uint8" | "int8" | "uint16" | "int16" | "uint24" | "int24" | "uint32" | "int32" | "uint40" | "int40" | "uint48" | "int48" | "uint64" | "int64" | "uint128" | "int128" | "float" | "double"
<ternary_data_type> ::= "(" <comparison> "?" (<data_type>|<identifier>) ":" (<data_type>|<identifier>) ")"
<string_data_type> ::= "string" ( '(' (<num_int> | <string> | <char> | <identifier>) ')' )? ;; "string" or "string(delimitor)"
<bytes_data_type> ::= "bytes(" (<num_int> | <string> | <char> | <identifier>) ")" ;; "bytes(delimitor)"
; identifier and numbers
<identifier> ::= (("_" | [a-z] | [A-Z])+)+ (("_" | "-" | [0-9] | [a-z] | [A-Z])+)+
<num_float> ::= <num_int> "." <num_int>
<num_int> ::= ([0-9])+ | "\x" [0-9]{1,2}
<char> ::= "'" [:print:] "'" | "'\" ([0-9]){1-} "'"
<string> ::= """ [:print:]+ """