-
Notifications
You must be signed in to change notification settings - Fork 1
/
nsl.bnf
105 lines (76 loc) · 3.58 KB
/
nsl.bnf
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
nsl-syntax ::= { <top-declarator> }*
top-declarator ::= <declare-definition>
| <module-definition>
| <macro>
declare-definition ::= "declare" <identifire> "{" { <interfaces-definition> }* "}"
interfaces-definition ::= <io-width-definition>
| <io-function-declarator>
io-width-definition ::= <io-wire> <identifire> <width-defitinion> ";"
io-wire ::= "input"
| "inout"
| "output"
width-definition ::= {[ "[" <width-expression> "]" ]}*
width-expression ::= <number>
| <identifire>
| <width-expression> <operator> <width-expression>
operator ::= "/"
| "*"
| "+"
| "-"
| "<<"
| ">>"
| "^"
| "~"
function-args ::= [ <identifire> { "," <identifire> }* ]
function-return ::= [ ":" <identifire> ]
io-function-declarator ::= <io-function> <identifire> [ "(" <function-args> ")" [ <function-return> ] ] ";"
io-function ::= "func_in"
| "func_out"
module-definition ::= "module" <identifire> "{" <module-expression> "}"
module-expression ::= { <reg-wire-module-declaration> }* { <module-behavior> }*
reg-wire-module-declaration ::= <reg-wire-definition>
| <module-declaration>
| <struct-wire-reg-declaration>
| <proc-declaration>
| <state-declaration>
| <func-declaration>
| <memory-declaration>
reg-wire-definition ::= <reg-wire> <identifire> <width-declarator> [ "," <identifire> <width-declarator> ] ";"
reg-wire ::= "reg" | "wire"
module-declaration ::= <identifire> <identifire> ";"
struct-wire ::= <identifire> <reg-wire> <identifire> ";"
proc-declaration ::= "proc_name" <proc-information> { "," <proc-information> }* ";"
proc-information ::= <identifire> "(" <function-args> ")"
state-declaration ::= "state_name" <identifire> { "," <identifire> }* ";"
func-declaration ::= "func_self" <identifire> "(" <function-args> ")" <function-return> ";"
memory-declaration ::= "mem"
module-behavior ::= <assignment-expression>
| <state-expression>
| <proc-expression>
| <if-declaration>
| <expression>
| <return-declaration>
assignment-expression ::= <wire-reg-assignment> | <expression>
wire-reg-assignment ::= <identifire> <assigner> <expression> ";"
assigner ::= "=" | ":="
expression ::= <number>
| <identifire>
| <func-expression>
| <expression> <operator> <expression>
| <expression> [ "[" <expression> [ ":" <expression> ] "]" ]
func-expression ::= <identifire> "(" <function-args> ")"
; --- macros ---
macro ::= "#" <macro-syntax> <newline>
macro-syntax ::= <macro-define>
| <macro-include>
| <macro-ifdef>
| <macro-ifndef>
| <macro-undef>
| "else"
| "endif"
macro-define ::= "define" <identifire> <define-pattern>
define-pattern ::= ?any-thing?
macro-include ::= "include" "\"" <file-path> "\""
macro-ifdef ::= "ifdef" <identifire>
macro-ifndef ::= "ifndef" <identifire>
macro-undef ::= "undef" <identifire>