summaryrefslogtreecommitdiff
path: root/src/xkbcomp/parser.y
blob: 7b28552643e6304c20a8f6cf220ab09d7d8b28ef (plain)
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
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/************************************************************
 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.

 Permission to use, copy, modify, and distribute this
 software and its documentation for any purpose and without
 fee is hereby granted, provided that the above copyright
 notice appear in all copies and that both that copyright
 notice and this permission notice appear in supporting
 documentation, and that the name of Silicon Graphics not be
 used in advertising or publicity pertaining to distribution
 of the software without specific prior written permission.
 Silicon Graphics makes no representation about the suitability
 of this software for any purpose. It is provided "as is"
 without any express or implied warranty.

 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
 THE USE OR PERFORMANCE OF THIS SOFTWARE.

 ********************************************************/

%{
#include "xkbcomp-priv.h"
#include "parseutils.h"

extern int yylex(union YYSTYPE *val, struct YYLTYPE *loc, void *scanner);

#define scanner param->scanner
%}

%define		api.pure
%locations
%lex-param	{ void *scanner }
%parse-param	{ struct parser_param *param }

%token
	END_OF_FILE	0
	ERROR_TOK	255
	XKB_KEYMAP	1
	XKB_KEYCODES	2
	XKB_TYPES	3
	XKB_SYMBOLS	4
	XKB_COMPATMAP	5
	XKB_GEOMETRY	6
	XKB_SEMANTICS	7
	XKB_LAYOUT	8
	INCLUDE		10
	OVERRIDE	11
	AUGMENT		12
	REPLACE		13
	ALTERNATE	14
	VIRTUAL_MODS	20
	TYPE		21
	INTERPRET	22
	ACTION_TOK	23
	KEY		24
	ALIAS		25
	GROUP		26
	MODIFIER_MAP	27
	INDICATOR	28
	SHAPE		29
	KEYS		30
	ROW		31
	SECTION		32
	OVERLAY		33
	TEXT		34
	OUTLINE		35
	SOLID		36
	LOGO		37
	VIRTUAL		38
	EQUALS		40
	PLUS		41
	MINUS		42
	DIVIDE		43
	TIMES		44
	OBRACE		45
	CBRACE		46
	OPAREN		47
	CPAREN		48
	OBRACKET	49
	CBRACKET	50
	DOT		51
	COMMA		52
	SEMI		53
	EXCLAM		54
	INVERT		55
	STRING		60
	INTEGER		61
	FLOAT		62
	IDENT		63
	KEYNAME		64
	PARTIAL		70
	DEFAULT		71
	HIDDEN		72
	ALPHANUMERIC_KEYS	73
	MODIFIER_KEYS		74
	KEYPAD_KEYS		75
	FUNCTION_KEYS		76
	ALTERNATE_GROUP		77

%right	EQUALS
%left	PLUS MINUS
%left	TIMES DIVIDE
%left	EXCLAM INVERT
%left	OPAREN
%start	XkbFile
%union	{
	int		 ival;
	unsigned	 uval;
	int64_t		 num;
        enum xkb_file_type file_type;
	char		*str;
	xkb_atom_t	sval;
	ParseCommon	*any;
	ExprDef		*expr;
	VarDef		*var;
	VModDef		*vmod;
	InterpDef	*interp;
	KeyTypeDef	*keyType;
	SymbolsDef	*syms;
	ModMapDef	*modMask;
	GroupCompatDef	*groupCompat;
	IndicatorMapDef	*ledMap;
	IndicatorNameDef *ledName;
	KeycodeDef	*keyName;
	KeyAliasDef	*keyAlias;
        void            *geom;
	XkbFile		*file;
}
%type <num>     INTEGER FLOAT
%type <str>     IDENT KEYNAME STRING
%type <ival>	Number Integer Float SignedNumber
%type <uval>	MergeMode OptMergeMode
%type <file_type> XkbCompositeType FileType
%type <uval>	DoodadType Flag Flags OptFlags KeyCode
%type <str>	KeyName MapName OptMapName KeySym
%type <sval>	FieldSpec Ident Element String
%type <any>	DeclList Decl
%type <expr>	OptExprList ExprList Expr Term Lhs Terminal ArrayInit KeySyms
%type <expr>	OptKeySymList KeySymList Action ActionList Coord CoordList
%type <var>	VarDecl VarDeclList SymbolsBody SymbolsVarDecl
%type <vmod>	VModDecl VModDefList VModDef
%type <interp>	InterpretDecl InterpretMatch
%type <keyType>	KeyTypeDecl
%type <syms>	SymbolsDecl
%type <modMask>	ModMapDecl
%type <groupCompat> GroupCompatDecl
%type <ledMap>	IndicatorMapDecl
%type <ledName>	IndicatorNameDecl
%type <keyName>	KeyNameDecl
%type <keyAlias> KeyAliasDecl
%type <geom>	ShapeDecl SectionDecl SectionBody SectionBodyItem RowBody RowBodyItem
%type <geom>    Keys Key OverlayDecl OverlayKeyList OverlayKey OutlineList OutlineInList
%type <geom>    DoodadDecl
%type <file>	XkbFile XkbMapConfigList XkbMapConfig XkbConfig
%type <file>	XkbCompositeMap XkbCompMapList
%%
XkbFile		:	XkbCompMapList
			{ $$= param->rtrn= $1; }
		|	XkbMapConfigList
			{ $$= param->rtrn= $1;  }
		|	XkbConfig
			{ $$= param->rtrn= $1; }
		;

XkbCompMapList	:	XkbCompMapList XkbCompositeMap
			{ $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
		|	XkbCompositeMap
			{ $$= $1; }
		;

XkbCompositeMap	:	OptFlags XkbCompositeType OptMapName OBRACE
			    XkbMapConfigList
			CBRACE SEMI
			{
                            $$ = CreateXKBFile(param->ctx, $2, $3,
                                               &$5->common, $1);
                        }
		;

XkbCompositeType:	XKB_KEYMAP	{ $$= FILE_TYPE_KEYMAP; }
		|	XKB_SEMANTICS	{ $$= FILE_TYPE_KEYMAP; }
		|	XKB_LAYOUT	{ $$= FILE_TYPE_KEYMAP; }
		;

XkbMapConfigList :	XkbMapConfigList XkbMapConfig
			{
                            if (!$2)
                                $$= $1;
                            else
                                $$= (XkbFile *)AppendStmt(&$1->common,&$2->common);
                        }
		|	XkbMapConfig
			{ $$= $1; }
		;

XkbMapConfig	:	OptFlags FileType OptMapName OBRACE
			    DeclList
			CBRACE SEMI
			{
                            if ($2 == FILE_TYPE_GEOMETRY)
                            {
                                free($3);
                                FreeStmt($5);
                                $$= NULL;
                            }
                            else
                            {
                                $$ = CreateXKBFile(param->ctx, $2, $3, $5, $1);
                            }
                        }
		;

XkbConfig	:	OptFlags FileType OptMapName DeclList
			{
                            if ($2 == FILE_TYPE_GEOMETRY)
                            {
                                free($3);
                                FreeStmt($4);
                                $$= NULL;
                            }
                            else
                            {
                                $$ = CreateXKBFile(param->ctx, $2, $3, $4, $1);
                            }
                        }
		;


FileType	:	XKB_KEYCODES		{ $$= FILE_TYPE_KEYCODES; }
		|	XKB_TYPES		{ $$= FILE_TYPE_TYPES; }
		|	XKB_COMPATMAP		{ $$= FILE_TYPE_COMPAT; }
		|	XKB_SYMBOLS		{ $$= FILE_TYPE_SYMBOLS; }
		|	XKB_GEOMETRY		{ $$= FILE_TYPE_GEOMETRY; }
		;

OptFlags	:	Flags			{ $$= $1; }
		|				{ $$= 0; }
		;

Flags		:	Flags Flag		{ $$= (($1)|($2)); }
		|	Flag			{ $$= $1; }
		;

Flag		:	PARTIAL			{ $$= XkbLC_Partial; }
		|	DEFAULT			{ $$= XkbLC_Default; }
		|	HIDDEN			{ $$= XkbLC_Hidden; }
		|	ALPHANUMERIC_KEYS	{ $$= XkbLC_AlphanumericKeys; }
		|	MODIFIER_KEYS		{ $$= XkbLC_ModifierKeys; }
		|	KEYPAD_KEYS		{ $$= XkbLC_KeypadKeys; }
		|	FUNCTION_KEYS		{ $$= XkbLC_FunctionKeys; }
		|	ALTERNATE_GROUP		{ $$= XkbLC_AlternateGroup; }
		;

DeclList	:	DeclList Decl
			{ $$= AppendStmt($1,$2); }
		|	{ $$= NULL; }
		;

Decl		:	OptMergeMode VarDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode VModDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode InterpretDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode KeyNameDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode KeyAliasDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode KeyTypeDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode SymbolsDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode ModMapDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode GroupCompatDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode IndicatorMapDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode IndicatorNameDecl
			{
			    $2->merge= StmtSetMerge(&$2->common,$1,&@1,scanner);
			    $$= &$2->common;
			}
		|	OptMergeMode ShapeDecl
			{
			}
		|	OptMergeMode SectionDecl
			{
			}
		|	OptMergeMode DoodadDecl
			{
			}
		|	MergeMode STRING
			{
			    if ($1==MergeAltForm) {
				yyerror(&@1, scanner,
                                        "cannot use 'alternate' to include other maps");
				$$= &IncludeCreate($2,MergeDefault)->common;
			    }
			    else {
				$$= &IncludeCreate($2,$1)->common;
			    }
                            free($2);
                        }
		;

VarDecl		:	Lhs EQUALS Expr SEMI
			{ $$= VarCreate($1,$3); }
		|	Ident SEMI
			{ $$= BoolVarCreate($1,1); }
		|	EXCLAM Ident SEMI
			{ $$= BoolVarCreate($2,0); }
		;

KeyNameDecl	:	KeyName EQUALS KeyCode SEMI
                        {
			    KeycodeDef *def;

			    def= KeycodeCreate($1,$3);
			    free($1);
			    $$= def;
			}
		;

KeyAliasDecl	:	ALIAS KeyName EQUALS KeyName SEMI
			{
			    KeyAliasDef	*def;
			    def= KeyAliasCreate($2,$4);
			    free($2);
			    free($4);
			    $$= def;
			}
		;

VModDecl	:	VIRTUAL_MODS VModDefList SEMI
			{ $$= $2; }
		;

VModDefList	:	VModDefList COMMA VModDef
			{ $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
		|	VModDef
			{ $$= $1; }
		;

VModDef		:	Ident
			{ $$= VModCreate($1,NULL); }
		|	Ident EQUALS Expr
			{ $$= VModCreate($1,$3); }
		;

InterpretDecl	:	INTERPRET InterpretMatch OBRACE
			    VarDeclList
			CBRACE SEMI
			{
			    $2->def= $4;
			    $$= $2;
			}
		;

InterpretMatch	:	KeySym PLUS Expr	
			{ $$= InterpCreate($1, $3); }
		|	KeySym			
			{ $$= InterpCreate($1, NULL); }
		;

VarDeclList	:	VarDeclList VarDecl
			{ $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
		|	VarDecl
			{ $$= $1; }
		;

KeyTypeDecl	:	TYPE String OBRACE
			    VarDeclList
			CBRACE SEMI
			{ $$= KeyTypeCreate($2,$4); }
		;

SymbolsDecl	:	KEY KeyName OBRACE
			    SymbolsBody
			CBRACE SEMI
			{ $$= SymbolsCreate($2,(ExprDef *)$4); free($2); }
		;

SymbolsBody	:	SymbolsBody COMMA SymbolsVarDecl
			{ $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
		|	SymbolsVarDecl
			{ $$= $1; }
		|	{ $$= NULL; }
		;

SymbolsVarDecl	:	Lhs EQUALS Expr
			{ $$= VarCreate($1,$3); }
		|	Lhs EQUALS ArrayInit
			{ $$= VarCreate($1,$3); }
		|	Ident
			{ $$= BoolVarCreate($1,1); }
		|	EXCLAM Ident
			{ $$= BoolVarCreate($2,0); }
		|	ArrayInit
			{ $$= VarCreate(NULL,$1); }
		;

ArrayInit	:	OBRACKET OptKeySymList CBRACKET
			{ $$= $2; }
		|	OBRACKET ActionList CBRACKET
			{ $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
		;

GroupCompatDecl	:	GROUP Integer EQUALS Expr SEMI
			{ $$= GroupCompatCreate($2,$4); }
		;

ModMapDecl	:	MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
			{ $$= ModMapCreate($2,$4); }
		;

IndicatorMapDecl:	INDICATOR String OBRACE VarDeclList CBRACE SEMI
			{ $$= IndicatorMapCreate($2,$4); }
		;

IndicatorNameDecl:	INDICATOR Integer EQUALS Expr SEMI
			{ $$= IndicatorNameCreate($2,$4,false); }
		|	VIRTUAL INDICATOR Integer EQUALS Expr SEMI
			{ $$= IndicatorNameCreate($3,$5,true); }
		;

ShapeDecl	:	SHAPE String OBRACE OutlineList CBRACE SEMI
			{ $$= NULL; }
		|	SHAPE String OBRACE CoordList CBRACE SEMI
			{ $$= NULL; }
		;

SectionDecl	:	SECTION String OBRACE SectionBody CBRACE SEMI
			{ $$= NULL; }
		;

SectionBody	:	SectionBody SectionBodyItem
			{ $$= NULL;}
		|	SectionBodyItem
			{ $$= NULL; }
		;

SectionBodyItem	:	ROW OBRACE RowBody CBRACE SEMI
			{ $$= NULL; }
		|	VarDecl
			{ FreeStmt(&$1->common); $$= NULL; }
		|	DoodadDecl
			{ $$= NULL; }
		|	IndicatorMapDecl
			{ FreeStmt(&$1->common); $$= NULL; }
		|	OverlayDecl
			{ $$= NULL; }
		;

RowBody		:	RowBody RowBodyItem
			{ $$= NULL;}
		|	RowBodyItem
			{ $$= NULL; }
		;

RowBodyItem	:	KEYS OBRACE Keys CBRACE SEMI
			{ $$= NULL; }
		|	VarDecl
			{ FreeStmt(&$1->common); $$= NULL; }
		;

Keys		:	Keys COMMA Key
			{ $$= NULL; }
		|	Key
			{ $$= NULL; }
		;

Key		:	KeyName
			{ free($1); $$= NULL; }
		|	OBRACE ExprList CBRACE
			{ FreeStmt(&$2->common); $$= NULL; }
		;

OverlayDecl	:	OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
			{ $$= NULL; }
		;

OverlayKeyList	:	OverlayKeyList COMMA OverlayKey
			{ $$= NULL; }
		|	OverlayKey
			{ $$= NULL; }
		;

OverlayKey	:	KeyName EQUALS KeyName
			{ free($1); free($3); $$= NULL; }
		;

OutlineList	:	OutlineList COMMA OutlineInList
			{ $$= NULL;}
		|	OutlineInList
			{ $$= NULL; }
		;

OutlineInList	:	OBRACE CoordList CBRACE
			{ $$= NULL; }
		|	Ident EQUALS OBRACE CoordList CBRACE
			{ $$= NULL; }
		|	Ident EQUALS Expr
			{ FreeStmt(&$3->common); $$= NULL; }
		;

CoordList	:	CoordList COMMA Coord
			{ $$= NULL; }
		|	Coord
			{ $$= NULL; }
		;

Coord		:	OBRACKET SignedNumber COMMA SignedNumber CBRACKET
			{ $$= NULL; }
		;

DoodadDecl	:	DoodadType String OBRACE VarDeclList CBRACE SEMI
			{ FreeStmt(&$4->common); $$= NULL; }
		;

DoodadType	:	TEXT			{ $$= 0; }
		|	OUTLINE			{ $$= 0; }
		|	SOLID			{ $$= 0; }
		|	LOGO			{ $$= 0; }
		;

FieldSpec	:	Ident			{ $$= $1; }
		|	Element			{ $$= $1; }
		;

Element		:	ACTION_TOK		
			{ $$= xkb_atom_intern(param->ctx, "action"); }
		|	INTERPRET
			{ $$= xkb_atom_intern(param->ctx, "interpret"); }
		|	TYPE
			{ $$= xkb_atom_intern(param->ctx, "type"); }
		|	KEY
			{ $$= xkb_atom_intern(param->ctx, "key"); }
		|	GROUP
			{ $$= xkb_atom_intern(param->ctx, "group"); }
		|	MODIFIER_MAP
			{$$= xkb_atom_intern(param->ctx, "modifier_map");}
		|	INDICATOR
			{ $$= xkb_atom_intern(param->ctx, "indicator"); }
		|	SHAPE	
			{ $$= xkb_atom_intern(param->ctx, "shape"); }
		|	ROW	
			{ $$= XKB_ATOM_NONE; }
		|	SECTION	
			{ $$= XKB_ATOM_NONE; }
		|	TEXT
			{ $$= XKB_ATOM_NONE; }
		;

OptMergeMode	:	MergeMode		{ $$= $1; }
		|				{ $$= MergeDefault; }
		;

MergeMode	:	INCLUDE			{ $$= MergeDefault; }
		|	AUGMENT			{ $$= MergeAugment; }
		|	OVERRIDE		{ $$= MergeOverride; }
		|	REPLACE			{ $$= MergeReplace; }
		|	ALTERNATE		{ $$= MergeAltForm; }
		;

OptExprList	:	ExprList			{ $$= $1; }
		|				{ $$= NULL; }
		;

ExprList	:	ExprList COMMA Expr
			{ $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
		|	Expr
			{ $$= $1; }
		;

Expr		:	Expr DIVIDE Expr
			{ $$= ExprCreateBinary(OpDivide,$1,$3); }
		|	Expr PLUS Expr
			{ $$= ExprCreateBinary(OpAdd,$1,$3); }
		|	Expr MINUS Expr
			{ $$= ExprCreateBinary(OpSubtract,$1,$3); }
		|	Expr TIMES Expr
			{ $$= ExprCreateBinary(OpMultiply,$1,$3); }
		|	Lhs EQUALS Expr
			{ $$= ExprCreateBinary(OpAssign,$1,$3); }
		|	Term
			{ $$= $1; }
		;

Term		:	MINUS Term
			{ $$= ExprCreateUnary(OpNegate,$2->type,$2); }
		|	PLUS Term
			{ $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
		|	EXCLAM Term
			{ $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
		|	INVERT Term
			{ $$= ExprCreateUnary(OpInvert,$2->type,$2); }
		|	Lhs
			{ $$= $1;  }
		|	FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
			{ $$= ActionCreate($1,$3); }
		|	Terminal
			{ $$= $1;  }
		|	OPAREN Expr CPAREN
			{ $$= $2;  }
		;

ActionList	:	ActionList COMMA Action
			{ $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
		|	Action
			{ $$= $1; }
		;

Action		:	FieldSpec OPAREN OptExprList CPAREN
			{ $$= ActionCreate($1,$3); }
		;

Lhs		:	FieldSpec
			{
			    ExprDef *expr;
                            expr= ExprCreate(ExprIdent,TypeUnknown);
                            expr->value.str= $1;
                            $$= expr;
			}
		|	FieldSpec DOT FieldSpec
                        {
                            ExprDef *expr;
                            expr= ExprCreate(ExprFieldRef,TypeUnknown);
                            expr->value.field.element= $1;
                            expr->value.field.field= $3;
                            $$= expr;
			}
		|	FieldSpec OBRACKET Expr CBRACKET
			{
			    ExprDef *expr;
			    expr= ExprCreate(ExprArrayRef,TypeUnknown);
			    expr->value.array.element= XKB_ATOM_NONE;
			    expr->value.array.field= $1;
			    expr->value.array.entry= $3;
			    $$= expr;
			}
		|	FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
			{
			    ExprDef *expr;
			    expr= ExprCreate(ExprArrayRef,TypeUnknown);
			    expr->value.array.element= $1;
			    expr->value.array.field= $3;
			    expr->value.array.entry= $5;
			    $$= expr;
			}
		;

Terminal	:	String
			{
			    ExprDef *expr;
                            expr= ExprCreate(ExprValue,TypeString);
                            expr->value.str= $1;
                            $$= expr;
			}
		|	Integer
			{
			    ExprDef *expr;
                            expr= ExprCreate(ExprValue,TypeInt);
                            expr->value.ival= $1;
                            $$= expr;
			}
		|	Float
			{
			    $$= NULL;
			}
		|	KeyName
			{
			    ExprDef *expr;
			    expr= ExprCreate(ExprValue,TypeKeyName);
			    memset(expr->value.keyName,0,5);
			    strncpy(expr->value.keyName,$1,4);
			    free($1);
			    $$= expr;
			}
		;

OptKeySymList	:	KeySymList			{ $$= $1; }
		|					{ $$= NULL; }
		;

KeySymList	:	KeySymList COMMA KeySym
			{ $$= AppendKeysymList($1,$3); }
                |       KeySymList COMMA KeySyms
                        { $$= AppendMultiKeysymList($1,$3); }
		|	KeySym
			{ $$= CreateKeysymList($1); }
                |       KeySyms
                        { $$= CreateMultiKeysymList($1); }
		;

KeySyms         :       OBRACE KeySymList CBRACE
                        { $$= $2; }
                ;

KeySym		:	IDENT	{ $$= $1; }
		|	SECTION	{ $$= strdup("section"); }
		|	Integer		
			{
			    if ($1 < 10) {	/* XK_0 .. XK_9 */
				$$= malloc(2);
				$$[0]= $1 + '0';
				$$[1]= '\0';
			    }
			    else {
				$$= malloc(17);
				snprintf($$, 17, "0x%x", $1);
			    }
			}
		;

SignedNumber	:	MINUS Number    { $$= -$2; }
		|	Number              { $$= $1; }
		;

Number		:	FLOAT		{ $$= $1; }
		|	INTEGER		{ $$= $1*XkbGeomPtsPerMM; }
		;

Float		:	FLOAT		{ $$= 0; }
		;

Integer		:	INTEGER		{ $$= $1; }
		;

KeyCode         :       INTEGER         { $$= $1; }
                ;

KeyName		:	KEYNAME		{ $$= $1; }
		;

Ident		:	IDENT
                        {
                            $$ = xkb_atom_intern(param->ctx, $1);
                            free($1);
                        }
		|	DEFAULT
                        {
                            $$ = xkb_atom_intern(param->ctx, "default");
                        }
		;

String		:	STRING
                        {
                            $$ = xkb_atom_intern(param->ctx, $1);
                            free($1);
                        }
		;

OptMapName	:	MapName	{ $$= $1; }
		|		{ $$= NULL; }
		;

MapName		:	STRING 	{ $$= $1; }
		;

%%

#undef scanner