Interp: More lazy keysym resolution
[platform/upstream/libxkbcommon.git] / src / xkbcomp / xkbparse.y
1 /************************************************************
2  Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc.
3
4  Permission to use, copy, modify, and distribute this
5  software and its documentation for any purpose and without
6  fee is hereby granted, provided that the above copyright
7  notice appear in all copies and that both that copyright
8  notice and this permission notice appear in supporting
9  documentation, and that the name of Silicon Graphics not be
10  used in advertising or publicity pertaining to distribution
11  of the software without specific prior written permission.
12  Silicon Graphics makes no representation about the suitability
13  of this software for any purpose. It is provided "as is"
14  without any express or implied warranty.
15
16  SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
17  SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
18  AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
19  GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
20  DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
21  DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
22  OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION  WITH
23  THE USE OR PERFORMANCE OF THIS SOFTWARE.
24
25  ********************************************************/
26
27 %token
28         END_OF_FILE     0
29         ERROR_TOK       255
30         XKB_KEYMAP      1
31         XKB_KEYCODES    2
32         XKB_TYPES       3
33         XKB_SYMBOLS     4
34         XKB_COMPATMAP   5
35         XKB_GEOMETRY    6
36         XKB_SEMANTICS   7
37         XKB_LAYOUT      8
38         INCLUDE         10
39         OVERRIDE        11
40         AUGMENT         12
41         REPLACE         13
42         ALTERNATE       14
43         VIRTUAL_MODS    20
44         TYPE            21
45         INTERPRET       22
46         ACTION_TOK      23
47         KEY             24
48         ALIAS           25
49         GROUP           26
50         MODIFIER_MAP    27
51         INDICATOR       28
52         SHAPE           29
53         KEYS            30
54         ROW             31
55         SECTION         32
56         OVERLAY         33
57         TEXT            34
58         OUTLINE         35
59         SOLID           36
60         LOGO            37
61         VIRTUAL         38
62         EQUALS          40
63         PLUS            41
64         MINUS           42
65         DIVIDE          43
66         TIMES           44
67         OBRACE          45
68         CBRACE          46
69         OPAREN          47
70         CPAREN          48
71         OBRACKET        49
72         CBRACKET        50
73         DOT             51
74         COMMA           52
75         SEMI            53
76         EXCLAM          54
77         INVERT          55
78         STRING          60
79         INTEGER         61
80         FLOAT           62
81         IDENT           63
82         KEYNAME         64
83         PARTIAL         70
84         DEFAULT         71
85         HIDDEN          72
86         ALPHANUMERIC_KEYS       73
87         MODIFIER_KEYS           74
88         KEYPAD_KEYS             75
89         FUNCTION_KEYS           76
90         ALTERNATE_GROUP         77
91 %{
92 #ifdef DEBUG
93 #define YYDEBUG 1
94 #endif
95 #define DEBUG_VAR parseDebug
96 #include "parseutils.h"
97 #include "xkbmisc.h"
98 #include <X11/Xlib.h>
99 #include <X11/keysym.h>
100 #include <X11/extensions/XKBgeomcommon.h>
101 #include <stdlib.h>
102
103 unsigned int parseDebug;
104
105 %}
106 %right  EQUALS
107 %left   PLUS MINUS
108 %left   TIMES DIVIDE
109 %left   EXCLAM INVERT
110 %left   OPAREN
111 %start  XkbFile
112 %union  {
113         int              ival;
114         unsigned         uval;
115         char            *str;
116         Atom            sval;
117         ParseCommon     *any;
118         ExprDef         *expr;
119         VarDef          *var;
120         VModDef         *vmod;
121         InterpDef       *interp;
122         KeyTypeDef      *keyType;
123         SymbolsDef      *syms;
124         ModMapDef       *modMask;
125         GroupCompatDef  *groupCompat;
126         IndicatorMapDef *ledMap;
127         IndicatorNameDef *ledName;
128         KeycodeDef      *keyName;
129         KeyAliasDef     *keyAlias;
130         ShapeDef        *shape;
131         SectionDef      *section;
132         RowDef          *row;
133         KeyDef          *key;
134         OverlayDef      *overlay;
135         OverlayKeyDef   *olKey;
136         OutlineDef      *outline;
137         DoodadDef       *doodad;
138         XkbFile         *file;
139 }
140 %type <ival>    Number Integer Float SignedNumber
141 %type <uval>    XkbCompositeType FileType MergeMode OptMergeMode
142 %type <uval>    DoodadType Flag Flags OptFlags
143 %type <str>     KeyName MapName OptMapName KeySym
144 %type <sval>    FieldSpec Ident Element String
145 %type <any>     DeclList Decl
146 %type <expr>    OptExprList ExprList Expr Term Lhs Terminal ArrayInit
147 %type <expr>    OptKeySymList KeySymList Action ActionList Coord CoordList
148 %type <var>     VarDecl VarDeclList SymbolsBody SymbolsVarDecl
149 %type <vmod>    VModDecl VModDefList VModDef
150 %type <interp>  InterpretDecl InterpretMatch
151 %type <keyType> KeyTypeDecl
152 %type <syms>    SymbolsDecl
153 %type <modMask> ModMapDecl
154 %type <groupCompat> GroupCompatDecl
155 %type <ledMap>  IndicatorMapDecl
156 %type <ledName> IndicatorNameDecl
157 %type <keyName> KeyNameDecl
158 %type <keyAlias> KeyAliasDecl
159 %type <shape>   ShapeDecl
160 %type <section> SectionDecl
161 %type <row>     SectionBody SectionBodyItem
162 %type <key>     RowBody RowBodyItem Keys Key
163 %type <overlay> OverlayDecl
164 %type <olKey>   OverlayKeyList OverlayKey
165 %type <outline> OutlineList OutlineInList
166 %type <doodad>  DoodadDecl
167 %type <file>    XkbFile XkbMapConfigList XkbMapConfig XkbConfig
168 %type <file>    XkbCompositeMap XkbCompMapList
169 %%
170 XkbFile         :       XkbCompMapList
171                         { $$= rtrnValue= $1; }
172                 |       XkbMapConfigList
173                         { $$= rtrnValue= $1;  }
174                 |       XkbConfig
175                         { $$= rtrnValue= $1; }
176                 ;
177
178 XkbCompMapList  :       XkbCompMapList XkbCompositeMap
179                         { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
180                 |       XkbCompositeMap
181                         { $$= $1; }
182                 ;
183
184 XkbCompositeMap :       OptFlags XkbCompositeType OptMapName OBRACE
185                             XkbMapConfigList
186                         CBRACE SEMI
187                         { $$= CreateXKBFile($2,$3,&$5->common,$1); }
188                 ;
189
190 XkbCompositeType:       XKB_KEYMAP      { $$= XkmKeymapFile; }
191                 |       XKB_SEMANTICS   { $$= XkmSemanticsFile; }
192                 |       XKB_LAYOUT      { $$= XkmLayoutFile; }
193                 ;
194
195 XkbMapConfigList :      XkbMapConfigList XkbMapConfig
196                         { $$= (XkbFile *)AppendStmt(&$1->common,&$2->common); }
197                 |       XkbMapConfig
198                         { $$= $1; }
199                 ;
200
201 XkbMapConfig    :       OptFlags FileType OptMapName OBRACE
202                             DeclList
203                         CBRACE SEMI
204                         { $$= CreateXKBFile($2,$3,$5,$1); }
205                 ;
206
207 XkbConfig       :       OptFlags FileType OptMapName DeclList
208                         { $$= CreateXKBFile($2,$3,$4,$1); }
209                 ;
210
211
212 FileType        :       XKB_KEYCODES            { $$= XkmKeyNamesIndex; }
213                 |       XKB_TYPES               { $$= XkmTypesIndex; }
214                 |       XKB_COMPATMAP           { $$= XkmCompatMapIndex; }
215                 |       XKB_SYMBOLS             { $$= XkmSymbolsIndex; }
216                 |       XKB_GEOMETRY            { $$= XkmGeometryIndex; }
217                 ;
218
219 OptFlags        :       Flags                   { $$= $1; }
220                 |                               { $$= 0; }
221                 ;
222
223 Flags           :       Flags Flag              { $$= (($1)|($2)); }
224                 |       Flag                    { $$= $1; }
225                 ;
226
227 Flag            :       PARTIAL                 { $$= XkbLC_Partial; }
228                 |       DEFAULT                 { $$= XkbLC_Default; }
229                 |       HIDDEN                  { $$= XkbLC_Hidden; }
230                 |       ALPHANUMERIC_KEYS       { $$= XkbLC_AlphanumericKeys; }
231                 |       MODIFIER_KEYS           { $$= XkbLC_ModifierKeys; }
232                 |       KEYPAD_KEYS             { $$= XkbLC_KeypadKeys; }
233                 |       FUNCTION_KEYS           { $$= XkbLC_FunctionKeys; }
234                 |       ALTERNATE_GROUP         { $$= XkbLC_AlternateGroup; }
235                 ;
236
237 DeclList        :       DeclList Decl
238                         { $$= AppendStmt($1,$2); }
239                 |       { $$= NULL; }
240                 ;
241
242 Decl            :       OptMergeMode VarDecl
243                         {
244                             $2->merge= StmtSetMerge(&$2->common,$1);
245                             $$= &$2->common;
246                         }
247                 |       OptMergeMode VModDecl
248                         {
249                             $2->merge= StmtSetMerge(&$2->common,$1);
250                             $$= &$2->common;
251                         }
252                 |       OptMergeMode InterpretDecl
253                         {
254                             $2->merge= StmtSetMerge(&$2->common,$1);
255                             $$= &$2->common;
256                         }
257                 |       OptMergeMode KeyNameDecl
258                         {
259                             $2->merge= StmtSetMerge(&$2->common,$1);
260                             $$= &$2->common;
261                         }
262                 |       OptMergeMode KeyAliasDecl
263                         {
264                             $2->merge= StmtSetMerge(&$2->common,$1);
265                             $$= &$2->common;
266                         }
267                 |       OptMergeMode KeyTypeDecl
268                         {
269                             $2->merge= StmtSetMerge(&$2->common,$1);
270                             $$= &$2->common;
271                         }
272                 |       OptMergeMode SymbolsDecl
273                         {
274                             $2->merge= StmtSetMerge(&$2->common,$1);
275                             $$= &$2->common;
276                         }
277                 |       OptMergeMode ModMapDecl
278                         {
279                             $2->merge= StmtSetMerge(&$2->common,$1);
280                             $$= &$2->common;
281                         }
282                 |       OptMergeMode GroupCompatDecl
283                         {
284                             $2->merge= StmtSetMerge(&$2->common,$1);
285                             $$= &$2->common;
286                         }
287                 |       OptMergeMode IndicatorMapDecl
288                         {
289                             $2->merge= StmtSetMerge(&$2->common,$1);
290                             $$= &$2->common;
291                         }
292                 |       OptMergeMode IndicatorNameDecl
293                         {
294                             $2->merge= StmtSetMerge(&$2->common,$1);
295                             $$= &$2->common;
296                         }
297                 |       OptMergeMode ShapeDecl
298                         {
299                             $2->merge= StmtSetMerge(&$2->common,$1);
300                             $$= &$2->common;
301                         }
302                 |       OptMergeMode SectionDecl
303                         {
304                             $2->merge= StmtSetMerge(&$2->common,$1);
305                             $$= &$2->common;
306                         }
307                 |       OptMergeMode DoodadDecl
308                         {
309                             $2->merge= StmtSetMerge(&$2->common,$1);
310                             $$= &$2->common;
311                         }
312                 |       MergeMode STRING
313                         {
314                             if ($1==MergeAltForm) {
315                                 yyerror("cannot use 'alternate' to include other maps");
316                                 $$= &IncludeCreate(scanBuf,MergeDefault)->common;
317                             }
318                             else {
319                                 $$= &IncludeCreate(scanBuf,$1)->common;
320                             }
321                         }
322                 ;
323
324 VarDecl         :       Lhs EQUALS Expr SEMI
325                         { $$= VarCreate($1,$3); }
326                 |       Ident SEMI
327                         { $$= BoolVarCreate($1,1); }
328                 |       EXCLAM Ident SEMI
329                         { $$= BoolVarCreate($2,0); }
330                 ;
331
332 KeyNameDecl     :       KeyName EQUALS Expr SEMI
333                         {
334                             KeycodeDef *def;
335
336                             def= KeycodeCreate($1,$3);
337                             if ($1)
338                                 free($1);
339                             $$= def;
340                         }
341                 ;
342
343 KeyAliasDecl    :       ALIAS KeyName EQUALS KeyName SEMI
344                         {
345                             KeyAliasDef *def;
346                             def= KeyAliasCreate($2,$4);
347                             if ($2)     free($2);       
348                             if ($4)     free($4);       
349                             $$= def;
350                         }
351                 ;
352
353 VModDecl        :       VIRTUAL_MODS VModDefList SEMI
354                         { $$= $2; }
355                 ;
356
357 VModDefList     :       VModDefList COMMA VModDef
358                         { $$= (VModDef *)AppendStmt(&$1->common,&$3->common); }
359                 |       VModDef
360                         { $$= $1; }
361                 ;
362
363 VModDef         :       Ident
364                         { $$= VModCreate($1,NULL); }
365                 |       Ident EQUALS Expr
366                         { $$= VModCreate($1,$3); }
367                 ;
368
369 InterpretDecl   :       INTERPRET InterpretMatch OBRACE
370                             VarDeclList
371                         CBRACE SEMI
372                         {
373                             $2->def= $4;
374                             $$= $2;
375                         }
376                 ;
377
378 InterpretMatch  :       KeySym PLUS Expr        
379                         { $$= InterpCreate($1, $3); }
380                 |       KeySym                  
381                         { $$= InterpCreate($1, NULL); }
382                 ;
383
384 VarDeclList     :       VarDeclList VarDecl
385                         { $$= (VarDef *)AppendStmt(&$1->common,&$2->common); }
386                 |       VarDecl
387                         { $$= $1; }
388                 ;
389
390 KeyTypeDecl     :       TYPE String OBRACE
391                             VarDeclList
392                         CBRACE SEMI
393                         { $$= KeyTypeCreate($2,$4); }
394                 ;
395
396 SymbolsDecl     :       KEY KeyName OBRACE
397                             SymbolsBody
398                         CBRACE SEMI
399                         { $$= SymbolsCreate($2,(ExprDef *)$4); }
400                 ;
401
402 SymbolsBody     :       SymbolsBody COMMA SymbolsVarDecl
403                         { $$= (VarDef *)AppendStmt(&$1->common,&$3->common); }
404                 |       SymbolsVarDecl
405                         { $$= $1; }
406                 |       { $$= NULL; }
407                 ;
408
409 SymbolsVarDecl  :       Lhs EQUALS Expr
410                         { $$= VarCreate($1,$3); }
411                 |       Lhs EQUALS ArrayInit
412                         { $$= VarCreate($1,$3); }
413                 |       Ident
414                         { $$= BoolVarCreate($1,1); }
415                 |       EXCLAM Ident
416                         { $$= BoolVarCreate($2,0); }
417                 |       ArrayInit
418                         { $$= VarCreate(NULL,$1); }
419                 ;
420
421 ArrayInit       :       OBRACKET OptKeySymList CBRACKET
422                         { $$= $2; }
423                 |       OBRACKET ActionList CBRACKET
424                         { $$= ExprCreateUnary(ExprActionList,TypeAction,$2); }
425                 ;
426
427 GroupCompatDecl :       GROUP Integer EQUALS Expr SEMI
428                         { $$= GroupCompatCreate($2,$4); }
429                 ;
430
431 ModMapDecl      :       MODIFIER_MAP Ident OBRACE ExprList CBRACE SEMI
432                         { $$= ModMapCreate($2,$4); }
433                 ;
434
435 IndicatorMapDecl:       INDICATOR String OBRACE VarDeclList CBRACE SEMI
436                         { $$= IndicatorMapCreate($2,$4); }
437                 ;
438
439 IndicatorNameDecl:      INDICATOR Integer EQUALS Expr SEMI
440                         { $$= IndicatorNameCreate($2,$4,False); }
441                 |       VIRTUAL INDICATOR Integer EQUALS Expr SEMI
442                         { $$= IndicatorNameCreate($3,$5,True); }
443                 ;
444
445 ShapeDecl       :       SHAPE String OBRACE OutlineList CBRACE SEMI
446                         { $$= ShapeDeclCreate($2,(OutlineDef *)&$4->common); }
447                 |       SHAPE String OBRACE CoordList CBRACE SEMI
448                         {
449                             OutlineDef *outlines;
450                             outlines= OutlineCreate(None,$4);
451                             $$= ShapeDeclCreate($2,outlines);
452                         }
453                 ;
454
455 SectionDecl     :       SECTION String OBRACE SectionBody CBRACE SEMI
456                         { $$= SectionDeclCreate($2,$4); }
457                 ;
458
459 SectionBody     :       SectionBody SectionBodyItem
460                         { $$=(RowDef *)AppendStmt(&$1->common,&$2->common);}
461                 |       SectionBodyItem
462                         { $$= $1; }
463                 ;
464
465 SectionBodyItem :       ROW OBRACE RowBody CBRACE SEMI
466                         { $$= RowDeclCreate($3); }
467                 |       VarDecl
468                         { $$= (RowDef *)$1; }
469                 |       DoodadDecl
470                         { $$= (RowDef *)$1; }
471                 |       IndicatorMapDecl
472                         { $$= (RowDef *)$1; }
473                 |       OverlayDecl
474                         { $$= (RowDef *)$1; }
475                 ;
476
477 RowBody         :       RowBody RowBodyItem
478                         { $$=(KeyDef *)AppendStmt(&$1->common,&$2->common);}
479                 |       RowBodyItem
480                         { $$= $1; }
481                 ;
482
483 RowBodyItem     :       KEYS OBRACE Keys CBRACE SEMI
484                         { $$= $3; }
485                 |       VarDecl
486                         { $$= (KeyDef *)$1; }
487                 ;
488
489 Keys            :       Keys COMMA Key
490                         { $$=(KeyDef *)AppendStmt(&$1->common,&$3->common);}
491                 |       Key
492                         { $$= $1; }
493                 ;
494
495 Key             :       KeyName
496                         { $$= KeyDeclCreate($1,NULL); }
497                 |       OBRACE ExprList CBRACE
498                         { $$= KeyDeclCreate(NULL,$2); }
499                 ;
500
501 OverlayDecl     :       OVERLAY String OBRACE OverlayKeyList CBRACE SEMI
502                         { $$= OverlayDeclCreate($2,$4); }
503                 ;
504
505 OverlayKeyList  :       OverlayKeyList COMMA OverlayKey
506                         {
507                             $$= (OverlayKeyDef *)
508                                 AppendStmt(&$1->common,&$3->common);
509                         }
510                 |       OverlayKey
511                         { $$= $1; }
512                 ;
513
514 OverlayKey      :       KeyName EQUALS KeyName
515                         { $$= OverlayKeyCreate($1,$3); }
516                 ;
517
518 OutlineList     :       OutlineList COMMA OutlineInList
519                         { $$=(OutlineDef *)AppendStmt(&$1->common,&$3->common);}
520                 |       OutlineInList
521                         { $$= $1; }
522                 ;
523
524 OutlineInList   :       OBRACE CoordList CBRACE
525                         { $$= OutlineCreate(None,$2); }
526                 |       Ident EQUALS OBRACE CoordList CBRACE
527                         { $$= OutlineCreate($1,$4); }
528                 |       Ident EQUALS Expr
529                         { $$= OutlineCreate($1,$3); }
530                 ;
531
532 CoordList       :       CoordList COMMA Coord
533                         { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
534                 |       Coord
535                         { $$= $1; }
536                 ;
537
538 Coord           :       OBRACKET SignedNumber COMMA SignedNumber CBRACKET
539                         {
540                             ExprDef *expr;
541                             expr= ExprCreate(ExprCoord,TypeUnknown);
542                             expr->value.coord.x= $2;
543                             expr->value.coord.y= $4;
544                             $$= expr;
545                         }
546                 ;
547
548 DoodadDecl      :       DoodadType String OBRACE VarDeclList CBRACE SEMI
549                         { $$= DoodadCreate($1,$2,$4); }
550                 ;
551
552 DoodadType      :       TEXT                    { $$= XkbTextDoodad; }
553                 |       OUTLINE                 { $$= XkbOutlineDoodad; }
554                 |       SOLID                   { $$= XkbSolidDoodad; }
555                 |       LOGO                    { $$= XkbLogoDoodad; }
556                 ;
557
558 FieldSpec       :       Ident                   { $$= $1; }
559                 |       Element                 { $$= $1; }
560                 ;
561
562 Element         :       ACTION_TOK              
563                         { $$= XkbcInternAtom("action",False); }
564                 |       INTERPRET
565                         { $$= XkbcInternAtom("interpret",False); }
566                 |       TYPE
567                         { $$= XkbcInternAtom("type",False); }
568                 |       KEY
569                         { $$= XkbcInternAtom("key",False); }
570                 |       GROUP
571                         { $$= XkbcInternAtom("group",False); }
572                 |       MODIFIER_MAP
573                         {$$=XkbcInternAtom("modifier_map",False);}
574                 |       INDICATOR
575                         { $$= XkbcInternAtom("indicator",False); }
576                 |       SHAPE   
577                         { $$= XkbcInternAtom("shape",False); }
578                 |       ROW     
579                         { $$= XkbcInternAtom("row",False); }
580                 |       SECTION 
581                         { $$= XkbcInternAtom("section",False); }
582                 |       TEXT
583                         { $$= XkbcInternAtom("text",False); }
584                 ;
585
586 OptMergeMode    :       MergeMode               { $$= $1; }
587                 |                               { $$= MergeDefault; }
588                 ;
589
590 MergeMode       :       INCLUDE                 { $$= MergeDefault; }
591                 |       AUGMENT                 { $$= MergeAugment; }
592                 |       OVERRIDE                { $$= MergeOverride; }
593                 |       REPLACE                 { $$= MergeReplace; }
594                 |       ALTERNATE               { $$= MergeAltForm; }
595                 ;
596
597 OptExprList     :       ExprList                        { $$= $1; }
598                 |                               { $$= NULL; }
599                 ;
600
601 ExprList        :       ExprList COMMA Expr
602                         { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
603                 |       Expr
604                         { $$= $1; }
605                 ;
606
607 Expr            :       Expr DIVIDE Expr
608                         { $$= ExprCreateBinary(OpDivide,$1,$3); }
609                 |       Expr PLUS Expr
610                         { $$= ExprCreateBinary(OpAdd,$1,$3); }
611                 |       Expr MINUS Expr
612                         { $$= ExprCreateBinary(OpSubtract,$1,$3); }
613                 |       Expr TIMES Expr
614                         { $$= ExprCreateBinary(OpMultiply,$1,$3); }
615                 |       Lhs EQUALS Expr
616                         { $$= ExprCreateBinary(OpAssign,$1,$3); }
617                 |       Term
618                         { $$= $1; }
619                 ;
620
621 Term            :       MINUS Term
622                         { $$= ExprCreateUnary(OpNegate,$2->type,$2); }
623                 |       PLUS Term
624                         { $$= ExprCreateUnary(OpUnaryPlus,$2->type,$2); }
625                 |       EXCLAM Term
626                         { $$= ExprCreateUnary(OpNot,TypeBoolean,$2); }
627                 |       INVERT Term
628                         { $$= ExprCreateUnary(OpInvert,$2->type,$2); }
629                 |       Lhs
630                         { $$= $1;  }
631                 |       FieldSpec OPAREN OptExprList CPAREN %prec OPAREN
632                         { $$= ActionCreate($1,$3); }
633                 |       Terminal
634                         { $$= $1;  }
635                 |       OPAREN Expr CPAREN
636                         { $$= $2;  }
637                 ;
638
639 ActionList      :       ActionList COMMA Action
640                         { $$= (ExprDef *)AppendStmt(&$1->common,&$3->common); }
641                 |       Action
642                         { $$= $1; }
643                 ;
644
645 Action          :       FieldSpec OPAREN OptExprList CPAREN
646                         { $$= ActionCreate($1,$3); }
647                 ;
648
649 Lhs             :       FieldSpec
650                         {
651                             ExprDef *expr;
652                             expr= ExprCreate(ExprIdent,TypeUnknown);
653                             expr->value.str= $1;
654                             $$= expr;
655                         }
656                 |       FieldSpec DOT FieldSpec
657                         {
658                             ExprDef *expr;
659                             expr= ExprCreate(ExprFieldRef,TypeUnknown);
660                             expr->value.field.element= $1;
661                             expr->value.field.field= $3;
662                             $$= expr;
663                         }
664                 |       FieldSpec OBRACKET Expr CBRACKET
665                         {
666                             ExprDef *expr;
667                             expr= ExprCreate(ExprArrayRef,TypeUnknown);
668                             expr->value.array.element= None;
669                             expr->value.array.field= $1;
670                             expr->value.array.entry= $3;
671                             $$= expr;
672                         }
673                 |       FieldSpec DOT FieldSpec OBRACKET Expr CBRACKET
674                         {
675                             ExprDef *expr;
676                             expr= ExprCreate(ExprArrayRef,TypeUnknown);
677                             expr->value.array.element= $1;
678                             expr->value.array.field= $3;
679                             expr->value.array.entry= $5;
680                             $$= expr;
681                         }
682                 ;
683
684 Terminal        :       String
685                         {
686                             ExprDef *expr;
687                             expr= ExprCreate(ExprValue,TypeString);
688                             expr->value.str= $1;
689                             $$= expr;
690                         }
691                 |       Integer
692                         {
693                             ExprDef *expr;
694                             expr= ExprCreate(ExprValue,TypeInt);
695                             expr->value.ival= $1;
696                             $$= expr;
697                         }
698                 |       Float
699                         {
700                             ExprDef *expr;
701                             expr= ExprCreate(ExprValue,TypeFloat);
702                             expr->value.ival= $1;
703                             $$= expr;
704                         }
705                 |       KeyName
706                         {
707                             ExprDef *expr;
708                             expr= ExprCreate(ExprValue,TypeKeyName);
709                             memset(expr->value.keyName,0,5);
710                             strncpy(expr->value.keyName,$1,4);
711                             free($1);
712                             $$= expr;
713                         }
714                 ;
715
716 OptKeySymList   :       KeySymList                      { $$= $1; }
717                 |                                       { $$= NULL; }
718                 ;
719
720 KeySymList      :       KeySymList COMMA KeySym
721                         { $$= AppendKeysymList($1,$3); }
722                 |       KeySym
723                         { $$= CreateKeysymList($1); }
724                 ;
725
726 KeySym          :       IDENT   { $$= strdup(scanBuf); }
727                 |       SECTION { $$= strdup("section"); }
728                 |       Integer         
729                         {
730                             if ($1 < 10) {      /* XK_0 .. XK_9 */
731                                 $$= malloc(2);
732                                 $$[0]= $1 + '0';
733                                 $$[1]= '\0';
734                             }
735                             else {
736                                 $$= malloc(17);
737                                 snprintf($$, 17, "%x", $1);
738                             }
739                         }
740                 ;
741
742 SignedNumber    :       MINUS Number    { $$= -$2; }
743                 |       Number              { $$= $1; }
744                 ;
745
746 Number          :       FLOAT           { $$= scanInt; }
747                 |       INTEGER         { $$= scanInt*XkbGeomPtsPerMM; }
748                 ;
749
750 Float           :       FLOAT           { $$= scanInt; }
751                 ;
752
753 Integer         :       INTEGER         { $$= scanInt; }
754                 ;
755
756 KeyName         :       KEYNAME         { $$= strdup(scanBuf); }
757                 ;
758
759 Ident           :       IDENT   { $$= XkbcInternAtom(scanBuf,False); }
760                 |       DEFAULT { $$= XkbcInternAtom("default",False); }
761                 ;
762
763 String          :       STRING  { $$= XkbcInternAtom(scanBuf,False); }
764                 ;
765
766 OptMapName      :       MapName { $$= $1; }
767                 |               { $$= NULL; }
768                 ;
769
770 MapName         :       STRING  { $$= strdup(scanBuf); }
771                 ;
772 %%
773 void
774 yyerror(const char *s)
775 {
776     if (warningLevel>0) {
777         (void)fprintf(stderr,"%s: line %d of %s\n",s,lineNum,
778                                         (scanFile?scanFile:"(unknown)"));
779         if ((warningLevel>3))
780             (void)fprintf(stderr,"last scanned symbol is: %s\n",scanBuf);
781     }
782     return;
783 }
784
785
786 int
787 yywrap(void)
788 {
789    return 1;
790 }
791