~ubuntu-branches/ubuntu/breezy/koffice/breezy

« back to all changes in this revision

Viewing changes to lib/kscript/yacc.yy

  • Committer: Bazaar Package Importer
  • Author(s): Ben Burton
  • Date: 2004-05-09 11:33:00 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040509113300-vfrdadqsvjfuhn3b
Tags: 1:1.3.1-1
* New upstream bugfix release.
* Built against newer imagemagick (closes: #246623).
* Made koffice-libs/kformula recommend/depend on latex-xft-fonts, which
  provides mathematical fonts that the formula editor can use.  Also
  patched the kformula part to make these fonts the default.
* Changed kword menu hint from "WordProcessors" to "Word processors"
  (closes: #246209).
* Spellchecker configuration is now fixed (closes: #221256, #227568).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
%{
2
 
 
3
 
#include "kscript_parsenode.h"
4
 
#include "kscript_parser.h"
5
 
#include <stdlib.h>
6
 
 
7
 
#include <qstring.h>
8
 
 
9
 
extern int yylex();
10
 
 
11
 
extern const char* idl_lexFile;
12
 
extern int idl_line_no;
13
 
 
14
 
void kscriptInitFlex( const char *_code, int extension );
15
 
 
16
 
void yyerror( const char *s )
17
 
{
18
 
  theParser->parse_error( idl_lexFile, s, idl_line_no );
19
 
}
20
 
 
21
 
%}
22
 
 
23
 
 
24
 
%union
25
 
{
26
 
  QString        *ident;
27
 
  KSParseNode    *node;
28
 
  KScript::Long   _int;
29
 
  QString        *_str;
30
 
  ushort          _char;
31
 
  KScript::Double _float;
32
 
}
33
 
 
34
 
%token <_str> T_FILE_OP
35
 
%token <_str> T_MATCH_LINE
36
 
%token T_LINE
37
 
%token T_INPUT
38
 
%token T_AMPERSAND
39
 
%token T_ASTERISK
40
 
%token T_CASE
41
 
%token <_char> T_CHARACTER_LITERAL
42
 
%token T_CIRCUMFLEX
43
 
%token T_COLON
44
 
%token T_COMMA
45
 
%token T_CONST
46
 
%token T_DEFAULT
47
 
%token T_ENUM
48
 
%token T_EQUAL
49
 
%token T_FALSE
50
 
%token <_float> T_FLOATING_PT_LITERAL
51
 
%token T_GREATER_THAN_SIGN
52
 
%token <ident> T_IDENTIFIER
53
 
%token T_IN
54
 
%token T_INOUT
55
 
%token <_int> T_INTEGER_LITERAL
56
 
%token T_LEFT_CURLY_BRACKET
57
 
%token T_LEFT_PARANTHESIS
58
 
%token T_LEFT_SQUARE_BRACKET
59
 
%token T_LESS_THAN_SIGN
60
 
%token T_MINUS_SIGN
61
 
%token T_OUT
62
 
%token T_PERCENT_SIGN
63
 
%token T_PLUS_SIGN
64
 
%token T_RIGHT_CURLY_BRACKET
65
 
%token T_RIGHT_PARANTHESIS
66
 
%token T_RIGHT_SQUARE_BRACKET
67
 
%token T_SCOPE
68
 
%token T_SEMICOLON
69
 
%token T_SHIFTLEFT
70
 
%token T_SHIFTRIGHT
71
 
%token T_SOLIDUS
72
 
%token <_str> T_STRING_LITERAL
73
 
%token <_str> T_PRAGMA
74
 
%token T_STRUCT
75
 
%token T_SWITCH
76
 
%token T_TILDE
77
 
%token T_TRUE
78
 
%token T_VERTICAL_LINE
79
 
%token T_CLASS
80
 
%token T_LESS_OR_EQUAL
81
 
%token T_GREATER_OR_EQUAL
82
 
%token T_ASSIGN
83
 
%token T_NOTEQUAL
84
 
%token T_MEMBER
85
 
%token T_DELETE
86
 
%token T_WHILE
87
 
%token T_IF
88
 
%token T_ELSE
89
 
%token T_FOR
90
 
%token T_DO
91
 
%token T_INCR
92
 
%token T_DECR
93
 
%token T_MAIN
94
 
%token T_FOREACH
95
 
%token <ident> T_SUBST
96
 
%token <_str> T_MATCH
97
 
%token T_NOT
98
 
%token T_RETURN
99
 
%token T_SIGNAL
100
 
%token T_EMIT
101
 
%token T_IMPORT
102
 
%token T_VAR
103
 
%token T_UNKNOWN
104
 
%token T_CATCH
105
 
%token T_TRY
106
 
%token T_RAISE
107
 
%token <_str> T_RANGE
108
 
%token <_str> T_CELL
109
 
%token T_FROM
110
 
%token T_PLUS_ASSIGN
111
 
%token T_MINUS_ASSIGN
112
 
%token T_AND
113
 
%token T_OR
114
 
%token T_DOLLAR
115
 
 
116
 
%type <node>   definitions
117
 
%type <node>   definition
118
 
%type <node>   const_dcl
119
 
%type <node>   or_expr
120
 
%type <node>   xor_expr
121
 
%type <node>   and_expr
122
 
%type <node>   shift_expr
123
 
%type <node>   add_expr
124
 
%type <node>   mult_expr
125
 
%type <node>   unary_expr
126
 
%type <node>   primary_expr
127
 
%type <node>   literal
128
 
%type <node>   scoped_name
129
 
%type <node>   inheritance_spec
130
 
%type <node>   class_dcl
131
 
%type <node>   class_header
132
 
%type <node>   class_body
133
 
%type <node>   class_exports
134
 
%type <node>   class_export
135
 
%type <node>   func_dcl
136
 
%type <node>   func_body
137
 
%type <node>   func_lines
138
 
%type <node>   func_line
139
 
%type <node>   func_param
140
 
%type <node>   func_params
141
 
%type <node>   assign_expr
142
 
%type <node>   equal_expr
143
 
%type <node>   index_expr
144
 
%type <node>   member_expr
145
 
%type <node>   array_elements
146
 
%type <node>   dict_elements
147
 
%type <node>   func_call_params
148
 
%type <node>   loops
149
 
%type <node>   incr_expr
150
 
%type <node>   while
151
 
%type <node>   else
152
 
%type <node>   main
153
 
%type <node>   match_expr
154
 
%type <node>   signal_param
155
 
%type <node>   signal_params
156
 
%type <node>   struct_dcl
157
 
%type <node>   struct_export
158
 
%type <node>   struct_exports
159
 
%type <node>   struct_members
160
 
%type <node>   qualified_names
161
 
%type <node>   qualified_name
162
 
%type <node>   catches
163
 
%type <node>   single_catch
164
 
%type <node>   loop_body
165
 
%type <_str>   import_list
166
 
%type <node>   bool_or
167
 
%type <node>   bool_and
168
 
 
169
 
%%
170
 
 
171
 
/*1*/
172
 
specification
173
 
        : /*empty*/
174
 
          {
175
 
            theParser->setRootNode( NULL );
176
 
          }
177
 
        | T_ASSIGN equal_expr
178
 
          {
179
 
            theParser->setRootNode( $2 );
180
 
          }
181
 
        | definitions
182
 
          {
183
 
            theParser->setRootNode( new KSParseNode( definitions, $1 ) );
184
 
          }
185
 
        ;
186
 
        
187
 
definitions
188
 
        : definition
189
 
          {
190
 
            $$ = new KSParseNode( definitions, $1 );
191
 
          }
192
 
        | definition definitions
193
 
          {
194
 
            $$ = new KSParseNode( definitions, $1 );
195
 
            $$->setBranch( 2, $2 );
196
 
          }
197
 
        ;
198
 
 
199
 
/*2*/
200
 
definition
201
 
        : const_dcl T_SEMICOLON
202
 
          {
203
 
            $$ = $1;
204
 
          }
205
 
        | struct_dcl T_SEMICOLON
206
 
          {
207
 
            $$ = $1;
208
 
          }
209
 
        | class_dcl T_SEMICOLON
210
 
          {
211
 
            $$ = $1;
212
 
          }
213
 
        | func_dcl T_RIGHT_CURLY_BRACKET
214
 
          {
215
 
            $$ = $1;
216
 
          }
217
 
        | T_IMPORT T_IDENTIFIER T_SEMICOLON
218
 
          {
219
 
            $$ = new KSParseNode( import );
220
 
            $$->setIdent( $2 );
221
 
          }
222
 
        | T_FROM T_IDENTIFIER T_IMPORT T_ASTERISK T_SEMICOLON
223
 
          {
224
 
            $$ = new KSParseNode( from );
225
 
            $$->setIdent( $2 );
226
 
            $$->setStringLiteral( QString( "" ) );
227
 
          }
228
 
        | T_FROM T_IDENTIFIER T_IMPORT import_list T_SEMICOLON
229
 
          {
230
 
            $$ = new KSParseNode( from );
231
 
            $$->setIdent( $2 );
232
 
            $$->setStringLiteral( $4 );
233
 
          }
234
 
        | T_PRAGMA      /*New*/
235
 
          {
236
 
            $$ = new KSParseNode( t_pragma );
237
 
            $$->setIdent( $1 );
238
 
          }
239
 
        | main
240
 
          {
241
 
            $$ = $1;
242
 
          }
243
 
        ;
244
 
 
245
 
import_list
246
 
        : T_IDENTIFIER
247
 
          {
248
 
                $$ = $1;
249
 
          }
250
 
        | T_IDENTIFIER T_COMMA import_list
251
 
          {
252
 
                (*$1) += "/";
253
 
                (*$1) += (*$3);
254
 
                $$ = $1;
255
 
          }
256
 
        ;
257
 
 
258
 
main
259
 
        : T_MAIN T_LEFT_CURLY_BRACKET func_body T_RIGHT_CURLY_BRACKET
260
 
          {
261
 
            $$ = new KSParseNode( func_dcl );
262
 
            $$->setBranch( 2, $3 );
263
 
            $$->setIdent( "main" );
264
 
          }
265
 
        | T_MAIN T_LEFT_PARANTHESIS func_params T_RIGHT_PARANTHESIS T_LEFT_CURLY_BRACKET func_body T_RIGHT_CURLY_BRACKET
266
 
          {
267
 
            $$ = new KSParseNode( func_dcl, $3, $6 );
268
 
            $$->setIdent( "main" );
269
 
          }
270
 
 
271
 
/*10*/
272
 
inheritance_spec
273
 
        : T_COLON qualified_names
274
 
          {
275
 
            $$ = $2;
276
 
          }
277
 
        ;
278
 
 
279
 
/* A list of qualified names like "KOM.Base, OpenParts.MainWindow, Qt.QWidget" */
280
 
qualified_names
281
 
        : qualified_name
282
 
          {
283
 
            $$ = new KSParseNode( t_qualified_names, $1 );
284
 
          }
285
 
        | qualified_name T_COMMA qualified_names
286
 
          {
287
 
            $$ = new KSParseNode( t_qualified_names, $1 );
288
 
            $$->setBranch( 2, $3 );
289
 
          }
290
 
        ;
291
 
 
292
 
/* A name like "QWidget" or "Qt.QWidget" or "Qt.Extension.PNG" */
293
 
qualified_name
294
 
        : scoped_name
295
 
          {
296
 
            $$ = $1;
297
 
          }
298
 
        | qualified_name T_MEMBER T_IDENTIFIER
299
 
          {
300
 
            $$ = new KSParseNode( member_expr, $1 );
301
 
            $$->setIdent( $3 );
302
 
          }
303
 
 
304
 
/* A usual identifier that may start with "::". For example "MyClass" or "::MyModule" */
305
 
scoped_name
306
 
        : T_IDENTIFIER
307
 
          {
308
 
            $$ = new KSParseNode( scoped_name );
309
 
            $$->setIdent( $1 );
310
 
          }
311
 
        | T_SCOPE T_IDENTIFIER
312
 
          {
313
 
            $$ = new KSParseNode( scoped_name );
314
 
            QString name = "::";
315
 
            name += *($2);
316
 
            delete $2;
317
 
            $$->setIdent( name );
318
 
          }
319
 
        ;
320
 
 
321
 
/* This rule fits for assignments like "a = 100" */
322
 
assign_expr
323
 
        : bool_or T_ASSIGN assign_expr
324
 
          {
325
 
            $$ = new KSParseNode( assign_expr, $1, $3 );
326
 
          }
327
 
        | bool_or T_PLUS_ASSIGN assign_expr
328
 
          {
329
 
            $$ = new KSParseNode( plus_assign, $1, $3 );
330
 
          }
331
 
        | bool_or T_MINUS_ASSIGN assign_expr
332
 
          {
333
 
            $$ = new KSParseNode( minus_assign, $1, $3 );
334
 
          }
335
 
        | bool_or
336
 
          {
337
 
            $$ = $1;
338
 
          }
339
 
        ;
340
 
 
341
 
bool_or
342
 
        : bool_and T_OR bool_or
343
 
          {
344
 
            $$ = new KSParseNode( bool_or, $1, $3 );
345
 
          }
346
 
        | bool_and
347
 
          {
348
 
            $$ = $1;
349
 
          }
350
 
        ;
351
 
 
352
 
bool_and
353
 
        : equal_expr T_AND bool_and
354
 
          {
355
 
            $$ = new KSParseNode( bool_and, $1, $3 );
356
 
          }
357
 
        | equal_expr
358
 
          {
359
 
            $$ = $1;
360
 
          }
361
 
        ;
362
 
 
363
 
equal_expr
364
 
        : or_expr T_EQUAL equal_expr
365
 
          {
366
 
            $$ = new KSParseNode( t_equal, $1, $3 );
367
 
          }
368
 
        | or_expr T_NOTEQUAL equal_expr
369
 
          {
370
 
            $$ = new KSParseNode( t_notequal, $1, $3 );
371
 
          }
372
 
        | or_expr T_LESS_OR_EQUAL equal_expr
373
 
          {
374
 
            $$ = new KSParseNode( t_less_or_equal, $1, $3 );
375
 
          }
376
 
        | or_expr T_GREATER_OR_EQUAL equal_expr
377
 
          {
378
 
            $$ = new KSParseNode( t_greater_or_equal, $1, $3 );
379
 
          }
380
 
        | or_expr T_LESS_THAN_SIGN equal_expr
381
 
          {
382
 
            $$ = new KSParseNode( t_less, $1, $3 );
383
 
          }
384
 
        | or_expr T_GREATER_THAN_SIGN equal_expr
385
 
          {
386
 
            $$ = new KSParseNode( t_greater, $1, $3 );
387
 
          }
388
 
        | or_expr
389
 
          {
390
 
            $$ = $1;
391
 
          }
392
 
        ;
393
 
 
394
 
/*15*/
395
 
or_expr
396
 
        : xor_expr
397
 
          {
398
 
            $$ = $1;
399
 
          }
400
 
        | or_expr T_VERTICAL_LINE xor_expr
401
 
          {
402
 
            $$ = new KSParseNode( t_vertical_line, $1, $3 );
403
 
          }
404
 
        ;
405
 
 
406
 
/*16*/
407
 
xor_expr
408
 
        : and_expr
409
 
          {
410
 
            $$ = $1;
411
 
          }
412
 
        | xor_expr T_CIRCUMFLEX and_expr
413
 
          {
414
 
            $$ = new KSParseNode( t_circumflex, $1, $3 );
415
 
          }
416
 
        ;
417
 
 
418
 
/*17*/
419
 
and_expr
420
 
        : shift_expr
421
 
          {
422
 
            $$ = $1;
423
 
          }
424
 
        | and_expr T_AMPERSAND shift_expr
425
 
          {
426
 
            $$ = new KSParseNode( t_ampersand, $1, $3 );
427
 
          }
428
 
        ;
429
 
 
430
 
/*18*/
431
 
shift_expr
432
 
        : add_expr
433
 
          {
434
 
            $$ = $1;
435
 
          }
436
 
        | shift_expr T_SHIFTRIGHT add_expr
437
 
          {
438
 
            $$ = new KSParseNode( t_shiftright, $1, $3 );
439
 
          }
440
 
        | shift_expr T_SHIFTLEFT add_expr
441
 
          {
442
 
            $$ = new KSParseNode( t_shiftleft, $1, $3 );
443
 
          }
444
 
        ;
445
 
 
446
 
/*19*/
447
 
add_expr
448
 
        : mult_expr
449
 
          {
450
 
            $$ = $1;
451
 
          }
452
 
        | add_expr T_PLUS_SIGN mult_expr
453
 
          {
454
 
            $$ = new KSParseNode( t_plus_sign, $1, $3 );
455
 
          }
456
 
        | add_expr T_MINUS_SIGN mult_expr
457
 
          {
458
 
            $$ = new KSParseNode( t_minus_sign, $1, $3 );
459
 
          }
460
 
        ;
461
 
 
462
 
/*20*/
463
 
mult_expr
464
 
        : unary_expr
465
 
          {
466
 
            $$ = $1;
467
 
          }
468
 
        | mult_expr T_ASTERISK unary_expr
469
 
          {
470
 
            $$ = new KSParseNode( t_asterik, $1, $3 );
471
 
          }
472
 
        | mult_expr T_SOLIDUS unary_expr
473
 
          {
474
 
            $$ = new KSParseNode( t_solidus, $1, $3 );
475
 
          }
476
 
        | mult_expr T_PERCENT_SIGN unary_expr
477
 
          {
478
 
            $$ = new KSParseNode( t_percent_sign, $1, $3 );
479
 
          }
480
 
        ;
481
 
 
482
 
/*22*/
483
 
unary_expr
484
 
        : T_MINUS_SIGN index_expr
485
 
          {
486
 
            $$ = new KSParseNode( t_minus_sign, $2 );
487
 
          }
488
 
        | T_PLUS_SIGN index_expr
489
 
          {
490
 
            $$ = new KSParseNode( t_plus_sign, $2 );
491
 
          }
492
 
        | T_TILDE index_expr
493
 
          {
494
 
            $$ = new KSParseNode( t_tilde, $2 );
495
 
          }
496
 
        | T_NOT index_expr
497
 
          {
498
 
            $$ = new KSParseNode( t_not, $2 );
499
 
          }
500
 
        | index_expr
501
 
          {
502
 
            $$ = $1;
503
 
          }
504
 
        ;
505
 
 
506
 
index_expr
507
 
        : index_expr T_LEFT_SQUARE_BRACKET assign_expr T_RIGHT_SQUARE_BRACKET
508
 
          {
509
 
            $$ = new KSParseNode( t_array, $1, $3 );
510
 
          }
511
 
        | index_expr T_LEFT_CURLY_BRACKET assign_expr T_RIGHT_CURLY_BRACKET
512
 
          {
513
 
            $$ = new KSParseNode( t_dict, $1, $3 );
514
 
          }
515
 
        | index_expr T_LEFT_PARANTHESIS T_RIGHT_PARANTHESIS
516
 
          {
517
 
            $$ = new KSParseNode( t_func_call, $1 );
518
 
          }
519
 
        | index_expr T_LEFT_PARANTHESIS func_call_params T_RIGHT_PARANTHESIS
520
 
          {
521
 
            $$ = new KSParseNode( t_func_call, $1, $3 );
522
 
          }
523
 
        | member_expr
524
 
          {
525
 
            $$ = $1;
526
 
          }
527
 
        ;
528
 
 
529
 
func_call_params
530
 
        : assign_expr T_COMMA func_call_params
531
 
          {
532
 
            $$ = new KSParseNode( func_call_params, $1, $3 );
533
 
          }
534
 
        ;
535
 
        | assign_expr
536
 
          {
537
 
            $$ = new KSParseNode( func_call_params, $1 );
538
 
          }
539
 
        ;
540
 
        
541
 
member_expr
542
 
        : index_expr T_MEMBER T_IDENTIFIER
543
 
          {
544
 
            $$ = new KSParseNode( member_expr, $1 );
545
 
            $$->setIdent( $3 );
546
 
          }
547
 
        | incr_expr
548
 
          {
549
 
            $$ = $1;
550
 
          }
551
 
        ;
552
 
 
553
 
incr_expr
554
 
        : T_INCR match_expr
555
 
          {
556
 
            $$ = new KSParseNode( t_incr, $2 );
557
 
          }
558
 
        | T_DECR match_expr
559
 
          {
560
 
            $$ = new KSParseNode( t_decr, $2 );
561
 
          }
562
 
        | match_expr T_INCR
563
 
          {
564
 
            /* Setting $1 twice indicates that this is a postfix operator */
565
 
            $$ = new KSParseNode( t_incr, $1, $1 );
566
 
          }
567
 
        | match_expr T_DECR
568
 
          {
569
 
            /* Setting $1 twice indicates that this is a postfix operator */
570
 
            $$ = new KSParseNode( t_decr, $1, $1 );
571
 
          }
572
 
        | match_expr
573
 
          {
574
 
            $$ = $1;
575
 
          }
576
 
        ;
577
 
 
578
 
match_expr
579
 
        : primary_expr T_MATCH
580
 
          {
581
 
            $$ = new KSParseNode( t_match, $1 );
582
 
            $$->setIdent( $2 );
583
 
          }
584
 
        | primary_expr T_SUBST
585
 
          {
586
 
            $$ = new KSParseNode( t_subst, $1 );
587
 
            $$->setIdent( $2 );
588
 
          }
589
 
        | primary_expr
590
 
          {
591
 
            $$ = $1;
592
 
          }
593
 
        ;
594
 
 
595
 
/*23*/
596
 
primary_expr
597
 
        : scoped_name
598
 
          {
599
 
            $$ = $1;
600
 
          }
601
 
        | literal
602
 
          {
603
 
            $$ = $1;
604
 
          }
605
 
        | T_INPUT
606
 
          {
607
 
            $$ = new KSParseNode( t_input );
608
 
          }
609
 
        | T_MATCH_LINE
610
 
          {
611
 
            $$ = new KSParseNode( t_match_line );
612
 
            $$->setIdent( $1 );
613
 
          }
614
 
        | T_FILE_OP assign_expr T_RIGHT_PARANTHESIS
615
 
          {
616
 
            $$ = new KSParseNode( t_file_op, $2 );
617
 
            $$->setIdent( $1 );
618
 
          }
619
 
        | T_LESS_THAN_SIGN or_expr T_GREATER_THAN_SIGN { }
620
 
        | T_LEFT_PARANTHESIS assign_expr T_RIGHT_PARANTHESIS
621
 
          {
622
 
            $$ = $2;
623
 
          }
624
 
        ;
625
 
 
626
 
/*24*/
627
 
/*25*/
628
 
literal
629
 
        : T_INTEGER_LITERAL
630
 
          {
631
 
            $$ = new KSParseNode( t_integer_literal );
632
 
            $$->setIntegerLiteral( $1 );
633
 
          }
634
 
        | T_CELL
635
 
          {
636
 
            $$ = new KSParseNode( t_cell );
637
 
            $$->setStringLiteral( $1 );
638
 
          }
639
 
        | T_RANGE
640
 
          {
641
 
            $$ = new KSParseNode( t_range );
642
 
            $$->setStringLiteral( $1 );
643
 
          }
644
 
        | T_STRING_LITERAL
645
 
          {
646
 
            $$ = new KSParseNode( t_string_literal );
647
 
            $$->setStringLiteral( $1 );
648
 
          }
649
 
        | T_CHARACTER_LITERAL
650
 
          {
651
 
            $$ = new KSParseNode( t_character_literal );
652
 
            $$->setCharacterLiteral( $1 );
653
 
          }
654
 
        | T_FLOATING_PT_LITERAL
655
 
          {
656
 
            $$ = new KSParseNode( t_floating_pt_literal );
657
 
            $$->setFloatingPtLiteral( $1 );
658
 
          }
659
 
        | T_TRUE  /*boolean_literal*/
660
 
          {
661
 
            $$ = new KSParseNode( t_boolean_literal );
662
 
            $$->setBooleanLiteral( true );
663
 
          }
664
 
        | T_FALSE /*boolean_literal*/
665
 
          {
666
 
            $$ = new KSParseNode( t_boolean_literal );
667
 
            $$->setBooleanLiteral( false );
668
 
          }
669
 
        | T_LEFT_SQUARE_BRACKET T_RIGHT_SQUARE_BRACKET
670
 
          {
671
 
            $$ = new KSParseNode( t_array_const );
672
 
          }
673
 
        | T_LEFT_SQUARE_BRACKET array_elements T_RIGHT_SQUARE_BRACKET
674
 
          {
675
 
            $$ = new KSParseNode( t_array_const, $2 );
676
 
          }
677
 
        | T_LEFT_CURLY_BRACKET T_RIGHT_CURLY_BRACKET
678
 
          {
679
 
            $$ = new KSParseNode( t_dict_const );
680
 
          }
681
 
        | T_LEFT_CURLY_BRACKET dict_elements T_RIGHT_CURLY_BRACKET
682
 
          {
683
 
            $$ = new KSParseNode( t_dict_const, $2 );
684
 
          }
685
 
        | T_LINE
686
 
          {
687
 
            $$ = new KSParseNode( t_line );
688
 
          }
689
 
        | T_DOLLAR T_INTEGER_LITERAL
690
 
          {
691
 
            $$ = new KSParseNode( t_regexp_group );
692
 
            $$->setIntegerLiteral( $2 );
693
 
          }
694
 
        ;
695
 
 
696
 
array_elements
697
 
        : assign_expr T_COMMA array_elements
698
 
          {
699
 
            $$ = new KSParseNode( t_array_element, $1, $3 );
700
 
          }
701
 
        | assign_expr
702
 
          {
703
 
            $$ = new KSParseNode( t_array_element, $1  );
704
 
          }
705
 
        ;
706
 
 
707
 
dict_elements
708
 
        : T_LEFT_PARANTHESIS assign_expr T_COMMA equal_expr T_RIGHT_PARANTHESIS T_COMMA dict_elements
709
 
          {
710
 
            $$ = new KSParseNode( t_dict_element, $2, $4, $7 );
711
 
          }
712
 
        | T_LEFT_PARANTHESIS assign_expr T_COMMA equal_expr T_RIGHT_PARANTHESIS
713
 
          {
714
 
            $$ = new KSParseNode( t_dict_element, $2, $4 );
715
 
          }
716
 
        ;
717
 
 
718
 
 
719
 
/*79*/
720
 
 
721
 
struct_dcl
722
 
        : T_STRUCT T_IDENTIFIER T_LEFT_CURLY_BRACKET struct_exports T_RIGHT_CURLY_BRACKET
723
 
          {
724
 
            $$ = new KSParseNode( t_struct, $4 );
725
 
            $$->setIdent( $2 );
726
 
          }
727
 
        ;
728
 
 
729
 
struct_exports
730
 
        : struct_export
731
 
          {
732
 
            $$ = new KSParseNode( exports, $1 );
733
 
          }
734
 
        | struct_export struct_exports
735
 
          {
736
 
            $$ = new KSParseNode( exports, $1 );
737
 
            $$->setBranch( 2, $2 );
738
 
          }
739
 
        ;
740
 
 
741
 
struct_export
742
 
        : func_dcl T_RIGHT_CURLY_BRACKET
743
 
          {
744
 
            $$ = $1;
745
 
          }     
746
 
        | T_VAR struct_members T_SEMICOLON
747
 
          {
748
 
            $$ = $2;
749
 
          }
750
 
        | const_dcl T_SEMICOLON
751
 
          {
752
 
            $$ = $1;
753
 
          }
754
 
        ;
755
 
 
756
 
struct_members
757
 
        : T_IDENTIFIER
758
 
          {
759
 
            $$ = new KSParseNode( t_struct_members );
760
 
            $$->setIdent( $1 );
761
 
          }
762
 
        | T_IDENTIFIER T_COMMA struct_members
763
 
          {
764
 
            $$ = new KSParseNode( t_struct_members, $3 );
765
 
            $$->setIdent( $1 );
766
 
          }
767
 
        ;
768
 
 
769
 
/*83*/
770
 
class_dcl
771
 
        : class_header T_LEFT_CURLY_BRACKET class_body T_RIGHT_CURLY_BRACKET
772
 
          {
773
 
            $$ = new KSParseNode( class_dcl, $1, $3 );
774
 
          }
775
 
        ;
776
 
 
777
 
/*84*/
778
 
class_header
779
 
        : T_CLASS T_IDENTIFIER
780
 
          {
781
 
            $$ = new KSParseNode( class_header );
782
 
            $$->setIdent( $2 );
783
 
          }
784
 
        | T_CLASS T_IDENTIFIER inheritance_spec
785
 
          {
786
 
            $$ = new KSParseNode( class_header );
787
 
            $$->setIdent( $2 );
788
 
            $$->setBranch( 1, $3 );
789
 
          }
790
 
        ;
791
 
 
792
 
/*85*/
793
 
class_body
794
 
        : /*empty*/
795
 
          {
796
 
            $$ = NULL;
797
 
          }
798
 
        | class_exports
799
 
          {
800
 
            $$ = $1;
801
 
          }
802
 
        ;
803
 
 
804
 
class_exports
805
 
        : class_export
806
 
          {
807
 
            $$ = new KSParseNode( exports, $1 );
808
 
          }
809
 
        | class_export class_exports
810
 
          {
811
 
            $$ = new KSParseNode( exports, $1 );
812
 
            $$->setBranch( 2, $2 );
813
 
          }
814
 
        ;
815
 
 
816
 
class_export
817
 
        : func_dcl T_RIGHT_CURLY_BRACKET
818
 
          {
819
 
            $$ = $1;
820
 
          }
821
 
        | struct_dcl T_SEMICOLON
822
 
          {
823
 
            $$ = $1;
824
 
          }
825
 
        | T_SIGNAL T_IDENTIFIER T_LEFT_PARANTHESIS signal_params T_RIGHT_PARANTHESIS T_SEMICOLON
826
 
          {
827
 
            $$ = new KSParseNode( signal_dcl, $4 );
828
 
            $$->setIdent( $2 );
829
 
          }
830
 
        | T_SIGNAL T_IDENTIFIER T_LEFT_PARANTHESIS T_RIGHT_PARANTHESIS T_SEMICOLON
831
 
          {
832
 
            $$ = new KSParseNode( signal_dcl, 0 );
833
 
            $$->setIdent( $2 );
834
 
          }
835
 
        | T_DELETE T_LEFT_PARANTHESIS T_IN T_IDENTIFIER T_RIGHT_PARANTHESIS T_LEFT_CURLY_BRACKET func_body T_RIGHT_CURLY_BRACKET
836
 
          {
837
 
            $$ = new KSParseNode( destructor_dcl );
838
 
            KSParseNode* n = new KSParseNode( func_param_in );
839
 
            n->setIdent( $4 );
840
 
            $$->setBranch( 1, n );
841
 
            $$->setBranch( 2, $7 );
842
 
            $$->setIdent( "delete" );
843
 
          }
844
 
        | const_dcl T_SEMICOLON
845
 
          {
846
 
            $$ = $1;
847
 
          }
848
 
        ;
849
 
 
850
 
func_dcl
851
 
        : T_IDENTIFIER T_LEFT_PARANTHESIS T_RIGHT_PARANTHESIS T_LEFT_CURLY_BRACKET func_body
852
 
          {
853
 
            $$ = new KSParseNode( func_dcl );
854
 
            $$->setBranch( 2, $5 );
855
 
            $$->setIdent( $1 );
856
 
          }
857
 
        | T_IDENTIFIER T_LEFT_PARANTHESIS func_params T_RIGHT_PARANTHESIS T_LEFT_CURLY_BRACKET func_body
858
 
          {
859
 
            $$ = new KSParseNode( func_dcl, $3, $6 );
860
 
            $$->setIdent( $1 );
861
 
          }
862
 
        ;
863
 
 
864
 
func_params
865
 
        : func_param
866
 
          {
867
 
            $$ = new KSParseNode( func_params, $1 );
868
 
          }
869
 
        | func_param T_COMMA func_params
870
 
          {
871
 
            $$ = new KSParseNode( func_params, $1, $3 );
872
 
          }
873
 
        ;
874
 
 
875
 
func_param
876
 
        : T_IN T_IDENTIFIER
877
 
          {
878
 
            $$ = new KSParseNode( func_param_in );
879
 
            $$->setIdent( $2 );
880
 
          }
881
 
        | T_IN T_IDENTIFIER T_ASSIGN assign_expr
882
 
          {
883
 
            $$ = new KSParseNode( func_param_in, $4 );
884
 
            $$->setIdent( $2 );
885
 
          }
886
 
        | T_OUT T_IDENTIFIER
887
 
          {
888
 
            $$ = new KSParseNode( func_param_out );
889
 
            $$->setIdent( $2 );
890
 
          }
891
 
        | T_INOUT T_IDENTIFIER
892
 
          {
893
 
            $$ = new KSParseNode( func_param_inout );
894
 
            $$->setIdent( $2 );
895
 
          }
896
 
        ;
897
 
 
898
 
signal_params
899
 
        : signal_param
900
 
          {
901
 
            $$ = new KSParseNode( signal_params, $1 );
902
 
          }
903
 
        | signal_param T_COMMA func_params
904
 
          {
905
 
            $$ = new KSParseNode( signal_params, $1, $3 );
906
 
          }
907
 
        ;
908
 
 
909
 
signal_param
910
 
        : T_IN T_IDENTIFIER
911
 
          {
912
 
            $$ = new KSParseNode( signal_param );
913
 
            $$->setIdent( $2 );
914
 
          }
915
 
        | T_IN T_IDENTIFIER T_ASSIGN assign_expr
916
 
          {
917
 
            $$ = new KSParseNode( signal_param, $4 );
918
 
            $$->setIdent( $2 );
919
 
          }
920
 
        ;
921
 
 
922
 
func_body
923
 
        : /*empty*/
924
 
          {
925
 
            $$ = NULL;
926
 
          }
927
 
        | func_lines
928
 
          {
929
 
            $$ = $1;
930
 
          }
931
 
        ;
932
 
 
933
 
func_lines
934
 
        : func_line
935
 
          {
936
 
            $$ = new KSParseNode( func_lines, $1 );
937
 
          }
938
 
        | func_line func_lines
939
 
          {
940
 
            $$ = new KSParseNode( func_lines, $1 );
941
 
            $$->setBranch( 2, $2 );
942
 
          }
943
 
        ;
944
 
 
945
 
func_line
946
 
        : assign_expr T_SEMICOLON
947
 
          {
948
 
            $$ = $1;
949
 
          }
950
 
        | T_RAISE assign_expr T_COMMA assign_expr T_SEMICOLON
951
 
          {
952
 
            $$ = new KSParseNode( t_raise, $2, $4 );
953
 
          }
954
 
        | T_EMIT assign_expr T_SEMICOLON
955
 
          {
956
 
            $$ = new KSParseNode( t_emit, $2 );
957
 
          }
958
 
        | T_RETURN T_SEMICOLON
959
 
          {
960
 
            $$ = new KSParseNode( t_return );
961
 
          }
962
 
        | T_RETURN assign_expr T_SEMICOLON
963
 
          {
964
 
            $$ = new KSParseNode( t_return, $2 );
965
 
          }
966
 
        | loops
967
 
          {
968
 
            $$ = $1;
969
 
          }
970
 
        | T_TRY T_LEFT_CURLY_BRACKET func_lines T_RIGHT_CURLY_BRACKET catches
971
 
          {
972
 
            $$ = new KSParseNode( t_try, $3, $5 );
973
 
          }
974
 
        | T_LEFT_CURLY_BRACKET func_lines T_RIGHT_CURLY_BRACKET
975
 
          {
976
 
            $$ = new KSParseNode( t_scope, $2 );
977
 
          }
978
 
        ;
979
 
 
980
 
catches
981
 
        : single_catch
982
 
          {
983
 
            $$ = $1;
984
 
          }
985
 
        | single_catch catches
986
 
          {
987
 
            $$ = $1;
988
 
            $$->setBranch( 4, $2 );
989
 
          }
990
 
        ;
991
 
 
992
 
single_catch
993
 
        : T_CATCH T_LEFT_PARANTHESIS assign_expr T_COMMA T_IDENTIFIER T_RIGHT_PARANTHESIS
994
 
          T_LEFT_CURLY_BRACKET func_lines T_RIGHT_CURLY_BRACKET
995
 
          {
996
 
            $$ = new KSParseNode( t_catch, $3, $8 );
997
 
            $$->setIdent( $5 );
998
 
          }
999
 
        | T_DEFAULT T_LEFT_PARANTHESIS T_IDENTIFIER T_COMMA T_IDENTIFIER T_RIGHT_PARANTHESIS
1000
 
          T_LEFT_CURLY_BRACKET func_lines T_RIGHT_CURLY_BRACKET
1001
 
          {
1002
 
            KSParseNode* x = new KSParseNode( scoped_name );
1003
 
            x->setIdent( $3 );
1004
 
            $$ = new KSParseNode( t_catch_default, x, $8 );
1005
 
            $$->setIdent( $5 );
1006
 
          }
1007
 
        ;
1008
 
 
1009
 
const_dcl
1010
 
        : T_CONST T_IDENTIFIER T_ASSIGN equal_expr
1011
 
          {
1012
 
            $$ = new KSParseNode( const_dcl, $4 );
1013
 
            $$->setIdent( $2 );
1014
 
          }
1015
 
        ;
1016
 
 
1017
 
loops
1018
 
        : while loop_body
1019
 
          {
1020
 
            $$ = new KSParseNode( t_while, $1, $2 );
1021
 
          }
1022
 
        | T_FOR T_LEFT_PARANTHESIS assign_expr T_SEMICOLON assign_expr T_SEMICOLON assign_expr T_RIGHT_PARANTHESIS loop_body
1023
 
          {
1024
 
            $$ = new KSParseNode( t_for, $3, $5, $7, $9 );
1025
 
          }
1026
 
        | T_DO loop_body while T_SEMICOLON
1027
 
          {
1028
 
            $$ = new KSParseNode( t_do, $2, $3 );
1029
 
          }
1030
 
        | T_IF T_LEFT_PARANTHESIS assign_expr T_RIGHT_PARANTHESIS loop_body else
1031
 
          {
1032
 
            $$ = new KSParseNode( t_if, $3, $5, $6 );
1033
 
          }
1034
 
        | T_FOREACH T_LEFT_PARANTHESIS T_IDENTIFIER T_COMMA assign_expr T_RIGHT_PARANTHESIS loop_body
1035
 
          {
1036
 
            $$ = new KSParseNode( t_foreach, $5, $7 );
1037
 
            $$->setIdent( $3 );
1038
 
          }
1039
 
        | T_FOREACH T_LEFT_PARANTHESIS T_IDENTIFIER T_COMMA T_IDENTIFIER T_COMMA assign_expr T_RIGHT_PARANTHESIS loop_body
1040
 
          {
1041
 
            /* We set $9 twice to indicate thet this is the foreach for maps */
1042
 
            $$ = new KSParseNode( t_foreach, $7, $9, $9 );
1043
 
            $$->setIdent( $3 );
1044
 
            $$->setStringLiteral( $5 );
1045
 
          }
1046
 
        ;
1047
 
 
1048
 
else
1049
 
        : /*empty*/
1050
 
          {
1051
 
            $$ = NULL;
1052
 
          }
1053
 
        | T_ELSE T_IF T_LEFT_PARANTHESIS assign_expr T_RIGHT_PARANTHESIS loop_body else
1054
 
          {
1055
 
            $$ = new KSParseNode( t_if, $4, $6, $7 );
1056
 
          }
1057
 
        | T_ELSE loop_body
1058
 
          {
1059
 
            $$ = $2;
1060
 
          }
1061
 
        ;
1062
 
 
1063
 
while
1064
 
        : T_WHILE T_LEFT_PARANTHESIS assign_expr T_RIGHT_PARANTHESIS
1065
 
          {
1066
 
            $$ = $3;
1067
 
          }
1068
 
        ;
1069
 
 
1070
 
loop_body
1071
 
        : T_LEFT_CURLY_BRACKET func_body T_RIGHT_CURLY_BRACKET
1072
 
          {
1073
 
            $$ = new KSParseNode( t_scope, $2 );
1074
 
          }
1075
 
        ;
1076
 
%%
1077
 
 
1078
 
void kscriptParse( const char *_code, int extension )
1079
 
{
1080
 
    kscriptInitFlex( _code, extension );
1081
 
    yyparse();
1082
 
}