forked from nez-peg/nez-grammar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c.nez
596 lines (571 loc) · 24 KB
/
c.nez
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
// C (ISO/IEC 9899:2011)
// ===============
//
// Based on grammar from ISO/IEC 9899:2011 [1].
//
// Limitations:
//
// * Non-BMP characters are completely ignored to avoid surrogate pair
// handling.
//
// Many thanks to inimino [3] for his grammar [4] which helped me to solve some
// problems (such as automatic semicolon insertion) and also served to double
// check that I converted the original grammar correctly.
//
// [1] ISO/IEC 9899:2011
File = _ { ( $(TopLevel) / _ )* #Source } EOT
_ = ( S / BLOCKCOMMENT / LINECOMMENT / ATTRIBUTE )*
S = [ \n\r\t\u000B\u000C]
BLOCKCOMMENT = '/*' ( !'*/' . )* '*/'
LINECOMMENT = '//' ( !'\n' . )*
/ "#" ( &'\\\n' . . / !'\n' . )*
ATTRIBUTE = '__attribute__' !W _ '((' ATTRIBUTECONTENT '))' _
/ '__asm' !W _ '(' ( !')' . )* ')' _
ATTRIBUTECONTENT = NAME _ '(' ('"' STRING_CONTENT* '"' / ( !')' . )*) _ ')' _
/ _ ( !'))' . )* _
EOL = '\r'? '\n'
/ !.
DIGIT = [0-9]
HEX = [A-Fa-f0-9]
W = [a-zA-Z0-9_]
/ UCHAR
UCHAR = '\\u' HEX4
/ '\\U' HEX4 HEX4
HEX4 = HEX HEX HEX HEX
Name = { NAME #Name } _
NAME = !DIGIT !( KEYWORD !W ) W+
KEYWORD = 'auto'
/ 'asm'
/ 'break'
/ 'case'
/ 'char'
/ 'const'
/ 'continue'
/ 'default'
/ 'double'
/ 'do'
/ 'else'
/ 'enum'
/ 'extern'
/ 'float'
/ 'for'
/ 'goto'
/ 'if'
/ 'int'
/ 'inline'
/ 'long'
/ 'register'
/ 'restrict'
/ 'return'
/ 'short'
/ 'signed'
/ 'sizeof'
/ 'static'
/ 'struct'
/ 'switch'
/ 'typedef'
/ 'union'
/ 'unsigned'
/ 'void'
/ 'volatile'
/ 'while'
/ '_Bool'
/ '_Complex'
/ '_Imaginary'
/ '_stdcall'
/ '__declspec'
/ '__attribute__'
/ '__asm__'
/ '__asm'
/ '__voratile__'
"++" = '++' _
"--" = '--' _
"&" = '&' !'&' _
"*" = '*' !'=' _
"+" = '+' ![+=] _
"-" = '-' !( '-' / [=>] ) _
"~" = '~' _
"!" = '!' !'=' _
"void" = 'void' !W
"char" = 'char' !W
"short" = 'short' !W
"int" = 'int' !W
"long" = 'long' !W
"float" = 'float' !W
"double" = 'double' !W
"signed" = 'signed' !W
"unsigned" = 'unsigned' !W
"_Bool" = '_Bool' !W
"_Complex" = '_Complex' !W
"struct" = 'struct' !W
"union" = 'union' !W
"{" = '{' _
"[" = '[' _
"]" = ']' _
"," = ',' _
"..." = '...' _
":" = ':' ![>] _
"/" = '/' !'=' _
"%" = '%' ![=>] _
"<<" = '<<' !'=' _
">>" = '>>' !'=' _
"<=" = '<=' _
">=" = '>=' _
"<" = '<' ![=] _
">" = '>' ![=] _
"==" = '==' _
"!=" = '!=' _
"^" = '^' ![=] _
"|" = '|' ![=] _
"&&" = '&&' _
"||" = '||' _
"?" = '?' _
";" = ';' _
"}" = '}' _
"->" = '->' _
"enum" = 'enum' !W
"asm" = 'asm' !W
"__asm" = '__asm' !W
"__asm__" = '__asm__' !W
"case" = 'case' !W
"default" = 'default' !W
"if" = 'if' !W
"else" = 'else' !W
"switch" = 'switch' !W
"while" = 'while' !W
"do" = 'do' !W
"for" = 'for' !W
"goto" = 'goto' !W
"continue" = 'continue' !W
"break" = 'break' !W
"return" = 'return' !W
"*=" = '*=' _
"/=" = '/=' _
"%=" = '%=' _
"+=" = '+=' _
"-=" = '-=' _
"<<=" = '<<=' _
">>=" = '>>=' _
"&=" = '&=' _
"^=" = '^=' _
"|=" = '|=' _
"=" = '=' !'=' _
"." = '.' _
"'" = '\'' _
"sizeof" = 'sizeof' !W _
"typedef" = 'typedef' !W _
"extern" = 'extern' !W _
"static" = 'static' !W _
"auto" = 'auto' !W _
"register" = 'register' !W _
"const" = 'const' !W _
"restrict" = 'restrict' !W _
"volatile" = 'volatile' !W _
"__volatile__" = '__volatile__' !W _
"_Atomic" = '_Atomic' !W _
"__declspec" = '__declspec' !W _
"__inline" = '__inline' !W _
"__signed" = '__signed' !W _
"__builtin_va_list" = '__builtin_va_list' !W _
"inline" = 'inline' !W _
"_stdcall" = '_stdcall' !W _
"node_type_t" = 'node_type_t' !W _
"(" = '(' _
")" = ')' _
"#" = '#' _
"include" = 'include' !W _
"define" = 'define' !W _
EOT = !.
TopLevel = Directive
/ TypeDef
/ Declaration
/ ExternBlock
/ { #Empty } ";"
ExternBlock = _ { 'extern' _ '\"C\"' _ "{" ( $(TopLevel) / _ )* "}" #Source } _
Declaration = FunctionDeclaration
/ StructDeclaration _ ";"
/ VariableDeclaration
Directive = "#" "include" { ( !'\n' . )* #Include }
/ "#" "define" { ( &'\\\n' . . / !'\n' . )* #Define }
/ "#" { ( &'\\\n' . . / !'\n' . )* #TODO }
FunctionDeclaration = { $(AnnotationList) $type(Type) _ $name(Name) _ "(" $(FunctionParamList) ")" (_ $(Block) / _ ";") #Function }
/ { $(AnnotationList) $type(Type) _ $(Block) #Function }
AnnotationList = { $(Annotation)* #List } _
Annotation = "extern" { #KeyValue $({ `extern` #Key }) $({ `true` #Value }) } _
/ "static" { #KeyValue $({ `static` #Key }) $({ `true` #Value }) } _
/ "inline" { #KeyValue $({ `inline` #Key }) $({ `true` #Value }) } _
/ "__inline" { #KeyValue $({ `__inline` #Key }) $({ `true` #Value }) } _
/ "auto" { #KeyValue $({ `auto` #Key }) $({ `true` #Value }) } _
/ "register" { #KeyValue $({ `register` #Key }) $({ `true` #Value }) } _
/ "volatile" { #KeyValue $({ `volatile` #Key }) $({ `true` #Value }) } _
/ "__declspec" "(" { #KeyValue $({ `volatile` #Key }) $(Name #Value) } _ ")" _
/ "inline" { #KeyValue $({ `inline` #Key }) $({ `true` #Value }) } _
/ "_stdcall" { #KeyValue $({ `stdcall` #Key }) $({ `true` #Value }) } _
FunctionParamList = { ( $(FunctionParam) ( "," $(FunctionParam) )* )? ( "," "..." )? #List }
/ { _ 'void' _ #List }
FunctionParam = { $(Type) _ $(VarName)? #Param } _
example Directive ~8fc4d0 #include<stdio.h>
example ExternBlock ~9efea3 extern "C" {void add();}
example FunctionDeclaration ~22dd3c '''
int main(){
}
'''
example FunctionDeclaration ~12710e '''
static int main(){
}
'''
example FunctionDeclaration ~1195e4 '''
int add(int a, int b){
}
'''
example FunctionDeclaration ~2def48 '''
int main(){
int a = add(b,c);
return a;
}
'''
example FunctionDeclaration ~a04c1e '''
int fibo(int n) {
if(n < 3) return 1;
return fibo(n-1)+fibo(n-2);
}
'''
// Declaration
//==============
TypeDef = { "typedef" _ $type(Type) _ $(TypeDefName) _ ( ',' _ $(TypeDefName) _ )* ";" #TypeDeclaration }
TypeDefName = { "*" $name(TypeDefName) #PointerName } _
/ TypeNameOrNest {$name "[" $size(ConstantExpression)? "]" #ArrayName / "(" $param(FunctionParamList) ")" #TFunc }*
TypeNameOrNest = <symbol TypeName> _
/ "(" TypeDefName ")"
TypeName = { NAME #Name }
VariableDeclaration = { $(AnnotationList) $type(Type) $(InitDecl) ( "," $(InitDecl) )* ATTRIBUTE? ";" #Declaration }
/ { $(AnnotationList) $type(Type) ( "=" $expr(Initializer) )? ( "," $(InitDecl) )* ATTRIBUTE? ";" #Declaration }
InitDecl = { $name(VarName) ( "=" $expr(Initializer) )? #VarDecl } _
InitDeclAssign = { $name(VarName) "=" $expr(Initializer) #VarDecl } _
VarName = { "*" $name(VarName) #PointerName } _
/ NameOrNest {$name "[" $size(ConstantExpression)? "]" #ArrayName / "(" $param(FunctionParamList) ")" #TFunc }*
NameOrNest = "(" VarName ")"
/ Name
Initializer = AssignmentExpression
/ ArrayInitializer
ArrayInitializer = "{" { ( $(Initializer) ( "," $(Initializer) )* )? ","? #Array } "}"
example TypeDef ~5fc3cf typedef unsigned char BYTE;
example TypeDef ~927c50 '''
typedef struct {
int no;
char name[20];
} PERSON;
'''
example VariableDeclaration ~0cf1e0 int a;
example VariableDeclaration ~83437a int a,*b,c;
example VariableDeclaration ~ef2263 int a=0;
example VariableDeclaration ~4bd8c5 int a=0,b=1,c=2;
example VariableDeclaration ~2bdd12 int * restrict array;
example VariableDeclaration ~cfaf2c int[] a={1,2,3};
example VariableDeclaration ~df76ed int x __attribute__ ((aligned (16)));
example VariableDeclaration ~01fa16 '''
int[][] id = {
{1,2,3},
{4,5,6}
};
'''
//Type
//====
Type = { _TypeQualifier $(TypeSuffix) } _
/ TypeSuffix
_TypeQualifier = "const" #TConst
/ "volatile" #TVolatile
/ "restrict" #TRestrict
/ "_Atomic" #TAtomic
TypeSuffix = PrimaryType {$ POINTER_QUALIFIER? "*" POINTER_QUALIFIER? #TPointer / "[" (NAME / DIGIT*) "]" #TArray / _ _TypeQualifier }*
POINTER_QUALIFIER = "const"
/ "restrict"
/ "volatile"
PrimaryType = StructDeclaration
/ { "void" #TVoid } _
/ { SIGN? CONST? "char" #TInt } _
/ { SIGN? CONST? "short" _ "int" #TInt } _
/ { SIGN? CONST? "short" #TInt } _
/ { SIGN? CONST? "int" #TInt } _
/ { "float" _ #TFloat } _
/ { "double" _ #TFloat } _
/ { "long" _ "double" _ #TFloat } _
/ { "long" ( _ SIGN )? ( _ "long" )? ( _ "int" )? #TInt } _
/ { SIGN? "long" ( _ "long" )? ( _ "int" )? #TInt } _
/ { "signed" `signed int` #TInt } _
/ { "unsigned" `unsigned int` #TInt } _
/ { "_Bool" #TBoolean } _
/ { "_Complex" #TComplex } _
/ { "__builtin_va_list" #TName } _
/ { "node_type_t" #TName } _
/ { $(<isa TypeName>) #TTypedef } _
StructDeclaration = { "struct" _ $name(Name)? _StructMember? #TStruct }
/ { "union" _ $name(Name)? _StructMember? #TUnion }
/ { "enum" _ $name(Name)? ( "{" $(EnumeratorList) ","? "}" )? #TEnum }
SIGN = ("signed" / "unsigned" / "__signed") _
CONST = "const" _
NAME_T = !DIGIT ( !( '_t' !W ) W )+ '_t' !W
_StructMember = '{' _ ( $(Directive) / $(StructMemberDeclaration) / _ )* _ "}"
StructMemberDeclaration = { $(AnnotationList) $type(Type) $(StructMemberName) ( "," $(StructMemberName) )* ";" _ #StructMemberDeclaration }
/ { $type(Type) ";" _ #StructMemberDeclaration }
StructMemberName = VarName {$name ":" $value(ConstantExpression) #Bit }*
/ { ":" $value(ConstantExpression) #Bit }
EnumeratorList = { $(Enumerator) ( "," $(Enumerator) )* ","? #List }
Enumerator = Name {$name "=" $value(ConstantExpression) }?
example Type ~5b21d7 int
example Type ~5a9005 const char
example Type ~1134c8 unsigned int
example Type ~c2a231 unsigned const int
example Type ~a5944d int[]
example Type ~6cf979 int[][]
example Type ~c2d905 '''
struct Person{
int id;
char* name[20];
int age;
}
'''
example Type ~87c2a8 '''
enum Kitty { MIMI , YUKI = 5 , RENA } cats;
'''
example Type ~bcacc5 '''
union mydata {
int i;
double d;
char *s;
};
'''
example StructDeclaration ~78c38d struct s{}
// Block, Statement
//===================
Block = { "{" ( $(Directive) / $(Statement) / $(Declaration) / _ )* "}" #Block }
Statement = Block
/ { "if" _ "(" $cond(Expression) ")" $then(Statement) ( "else" _ $else(Statement) )? #If }
/ { "switch" _ "(" $cond(Expression) ")" $body(Statement) #Switch }
/ { "while" _ "(" $cond(Expression) ")" $body(Statement) #While }
/ { "do" _ $body(Statement) "while" _ "(" $cond(Expression) ")" ";" #DoWhile }
/ { "for" _ "(" $init(Expression)? ";" $cond(Expression)? ";" $iter(Expression)? ")" $body(Statement) #For }
/ { "for" _ "(" $init(Declaration) $cond(Expression)? ";" $iter(Expression)? ")" $body(Statement) #For }
/ { "goto" _ $label(Name) ";" #Goto }
/ { "continue" _ ";" #Continue }
/ { "break" _ ";" #Break }
/ { "return" _ $expr(Expression)? ";" #Return }
/ { "case" _ $cond(ConstantExpression) ":" ( !"case" !"default" $(Statement) )* #SwitchCase }
/ { "default" _ ":" ( !"case" $(Statement) )* #SwitchDefault }
/ { $label(Name) ":" #Label }
/ TypeDef
/ { $expr(Expression) ";" #ExpressionStatement }
/ { ("asm" / "__asm" / "__asm__") _ $({ ("volatile" / "__volatile__") #Volatile } _ )? "(" $(CString) ")" #Asm } ";"
/ { #Empty } ";"
example Block ~8909e9 '''
{
}
'''
example Block ~0038ad '''
{
a;
}
'''
example Block ~6bba1c '''
{
a;
a;
}
'''
example Statement ~1591a2 '''
if(c){
}
'''
example Statement ~fda420 '''
if(c){
}
else{
}
'''
example Statement ~b8c2e3 '''
while(c){
}
'''
example Statement ~4bf45a '''
do{
}
while(c);
'''
example Statement ~d46e74 '''
for(;;){
}
'''
example Statement ~c350a2 '''
for(int i = 0;i<1;i++){
}
'''
example Statement ~41aac4 '''
goto label;
'''
example Statement ~d309c9 '''
return;
'''
example Statement ~f26d52 '''
return 0;
'''
example Statement ~03222e '''
continue;
'''
example Statement ~084dd2 '''
switch(c) {
case 0:
return false;
case 1:
return true;
}
'''
example Statement ~378d31 '''
switch(c) {
case 0:
case 1:
return true;
default:
return false;
}
'''
example Statement ~e6e0ae '''
asm volatile("int3");
'''
//Expression
//==========
Expression = AssignmentExpression {$ "," $(AssignmentExpression) #Expression }*
AssignmentExpression = { $left(UnaryExpression) _AssignmentOperator $right(AssignmentExpression) }
/ ConditionalExpression
_AssignmentOperator = "=" #Assign
/ "*=" #AssignMul
/ "/=" #AssignDiv
/ "%=" #AssignMod
/ "+=" #AssignAdd
/ "-=" #AssignSub
/ "<<=" #AssignLeftShift
/ ">>=" #AssignRightShift
/ "&=" #AssignBitwiseAnd
/ "^=" #AssignBitwiseXOr
/ "|=" #AssignBitwiseOr
ConstantExpression = ConditionalExpression
ConditionalExpression = LogicalORExpression {$cond "?" $then(Expression) ":" $else(LogicalORExpression) #Trinary }*
LogicalORExpression = LogicalANDExpression {$left "||" $right(LogicalANDExpression) #Or }*
LogicalANDExpression = InclusiveORExpression {$left "&&" $right(InclusiveORExpression) #And }*
InclusiveORExpression = ExclusiveORExpression {$left "|" $right(ExclusiveORExpression) #BitwiseOr }*
ExclusiveORExpression = ANDExpression {$left "^" $right(ANDExpression) #BitwiseXor }*
ANDExpression = EqualityExpression {$left "&" $right(EqualityExpression) #BitwiseAnd }*
EqualityExpression = RelationalExpression {$left ("==" #Equals / "!=" #NotEquals) $right(RelationalExpression) }*
RelationalExpression = ShiftExpression {$left ("<=" #LessThanEquals / ">=" #GreaterThanEquals / "<" #LessThan / ">" #GreaterThan) $right(ShiftExpression) }*
ShiftExpression = AdditiveExpression {$left ("<<" #LeftShift / ">>" #RightShift) $right(AdditiveExpression) }*
AdditiveExpression = MultiplicativeExpression {$left ("+" #Add / "-" #Sub) $right(MultiplicativeExpression) }*
MultiplicativeExpression = CastExpression {$left ("*" #Mul / "/" #Div / "%" #Mod) $right(CastExpression) }*
UnaryExpression = PostfixExpression
/ { "++" $expr(UnaryExpression) #PrefixInc }
/ { "--" $expr(UnaryExpression) #PrefixDec }
/ { "&" $expr(CastExpression) #Address }
/ { "*" $expr(CastExpression) #Star }
/ { "+" $expr(CastExpression) #Plus }
/ { "-" $expr(CastExpression) #Minus }
/ { "~" $expr(CastExpression) #Compl }
/ { "!" $expr(CastExpression) #Not }
/ { "sizeof" ($expr(UnaryExpression) / "(" $type(Type) ")") #SizeOf }
CastExpression = { "(" $type(Type) ")" $expr(CastExpression) #Cast }
/ UnaryExpression
PostfixExpression = PrimaryExpression {$recv _FunctionCall / _PointerField / _Index / _Field / _Inc / _Dec }*
_FunctionCall = $({ "(" _ArgumentExpressionList? ")" #List }) #Apply
_ArgumentExpressionList = ($(AssignmentExpression) / $(Type)) ( "," ($(TypeP) / $(AssignmentExpression) / $(Type)) )*
_Index = "[" $(Expression) "]" #Index
_Field = "." $(Name) #Field
_PointerField = "->" $(Name) #PointerField
_Inc = "++" #Inc
_Dec = "--" #Dec
TypeP = Name {$ "*" #TPointer }+ &( _ (")" / ",") )
PrimaryExpression = Constant
/ CString
/ "(" Expression ")"
/ Name
example Expression ~46f038 x=y
example Expression ~8e03b0 x+=y
example Expression ~548f79 x->y
example Expression ~4e09fb c?x:y
example Expression ~7ac13c x<<y
example Expression ~9b2696 x>>y
example Expression ~dea67f x|y
example Expression ~7f3ecc x&y
example Expression ~78b953 x^y
example Expression ~f21916 ~x
example Expression ~006e0a x&&y
example Expression ~b60455 x||y
example Expression ~51b2b2 !x
example Expression ~b0be29 x==y
example Expression ~f89dae x!=y
example Expression ~ad9f44 x<y
example Expression ~37ebeb x<=y
example Expression ~ae662a x+y
example Expression ~fa8a6a x*y
example Expression ~b89235 ++x
example Expression ~5f409e x++
example Expression ~8a240d x.f
example Expression ~af11e0 x.f(y)
example Expression ~31a0c5 x[y]
example Expression ~20a347 x.f.z
example Expression ~792d40 x.f(y).z
example Expression ~3ef58d func()
example Expression ~c63a4d func(a,b)
example Expression ~cd52e0 \uAAAA
example Expression ~942075 (int) x
example Expression ~9e6de4 (int *)malloc(sizeof(int) * 100)
example Expression ~fc3b31 "a"
example Expression ~9951c9 "a" "b" "c"
example Expression ~ababc4 'a'
example Expression ~46dcf5 0123u
example Expression ~de692c 0xAA
example Expression ~4ffadc 0xAA.BB
example Expression ~6653cd 0xAAp10
example Expression ~1adad1 0x186A0UL
example Expression ~3b3014 3.14e3
example Expression ~81f9f2 "\\x0a"
example Expression ~9f41ae "\\n"
example Expression ~3f5524 "\\0"
//Literal
//=======
Constant = CFloat
/ CInteger
/ CChar
CFloat = { (DECIMAL_FLOAT / HEX_FLOAT) #Float } FLOAT_SUFFIX? _
DECIMAL_FLOAT = FRACTION EXPONENT?
/ DIGIT+ EXPONENT
FRACTION = DIGIT* '.' DIGIT+
/ DIGIT+ '.'
EXPONENT = [eE] [+\-]? DIGIT+
HEX_FLOAT = HEX_PREFIX HEX_FRACTION BINARY_EXPONENT?
/ HEX_PREFIX HEX+ BINARY_EXPONENT
HEX_PREFIX = '0' [xX]
HEX_FRACTION = HEX* '.' HEX+
/ HEX+ '.'
BINARY_EXPONENT = [pP] [+\-]? DIGIT+
FLOAT_SUFFIX = [flFL]
CInteger = { (HEXICAL / DECIMAL / OCTAL) #Integer } INT_SUFFIX? _
DECIMAL = [1-9] DIGIT*
HEXICAL = '0' [xX] ( [0-9] / [A-F] / [a-f] )+
OCTAL = '0' [0-7]*
INT_SUFFIX = [uU] LONG_SUFFIX?
/ LONG_SUFFIX [uU]?
LONG_SUFFIX = 'll'
/ 'LL'
/ [lL]
CString = 'L'? ({ $(String) (_ $(String))+ #CString } / String) _
String = '"' { STRING_CONTENT* #String } '"' _
CChar = 'L'? "'" { CHAR_CONTENT* #Character } "'" _
STRING_CONTENT = ESCAPE
/ &'\\\n' . . / ![\"\n\\] .
CHAR_CONTENT = ESCAPE
/ !['\n\\] .
ESCAPE = SIMPLE_ESCAPE
/ OCTAL_ESCAPE
/ HEX_ESCAPE
/ UCHAR
SIMPLE_ESCAPE = '\\' ['\"?\\abfnrtv]
OCTAL_ESCAPE = '\\' [0-7] [0-7]? [0-7]?
HEX_ESCAPE = '\\x' HEX+
// formatted by $ nez format