Skip to content

Commit 78f67fc

Browse files
Merge pull request #1 from hyperpolymath/claude/wokelang-ebnf-grammar-QoeVv
WokeLang EBNF grammar specification
2 parents 60f3810 + 8fdd9ed commit 78f67fc

1 file changed

Lines changed: 294 additions & 0 deletions

File tree

grammar/wokelang.ebnf

Lines changed: 294 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,294 @@
1+
(* ============================================================================ *)
2+
(* WokeLang - Human-Centered, Consent-Driven Programming Language *)
3+
(* Complete EBNF Grammar Specification *)
4+
(* ============================================================================ *)
5+
(* *)
6+
(* Philosophy: Emotionally-Aware, Consent-First, Gratitude-Based Programming *)
7+
(* *)
8+
(* Key Features: *)
9+
(* - Natural language-style syntax *)
10+
(* - Explicit consent blocks *)
11+
(* - Built-in gratitude/attribution system *)
12+
(* - Emotional annotations (emote tags) *)
13+
(* - Physical unit system *)
14+
(* - Gentle error handling *)
15+
(* - Worker/side quest concurrency model *)
16+
(* *)
17+
(* ============================================================================ *)
18+
19+
(* --- Program Structure --- *)
20+
21+
program = { top_level_item } ;
22+
23+
top_level_item = function_def
24+
| consent_block
25+
| gratitude_decl
26+
| worker_def
27+
| side_quest_def
28+
| superpower_decl
29+
| module_import
30+
| pragma
31+
| type_def
32+
| const_def
33+
;
34+
35+
(* --- Module System --- *)
36+
37+
module_import = "use" , qualified_name , [ "renamed" , identifier ] , ";" ;
38+
39+
qualified_name = identifier , { "." , identifier } ;
40+
41+
(* --- Function Definitions --- *)
42+
43+
function_def = [ emote_tag ] ,
44+
"to" , identifier ,
45+
"(" , [ parameter_list ] , ")" ,
46+
[ "" , type ] ,
47+
"{" ,
48+
[ "hello" , string_literal , ";" ] ,
49+
{ statement } ,
50+
[ "goodbye" , string_literal , ";" ] ,
51+
"}" ;
52+
53+
parameter_list = parameter , { "," , parameter } ;
54+
55+
parameter = identifier , [ ":" , type ] ;
56+
57+
(* --- Consent System --- *)
58+
59+
consent_block = "only" , "if" , "okay" , string_literal , "{" , { statement } , "}" ;
60+
61+
(* --- Gratitude System --- *)
62+
63+
gratitude_decl = "thanks" , "to" , "{" , { gratitude_entry } , "}" ;
64+
65+
gratitude_entry = string_literal , "" , string_literal , ";" ;
66+
67+
(* --- Statements --- *)
68+
69+
statement = variable_decl
70+
| assignment
71+
| return_stmt
72+
| conditional
73+
| loop
74+
| attempt_block
75+
| consent_block
76+
| expression_stmt
77+
| worker_spawn
78+
| complain_stmt
79+
| emote_annotated_stmt
80+
;
81+
82+
variable_decl = "remember" , identifier , "=" , expression ,
83+
[ "measured" , "in" , unit_type ] , ";" ;
84+
85+
assignment = identifier , "=" , expression , ";" ;
86+
87+
return_stmt = "give" , "back" , expression , ";" ;
88+
89+
conditional = "when" , expression , "{" , { statement } , "}" ,
90+
[ "otherwise" , "{" , { statement } , "}" ] ;
91+
92+
loop = "repeat" , expression , "times" , "{" , { statement } , "}" ;
93+
94+
attempt_block = "attempt" , "safely" , "{" , { statement } , "}" ,
95+
"or" , "reassure" , string_literal , ";" ;
96+
97+
expression_stmt = expression , ";" ;
98+
99+
worker_spawn = "spawn" , "worker" , identifier , ";" ;
100+
101+
complain_stmt = "complain" , string_literal , ";" ;
102+
103+
emote_annotated_stmt = emote_tag , statement ;
104+
105+
(* --- Expressions --- *)
106+
107+
expression = logical_or ;
108+
109+
logical_or = logical_and , { "or" , logical_and } ;
110+
111+
logical_and = equality , { "and" , equality } ;
112+
113+
equality = comparison , { ( "==" | "!=" ) , comparison } ;
114+
115+
comparison = additive , { ( "<" | ">" | "<=" | ">=" ) , additive } ;
116+
117+
additive = multiplicative , { ( "+" | "-" ) , multiplicative } ;
118+
119+
multiplicative = unary , { ( "*" | "/" | "%" ) , unary } ;
120+
121+
unary = ( "not" | "-" ) , unary
122+
| primary ;
123+
124+
primary = literal
125+
| identifier
126+
| function_call
127+
| "(" , expression , ")"
128+
| unit_measurement
129+
;
130+
131+
function_call = identifier , "(" , [ argument_list ] , ")" ;
132+
133+
argument_list = expression , { "," , expression } ;
134+
135+
unit_measurement = expression , "measured" , "in" , unit_type ;
136+
137+
(* --- Pattern Matching --- *)
138+
139+
decide_stmt = "decide" , "based" , "on" , expression , "{" , { match_arm } , "}" ;
140+
141+
match_arm = pattern , "" , "{" , { statement } , "}" ;
142+
143+
pattern = literal
144+
| identifier
145+
| "_"
146+
;
147+
148+
(* --- Concurrency Primitives --- *)
149+
150+
worker_def = "worker" , identifier , "{" , { statement } , "}" ;
151+
152+
side_quest_def = "side" , "quest" , identifier , "{" , { statement } , "}" ;
153+
154+
superpower_decl = "superpower" , identifier , "{" , { statement } , "}" ;
155+
156+
(* --- Emote Tags (Emotional Annotations) --- *)
157+
158+
emote_tag = "@" , identifier , [ "(" , emote_params , ")" ] ;
159+
160+
emote_params = emote_param , { "," , emote_param } ;
161+
162+
emote_param = identifier , "=" , ( number | string_literal | identifier ) ;
163+
164+
(* --- Type System --- *)
165+
166+
type = basic_type
167+
| array_type
168+
| optional_type
169+
| reference_type
170+
;
171+
172+
basic_type = "String"
173+
| "Int"
174+
| "Float"
175+
| "Bool"
176+
| identifier
177+
;
178+
179+
array_type = "[" , type , "]" ;
180+
181+
optional_type = "Maybe" , type ;
182+
183+
reference_type = "&" , type ;
184+
185+
unit_type = identifier ; (* meters, seconds, kilograms, etc. *)
186+
187+
(* --- Type Definitions --- *)
188+
189+
type_def = "type" , identifier , "=" , type_variant , ";" ;
190+
191+
type_variant = struct_type
192+
| enum_type
193+
| type_alias
194+
;
195+
196+
struct_type = "{" , field_list , "}" ;
197+
198+
field_list = field , { "," , field } ;
199+
200+
field = identifier , ":" , type ;
201+
202+
enum_type = variant , { "|" , variant } ;
203+
204+
variant = identifier , [ "(" , type_list , ")" ] ;
205+
206+
type_list = type , { "," , type } ;
207+
208+
type_alias = type ;
209+
210+
(* --- Constants --- *)
211+
212+
const_def = "const" , identifier , ":" , type , "=" , expression , ";" ;
213+
214+
(* --- Pragmas (Caring Modes) --- *)
215+
216+
pragma = "#" , pragma_directive , ( "on" | "off" ) , ";" ;
217+
218+
pragma_directive = "care"
219+
| "strict"
220+
| "verbose"
221+
;
222+
223+
(* --- Constraints --- *)
224+
225+
constraint_block = "must" , "have" , "{" , { constraint } , "}" ;
226+
227+
constraint = expression , ";" ;
228+
229+
(* --- Literals --- *)
230+
231+
literal = number
232+
| string_literal
233+
| bool_literal
234+
| array_literal
235+
| gratitude_literal
236+
;
237+
238+
number = integer | float ;
239+
240+
integer = [ "-" ] , digit , { digit } ;
241+
242+
float = [ "-" ] , digit , { digit } , "." , digit , { digit } ;
243+
244+
string_literal = '"' , { string_char } , '"' ;
245+
246+
string_char = ? any character except '"' and '\' ?
247+
| escape_sequence ;
248+
249+
escape_sequence = "\\" , ( "n" | "t" | "r" | '"' | "'" | "\\" ) ;
250+
251+
bool_literal = "true" | "false" ;
252+
253+
array_literal = "[" , [ expression_list ] , "]" ;
254+
255+
expression_list = expression , { "," , expression } ;
256+
257+
gratitude_literal = "thanks" , "(" , string_literal , ")" ;
258+
259+
(* --- Identifiers and Keywords --- *)
260+
261+
identifier = letter , { letter | digit | "_" } ;
262+
263+
letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j"
264+
| "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t"
265+
| "u" | "v" | "w" | "x" | "y" | "z"
266+
| "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J"
267+
| "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T"
268+
| "U" | "V" | "W" | "X" | "Y" | "Z" ;
269+
270+
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
271+
272+
(* --- Reserved Keywords --- *)
273+
274+
(* Core Control Flow: to, give back, remember, when, otherwise, repeat, times *)
275+
(* Consent & Safety: only if okay, attempt safely, or reassure, complain *)
276+
(* Gratitude: thanks to, thanks *)
277+
(* Lifecycle: hello, goodbye *)
278+
(* Concurrency: worker, side quest, superpower, spawn *)
279+
(* Pattern Matching: decide based on *)
280+
(* Units: measured in *)
281+
(* Pragmas: care, strict, verbose *)
282+
(* Types: String, Int, Float, Bool, Maybe *)
283+
(* Boolean: true, false, and, or, not *)
284+
(* Constraints: must have *)
285+
286+
(* --- Comments --- *)
287+
288+
line_comment = "//" , { ? any character except newline ? } , newline ;
289+
290+
block_comment = "/*" , { ? any character ? } , "*/" ;
291+
292+
(* ============================================================================ *)
293+
(* End of WokeLang Grammar Specification *)
294+
(* ============================================================================ *)

0 commit comments

Comments
 (0)