|
11 | 11 | 此项目目前处于早期开发阶段,不建议用于生产环境。 |
12 | 12 | [项目地址](https://github.com/Pivot-Studio/pivot-lang) |
13 | 13 |
|
14 | | -## 安装 |
15 | | -见[此处](https://lang.pivotstudio.cn/tutorial/installation.html) |
16 | | - |
17 | | -## 文档地址 |
18 | | -https://lang.pivotstudio.cn |
19 | | - |
20 | | -## CONTRIBUTING |
21 | | -[CONTRIBUTING](CONTRIBUTING.md) |
22 | | -中文见[此处](https://lang.pivotstudio.cn/CONTRIBUTING-CN.html) |
23 | | -欢迎加入[社区群](https://jq.qq.com/?_wv=1027&k=I5vdShVl) |
24 | | - |
25 | | -## dependencies |
26 | | -- [llvm-14](https://github.com/llvm/llvm-project/releases/tag/llvmorg-14.0.6) |
27 | | -- [rust](https://www.rust-lang.org/) |
28 | | - |
29 | | -**重要**:如果你想参与开发,请先在项目目录`make vm install`,然后根据自己是linux还是mac运行`make devlinux`或者`make devmac` |
30 | | - |
31 | | -## 特点 |
32 | | -- 静态编译(jit模式与immix gc不兼容,因为llvm生成自定义stackmap[目前必需要静态编译](https://llvm.org/docs/GarbageCollection.html#emitting-assembly-code-gcmetadataprinter)) |
33 | | -- 极其方便的rust互操作 |
34 | | -- 支持debug |
35 | | -- 支持lsp,自带vsc插件,能提供优秀的代码支持 |
36 | | - |
37 | | - |
38 | | -## 项目结构 |
39 | | - |
40 | | -- [vm](vm) 包含rumtime |
41 | | -- [src](src) 编译器源码所在 |
42 | | -- [internal_macro](internal_macro) 内部过程宏 |
43 | | - |
44 | | -## grammar |
45 | | - |
46 | | -```ebnf |
47 | | -add_exp = |
48 | | - | mul_exp ("+" | "-" add_exp)? |
49 | | - ; |
50 | | -
|
51 | | -mul_exp = |
52 | | - | unary_exp ("*"|"/" mul_exp)? |
53 | | - ; |
54 | | -
|
55 | | -unary_exp = |
56 | | - | pointer_exp |
57 | | - | ("-" | "!") pointer_exp |
58 | | - ; |
59 | | -
|
60 | | -
|
61 | | -pointer_exp = ("&"|"*")* complex_exp; |
62 | | -
|
63 | | -complex_exp = primary_exp (take_exp_op|array_element_op|call_function_op)*; |
64 | | -
|
65 | | -take_exp_op = ("." identifier) ; |
66 | | -
|
67 | | -array_element_op = ('[' logic_exp ']') ; |
68 | | -
|
69 | | -call_function_op = ("(" (logic_exp (","logic_exp)*)? ")") ; |
70 | | -
|
71 | | -primary_exp = |
72 | | - | number |
73 | | - | bool_const |
74 | | - | parantheses_exp |
75 | | - | extern_identifier |
76 | | - | struct_init_exp |
77 | | - | string_literal |
78 | | - ; |
79 | | -
|
80 | | -parantheses_exp = "(" logic_exp ")"; |
81 | | -
|
82 | | -number = [0-9]+ ("." number)? ; |
83 | | -
|
84 | | -identifier = [a-zA-Z_][a-zA-Z0-9_]* ; |
85 | | -
|
86 | | -extern_identifier = (identifier "::")* identifier ; |
87 | | -
|
88 | | -bool_const = |
89 | | - | "true" |
90 | | - | "false" |
91 | | - ; |
92 | | -
|
93 | | -compare_exp = |
94 | | - | add_exp (("<=" | "<"|">="|">"|"=="|"!=") add_exp)* |
95 | | - ; |
96 | | -
|
97 | | -logic_exp = |
98 | | - | compare_exp (("&&"|"||") compare_exp)* |
99 | | - ; |
100 | | -
|
101 | | -struct_init_exp = |
102 | | - | type_name "{" (struct_init_exp_field ("," struct_init_exp_field)* )? "}" |
103 | | - ; |
104 | | -
|
105 | | -struct_init_exp_field = identifier ":" logic_exp ; |
106 | | -
|
107 | | -assignee = pointer_exp; |
108 | | -
|
109 | | -assignment = assignee "=" logic_exp ; |
110 | | -
|
111 | | -new_variable = "let" identifier "=" logic_exp ; |
112 | | -
|
113 | | -global_variable = "const" identifier "=" logic_exp ; |
114 | | -
|
115 | | -if_statement = "if" logic_exp statement_block ("else" if_statement | statement_block)?; |
116 | | -
|
117 | | -while_statement = "while" logic_exp statement_block ; |
118 | | -
|
119 | | -for_statement = "for" (assignment | new_variable) ";" logic_exp ";" assignment statement_block; |
120 | | -
|
121 | | -statement_block = "{" statements "}" ; |
122 | | -
|
123 | | -impl_block = "impl" extern_identifier "{" function_def* "}" ; |
124 | | -
|
125 | | -statements = statement* ; |
126 | | -
|
127 | | -break_statement = "break" ";" ; |
128 | | -
|
129 | | -continue_statement = "continue" ";" ; |
130 | | -
|
131 | | -statement = |
132 | | - | assignment ";" |
133 | | - | new_variable ";" |
134 | | - | return_statement |
135 | | - | if_statement |
136 | | - | while_statement |
137 | | - | break_statement |
138 | | - | continue_statement |
139 | | - | complex_exp ";" |
140 | | - ; |
141 | | -
|
142 | | -toplevel_statement = |
143 | | - | struct_def |
144 | | - | function_def |
145 | | - | global_variable |
146 | | - | use_statement ";" |
147 | | - ; |
148 | | -
|
149 | | -program = toplevel_statement* ; |
150 | | -
|
151 | | -function_def = "fn" identifier "(" (typed_identifier (","typed_identifier)*)? ")" type_name (statement_block | ";") ; |
152 | | -
|
153 | | -generic_type = "<" type_name ("|" type_name)* ">" ; |
154 | | -
|
155 | | -generic_type_def = "<" identifier ("|" identifier)* ">" ; |
156 | | -
|
157 | | -struct_def = "struct" identifier generic_type_def? "{" struct_field* "}" ; |
158 | | -
|
159 | | -type_name = "*"* extern_identifier ; |
160 | | -
|
161 | | -typed_identifier = identifier ":" type_name ; |
162 | | -
|
163 | | -struct_field = typed_identifier ";" ; |
164 | | -
|
165 | | -return_statement = "return" logic_exp ";" ; |
166 | | -
|
167 | | -use_statement = "use" identifier ("::" identifier)* ";" ; |
168 | | -
|
169 | | -string_literal = "\"" [^"]* "\"" ; |
170 | | -
|
171 | | -trait_def = "trait" identifier generic_type_def? (":" type_add)? "{" function_def* "}" ; |
172 | | -
|
173 | | -type_add = type_name ("+" type_name)* ; |
174 | | -
|
175 | | -macro_match_exp = |
176 | | - | any_exp_except_dollar_and_parantheses |
177 | | - | "$" identifier ":" tp |
178 | | - | "(" macro_match_exp * ")" "*" |
179 | | - | "(" macro_match_exp * ")" "+" |
180 | | - | "(" macro_match_exp * ")" |
181 | | - ; |
182 | | -
|
183 | | -macro_match_arm = "(" macro_match_exp* ")" "=>" statement_block ; |
184 | | -``` |
| 14 | +## 官网 |
| 15 | +[https://lang.pivotstudio.cn](https://lang.pivotstudio.cn) |
0 commit comments