-
Notifications
You must be signed in to change notification settings - Fork 0
/
yacc.y
1409 lines (1267 loc) · 49.2 KB
/
yacc.y
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
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
FILE NAME: yacc.y
Copyright (C) 1997-2016 Vladimir Makarov.
Written by Vladimir Makarov <vmakarov@gcc.gnu.org>
This file is part of the tool OKA.
This is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This software is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU CC; see the file COPYING. If not, write to the Free
Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
TITLE: Parser of OKA (pipeline hazards description translator)
described as YACC file
DESCRIPTION: This file makes lexical, syntactic analysis
(with possible syntactic error recovery) of a file and
builds up internal representation of parsed pipeline
hazards description.
SPECIAL CONSIDERATION:
Defining macro `NDEBUG' (e.g. by option `-D' in C compiler
command line) during the file compilation disables to fix
some internal errors of parser work and errors of its usage.
*/
%{
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif /* #ifdef HAVE_CONFIG_H */
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include "position.h"
#include "errors.h"
#include "ird.h"
#include "common.h"
#include "tab.h"
#include "yacc.h"
#include <assert.h>
/* The following variables and forward definitions of functions are
used in actions of YACC grammar. */
/* The following variable value is begin position of the last lexema returned
by the function `yylex'. */
static position_t current_lexema_position;
static void syntax_error (const char *s);
%}
/* Attributes of all YACC symbols (token and nonterminals) will be
`node'. Some construction YACC action will be `position'. */
%union
{
IR_node_t node;
position_t position;
integer_t inumber;
}
/* The attributes of the following tokens are not defined and not used. */
%token PERCENTS COMMA COLON SEMICOLON LEFT_PARENTHESIS RIGHT_PARENTHESIS
LEFT_BRACKET RIGHT_BRACKET LEFT_ANGLE_BRACKET RIGHT_ANGLE_BRACKET
PLUS BAR STAR
LOCAL IMPORT EXPORT AUTOMATON UNIT EXCLUSION
NOTHING INPUT RESULT INSTRUCTION RESERVATION
/* The attributes of the following tokens are defined and used. */
%token <node> IDENTIFIER NUMBER CODE_INSERTION ADDITIONAL_C_CODE
%type <node> declaration_part declaration identifier_declaration
instruction_declaration reservation_declaration
unit_declaration optional_automaton_identifier
automaton_declaration exclusion_clause identifier_list
expression_definition_list expression_definition
instruction_or_reservation_identifier_list
instruction_or_reservation_identifier expression
unit_or_reservation_identifier
%type <inumber> input_result_number
%left BAR
%left PLUS
IDENTIFIER NOTHING INPUT RESULT
LEFT_PARENTHESIS LEFT_BRACKET /* for concatenation. */
%left STAR
%start description
%%
description : declaration_part PERCENTS
{
$<position>$ = current_lexema_position;
}
expression_definition_list ADDITIONAL_C_CODE
{
IR_node_t first_declaration;
IR_node_t first_expression_definition;
/* Transform cyclic declaration list to usual list. */
if ($1 != NULL)
{
first_declaration = IR_next_declaration ($1);
IR_set_next_declaration ($1, NULL);
$1 = first_declaration;
}
/* Transform cyclic expression definition list to
usual list. */
if ($4 != NULL)
{
first_expression_definition
= IR_next_expression_definition ($4);
IR_set_next_expression_definition ($4, NULL);
$4 = first_expression_definition;
}
description
= IR_new_description
(($1 == NULL ? $<position>3 : IR_position ($1)),
$1, $4, $5);
}
;
/* The attribute of the following nonterminal is the last declaration
of given declaration list. The declaration list is cyclic. */
declaration_part : {$$ = NULL;}
| declaration_part declaration
{
if ($1 == NULL)
/* Make cycle. */
IR_set_next_declaration ($2, $2);
else
{
/* Add element to cyclic list */
IR_set_next_declaration ($2,
IR_next_declaration ($1));
IR_set_next_declaration ($1, $2);
}
$$ = $2;
}
| declaration_part error
{
syntax_error ("syntax error in declaration");
$$ = $1; /* Ignore error declaration. */
}
;
declaration : identifier_declaration
{
IR_node_t first_identifier;
if (IR_identifier_list ($1) != NULL)
{
/* Transform cyclic list to usual list. */
first_identifier
= IR_next_identifier (IR_identifier_list ($1));
IR_set_next_identifier (IR_identifier_list ($1), NULL);
IR_set_identifier_list ($1, first_identifier);
}
if (IR_IS_OF_TYPE ($1, IR_NM_exclusion_clause)
&& IR_identifier_list_2 ($1) != NULL)
{
/* Transform cyclic list to usual list. */
first_identifier
= IR_next_identifier (IR_identifier_list_2 ($1));
IR_set_next_identifier (IR_identifier_list_2 ($1), NULL);
IR_set_identifier_list_2 ($1, first_identifier);
}
$$ = $1;
}
| LOCAL {$<position>$ = current_lexema_position;} CODE_INSERTION
{
$$ = IR_new_local_code ($<position>2, NULL, $3);
}
| IMPORT {$<position>$ = current_lexema_position;} CODE_INSERTION
{
$$ = IR_new_import_code ($<position>2, NULL, $3);
}
| EXPORT {$<position>$ = current_lexema_position;} CODE_INSERTION
{
$$ = IR_new_export_code ($<position>2, NULL, $3);
}
;
/* The attribute of the following nonterminal is an identifier
declaration whose identifier list refers to last identifier and the
identifier list is cyclic. */
identifier_declaration : instruction_declaration {$$ = $1;}
| reservation_declaration {$$ = $1;}
| unit_declaration {$$ = $1;}
| automaton_declaration {$$ = $1;}
| exclusion_clause {$$ = $1;}
;
/* The attribute of the following nonterminal is instruction
declaration whose identifier list refers to last identifier and the
identifier list is cyclic. */
instruction_declaration : INSTRUCTION
{
$$
= IR_new_instruction_declaration
(current_lexema_position, NULL, NULL);
}
| instruction_declaration IDENTIFIER
{
if (IR_identifier_list ($1) == NULL)
/* Make cycle */
IR_set_next_identifier ($2, $2);
else
{
/* Add element to cyclic list */
IR_set_next_identifier
($2, IR_next_identifier (IR_identifier_list
($1)));
IR_set_next_identifier
(IR_identifier_list ($1), $2);
}
IR_set_identifier_list ($1, $2);
$$ = $1;
}
;
/* The attribute of the following nonterminal is reservation
declaration whose identifier list refers to last identifier and the
identifier list is cyclic. */
reservation_declaration : RESERVATION
{
$$
= IR_new_reservation_declaration
(current_lexema_position, NULL, NULL);
}
| reservation_declaration IDENTIFIER
{
if (IR_identifier_list ($1) == NULL)
/* Make cycle */
IR_set_next_identifier ($2, $2);
else
{
/* Add element to cyclic list */
IR_set_next_identifier
($2,
IR_next_identifier (IR_identifier_list
($1)));
IR_set_next_identifier
(IR_identifier_list ($1), $2);
}
IR_set_identifier_list ($1, $2);
$$ = $1;
}
;
/* The attribute of the following nonterminal is unit declaration whose
identifier list refers to last identifier and the identifier list
is cyclic. */
unit_declaration : UNIT optional_automaton_identifier
{
$$ = IR_new_unit_declaration (current_lexema_position,
NULL, NULL, $2);
}
| unit_declaration IDENTIFIER
{
if (IR_identifier_list ($1) == NULL)
/* Make cycle */
IR_set_next_identifier ($2, $2);
else
{
/* Add element to cyclic list */
IR_set_next_identifier
($2, IR_next_identifier (IR_identifier_list
($1)));
IR_set_next_identifier
(IR_identifier_list ($1), $2);
}
IR_set_identifier_list ($1, $2);
$$ = $1;
}
;
exclusion_clause : EXCLUSION {$<position>$ = current_lexema_position;}
identifier_list COLON identifier_list
{
$$ = IR_new_exclusion_clause ($<position>2,
NULL, $3, $5);
}
;
/* The attribute of the following nonterminal is the last element in
the cyclic identifier list. */
identifier_list : IDENTIFIER
{
IR_set_next_identifier ($1, $1);
$$ = $1;
}
| identifier_list IDENTIFIER
{
/* Add element to cyclic list */
IR_set_next_identifier ($2, IR_next_identifier ($1));
IR_set_next_identifier ($1, $2);
$$ = $1;
}
;
/* The attribute of the following nonterminal is automaton identifier
or NULL in the case of its absence. */
optional_automaton_identifier : {$$ = NULL;}
| LEFT_ANGLE_BRACKET
IDENTIFIER RIGHT_ANGLE_BRACKET
{$$ = $2;}
;
/* The attribute of the following nonterminal is automaton declaration
whose identifier list refers to last identifier and the identifier
list is cyclic. */
automaton_declaration
: AUTOMATON
{
$$ = IR_new_automaton_declaration (current_lexema_position,
NULL, NULL);
}
| automaton_declaration IDENTIFIER
{
if (IR_identifier_list ($1) == NULL)
/* Make cycle */
IR_set_next_identifier ($2, $2);
else
{
/* Add element to cyclic list */
IR_set_next_identifier
($2, IR_next_identifier (IR_identifier_list
($1)));
IR_set_next_identifier
(IR_identifier_list ($1), $2);
}
IR_set_identifier_list ($1, $2);
$$ = $1;
}
;
/* The attribute of the following nonterminal is last expression
definition of given expression definition list. The expression
definition list is cyclic. */
expression_definition_list : {$$ = NULL; }
| expression_definition_list expression_definition
{
if ($1 != NULL)
{
IR_node_t first_expression;
/* Add cyclic list to the first
cyclic list. */
first_expression
= IR_next_expression_definition ($2);
IR_set_next_expression_definition
($2,
IR_next_expression_definition ($1));
IR_set_next_expression_definition
($1, first_expression);
}
$$ = $2;
}
| expression_definition_list error SEMICOLON
{
syntax_error
("syntax error in expression definition");
$$ = $1; /* Ignore error expression. */
}
| expression_definition_list error ADDITIONAL_C_CODE
{
yychar = ADDITIONAL_C_CODE;
syntax_error
("syntax error in expression definition");
$$ = $1; /* Ignore error expression. */
}
;
/* Attribute of this nonterminal is node representing last of
expression definition of expression definitions list corresponding
to given construction. */
expression_definition : instruction_or_reservation_identifier_list COLON
expression SEMICOLON
{
IR_node_t first_expression_definition;
IR_node_t current_expression_definition;
assert ($1 != NULL);
/* Set up expression for expression definitions. */
first_expression_definition
= IR_next_expression_definition ($1);
current_expression_definition
= first_expression_definition;
for (;;)
{
IR_set_expression
(current_expression_definition, $3);
if (current_expression_definition == $1)
break;
current_expression_definition
= IR_next_expression_definition
(current_expression_definition);
}
$$ = $1;
}
;
/* Attribute of this nonterminal is node representing last of
expression definition of expression definitions list in given
expression definition identifier list. */
instruction_or_reservation_identifier_list
: instruction_or_reservation_identifier
{
IR_set_next_expression_definition ($1, $1);
$$ = $1;
}
| instruction_or_reservation_identifier_list
COMMA instruction_or_reservation_identifier
{
assert ($1 != NULL);
/* Add element to cyclic list */
IR_set_next_expression_definition
($3, IR_next_expression_definition ($1));
IR_set_next_expression_definition ($1, $3);
$$ = $3;
}
;
instruction_or_reservation_identifier
: IDENTIFIER
{
$$ = IR_new_expression_definition (current_lexema_position, $1);
}
;
expression : expression IDENTIFIER
{
yychar = IDENTIFIER;
$<position>$ = current_lexema_position;
}
expression
{
$$ = IR_new_new_cycle_concatenation ($<position>3, $1, $4);
}
| expression NOTHING
{
yychar = NOTHING;
$<position>$ = current_lexema_position;
}
expression
{
$$ = IR_new_new_cycle_concatenation ($<position>3, $1, $4);
}
| expression RESULT
{
yychar = RESULT;
$<position>$ = current_lexema_position;
}
expression
{
$$ = IR_new_new_cycle_concatenation ($<position>3, $1, $4);
}
| expression INPUT
{
yychar = INPUT;
$<position>$ = current_lexema_position;
}
expression
{
$$ = IR_new_new_cycle_concatenation ($<position>3, $1, $4);
}
| expression LEFT_PARENTHESIS
{
yychar = LEFT_PARENTHESIS;
$<position>$ = current_lexema_position;
}
expression
{
$$ = IR_new_new_cycle_concatenation ($<position>3, $1, $4);
}
| expression LEFT_BRACKET
{
yychar = LEFT_BRACKET;
$<position>$ = current_lexema_position;
}
expression
{
$$ = IR_new_new_cycle_concatenation ($<position>3, $1, $4);
}
| expression PLUS {$<position>$ = current_lexema_position;}
expression
{
$$ = IR_new_concatenation ($<position>3, $1, $4);
}
| expression STAR {$<position>$ = current_lexema_position;} NUMBER
{
$$ = IR_new_repetition ($<position>3, $1, $4);
}
| LEFT_PARENTHESIS expression RIGHT_PARENTHESIS {$$ = $2;}
| LEFT_BRACKET {$<position>$ = current_lexema_position;}
expression RIGHT_BRACKET
{
$$ = IR_new_optional_expression ($<position>2, $3);
}
| expression BAR {$<position>$ = current_lexema_position;}
expression
{
$$ = IR_new_alternative ($<position>3, $1, $4);
}
| unit_or_reservation_identifier
{
$$ = IR_new_expression_atom (IR_position ($1), $1);
}
| NOTHING
{
$$ = IR_new_nothing (current_lexema_position);
}
| RESULT input_result_number
{
$$ = IR_new_result (current_lexema_position, $2);
}
| INPUT input_result_number
{
$$ = IR_new_input (current_lexema_position, $2);
}
;
input_result_number : {$$ = 0;}
| NUMBER {$$ = IR_number_value ($1);}
;
unit_or_reservation_identifier : IDENTIFIER {$$ = $1;}
;
%%
/* This page contains abstract data `scanner'. This abstract data
divides input stream characters on tokens (lexemas). */
/* The following structure describes current input stream and scanner
state. */
struct input_stream_state
{
FILE *input_file;
/* The following member is TRUE if the first `%%' in given input stream
was already processed or FALSE otherwise. */
int it_is_first_percents;
/* The following member is TRUE if the ADDITIONAL_CODE lexema was already
returned by the scanner or FALSE otherwise. Remember that lexema
ADDITIONAL_CODE is always returned by the scanner
even if second `%%' in the input stream is absent. */
int additional_c_code_was_returned;
};
/* The following structure contains current input stream and
scanner state. If the member `input_file' value is NULL
then input stream is not defined. */
static struct input_stream_state current_input_stream_state;
/* The function returns lexical code of corresponding keyword or 0 if
given identifier (parameter `str' is identifier (without start `%')
string with end marker '\0'; `length' is length of identifier
string without end marker '\0') is not keyword. Fast search is
implemented by minimal pruned O-trie forest. */
static int
find_keyword (const char *str, int length)
{
switch (length)
{
case 4:
return (strcmp (str, "unit") == 0 ? UNIT : 0);
case 5:
return (strcmp (str, "local") == 0 ? LOCAL : 0);
case 6:
switch (*str)
{
case 'e':
return (strcmp (str, "export") == 0 ? EXPORT : 0);
case 'i':
return (strcmp (str, "import") == 0 ? IMPORT : 0);
default:
return 0;
}
case 7:
return (strcmp (str, "nothing") == 0 ? NOTHING : 0);
case 9:
if (*str == 'e')
return (strcmp (str, "exclusion") == 0 ? EXCLUSION : 0);
else
return (strcmp (str, "automaton") == 0 ? AUTOMATON : 0);
case 11:
switch (*str)
{
case 'i':
return (strcmp (str, "instruction") == 0 ? INSTRUCTION : 0);
case 'r':
return (strcmp (str, "reservation") == 0 ? RESERVATION : 0);
default:
return 0;
}
default:
return 0;
}
}
/* The following value is used if previous_char does not contain an
input char */
#define EMPTY_PREVIOUS_CHAR (-2000)
/* The following variable is used for storing '\r'. */
static int previous_char;
/* The following two functions for replacing "\r\n" onto "\n". */
static int
getch (FILE *f)
{
int c;
if (previous_char != '\r')
c = getc (f);
else
{
c = previous_char;
previous_char = EMPTY_PREVIOUS_CHAR;
}
if (c == '\r')
{
c = getc (f);
if (c != '\n')
{
ungetc (c, f);
c = '\r';
}
}
return c;
}
static void
ungetch (int c, FILE *f)
{
if (c != '\r')
ungetc (c, f);
else
previous_char = c;
}
/* The function skips C commentary. Parameter `store_flag' is flag of
storing commentary characters onto top internal representation
object. The function returns TRUE if no error (EOF) was fixed,
otherwise FALSE
Current position corresponds to `*' after commentary start ('/')
before the function call. Current_position corresponds to first
character after skipped commentary ('/') or EOF after the function
call. */
static int
skip_commentary (int store_flag)
{
int input_char;
current_position.column_number++;
if (store_flag)
IR_TOP_ADD_BYTE ('*');
for (;;)
{
input_char = getch (current_input_stream_state.input_file);
/* Here `current_position' corresponds to `input_char'. */
if (input_char == '*')
{
if (store_flag)
IR_TOP_ADD_BYTE (input_char);
input_char = getch (current_input_stream_state.input_file);
current_position.column_number++;
/* Here `current_position' corresponds to `input_char'. */
if (input_char == '/')
{
if (store_flag)
IR_TOP_ADD_BYTE (input_char);
current_position.column_number++;
return TRUE;
}
else
{
ungetch (input_char, current_input_stream_state.input_file);
continue;
}
}
else if (input_char == EOF)
{
ungetch (input_char, current_input_stream_state.input_file);
return FALSE;
}
if (input_char == '\n')
{
current_position.column_number = 1;
current_position.line_number++;
}
else if (input_char == '\t')
current_position.column_number
= ((current_position.column_number - 1) / TAB_STOP + 1)
* TAB_STOP + 1;
else
current_position.column_number++;
if (store_flag)
IR_TOP_ADD_BYTE (input_char);
}
}
/* The function skips C string code (e.g `a', `\n', or `\077'). The
function also stores skipped characters onto top internal
representation object. Parameter `input_char' is the most recent
read character. The function returns (with the aid of parameter
`correct_new_line') flag of that correct new line was read. The
function returns TRUE if no error (EOF or incorrect new line) was
fixed, otherwise FALSE.
The value of parameter `correct_new_line' can be used for fixing
errors when character constant is processed. It is supposed that
the current character is not end marker (string or character
constant). Current position corresponds to parameter `input_char'
before the function call. Current_position corresponds to first
character after skipped valid character code or EOF (or incorrect
new line) after the function call. */
static int
skip_string_code (int input_char, int *correct_new_line)
{
if (input_char == EOF || input_char == '\n')
{
ungetch (input_char, current_input_stream_state.input_file);
return FALSE;
}
*correct_new_line = FALSE;
IR_TOP_ADD_BYTE (input_char);
if (input_char == '\\')
{
current_position.column_number++;
input_char = getch (current_input_stream_state.input_file);
IR_TOP_ADD_BYTE (input_char);
if (input_char == 'n' || input_char == 't' || input_char == 'v'
|| input_char == 'b' || input_char == 'r' || input_char == 'f'
|| input_char == '\\' || input_char == '\'' || input_char == '\"')
current_position.column_number++;
else if (input_char == '\n')
{
current_position.column_number = 1;
current_position.line_number++;
*correct_new_line = TRUE;
}
else if (isdigit (input_char) && input_char != '8'
&& input_char != '9')
{
current_position.column_number++;
input_char = getch (current_input_stream_state.input_file);
if (!isdigit (input_char) || input_char == '8'
|| input_char == '9')
ungetch (input_char, current_input_stream_state.input_file);
else
{
current_position.column_number++;
IR_TOP_ADD_BYTE (input_char);
input_char = getch (current_input_stream_state.input_file);
if (!isdigit (input_char) || input_char == '8'
|| input_char == '9')
ungetch (input_char, current_input_stream_state.input_file);
else
{
current_position.column_number++;
IR_TOP_ADD_BYTE (input_char);
}
}
}
else
current_position.column_number++;
}
else if (input_char == '\t')
current_position.column_number
= ((current_position.column_number - 1) / TAB_STOP + 1) * TAB_STOP + 1;
else
current_position.column_number++;
return TRUE;
}
/* The function skips C character constant by using function
`skip_string_code'. The function may fix error in the C character
constant. The function also stores skipped characters onto top
internal representation object. Current position corresponds to
first character after '\'' (which was already read) before the
function call. Current_position corresponds to to first character
after '\'' if error was not fixed after the function call. */
static void
skip_C_character (void)
{
int input_char;
int correct_new_line;
int error_flag;
error_flag = FALSE;
input_char = getch (current_input_stream_state.input_file);
/* Here `current_position' corresponds to `input_char'. */
if (input_char == '\'')
{
IR_TOP_ADD_BYTE (input_char);
error (FALSE, current_position, "invalid character constant");
current_position.column_number++;
error_flag = TRUE;
}
else
{
if (!skip_string_code (input_char, &correct_new_line)
|| correct_new_line)
{
error (FALSE, current_position, "invalid character constant");
error_flag = TRUE;
}
}
input_char = getch (current_input_stream_state.input_file);
if (input_char != '\'')
{
ungetch (input_char, current_input_stream_state.input_file);
if (!error_flag)
error (FALSE, current_position, "invalid character constant");
}
else
{
IR_TOP_ADD_BYTE (input_char);
current_position.column_number++;
}
}
/* The function skips C string constant by using function
`skip_string_code'. The function may fix error in the C string
constant. The function also stores skipped characters onto top
internal representation object. Current position corresponds to
first character after '\"' (which was already read) before the
function call. Current_position corresponds to to first character
after '\"' if error was not fixed after the function call. */
static void
skip_C_string (void)
{
int input_char;
int correct_new_line;
for (;;)
{
/* Here `current_position' corresponds to next character. */
input_char = getch (current_input_stream_state.input_file);
if (input_char == '\"')
{
current_position.column_number++;
IR_TOP_ADD_BYTE (input_char);
break;
}
if (!skip_string_code (input_char, &correct_new_line))
{
error (FALSE, current_position, "string end is absent");
break;
}
}
}
/* This function is major scanner function. The function recognizes
next source lexema from the input file, returns its code, modifies
variable current_position so that its value is equal to position of
the current character in the current input file and sets up
variable `current_lexema_position' so that its value is equal to
start position of the returned lexema, creates corresponding
internal representation node (if it is needed) and sets up yylval
to the node. The function skips all white spaces and commentaries
and fixes the most of lexical errors. */
int
yylex (void)
{
int input_char;
int number_of_successive_error_characters;
for (number_of_successive_error_characters = 0;;)
{
input_char = getch (current_input_stream_state.input_file);
/* `current_position' corresponds `input_char' here */
switch (input_char)
{
case '\f':
/* flow-through */
case ' ':
current_position.column_number++;
break;
case '\t':
current_position.column_number
= ((current_position.column_number - 1) / TAB_STOP + 1)
* TAB_STOP + 1;
break;
case '\n':
current_position.column_number = 1;
current_position.line_number++;
break;
case EOF:
current_lexema_position = current_position;
if (!current_input_stream_state.additional_c_code_was_returned)
{
char *additional_code_itself;
ungetch (input_char, current_input_stream_state.input_file);
current_input_stream_state.additional_c_code_was_returned = TRUE;
IR_TOP_ADD_BYTE ('\0');
additional_code_itself = IR_TOP_BEGIN ();
IR_TOP_FINISH ();
yylval.node = IR_new_additional_code (current_lexema_position,
additional_code_itself);
return ADDITIONAL_C_CODE;
}
else
return 0;
case '/':
current_lexema_position = current_position;
current_position.column_number++;
input_char = getch (current_input_stream_state.input_file);
if (input_char != '*')
{
number_of_successive_error_characters++;
if (number_of_successive_error_characters == 1)
error (FALSE, current_lexema_position,
"invalid input character '/'");
ungetch (input_char, current_input_stream_state.input_file);
}
else if (!skip_commentary (FALSE))
error (FALSE, current_lexema_position, "commentary end is absent");
break;
case '(':
current_lexema_position = current_position;
current_position.column_number++;
return LEFT_PARENTHESIS;
case ')':
current_lexema_position = current_position;
current_position.column_number++;
return RIGHT_PARENTHESIS;
case '[':
current_lexema_position = current_position;
current_position.column_number++;
return LEFT_BRACKET;
case ']':
current_lexema_position = current_position;
current_position.column_number++;
return RIGHT_BRACKET;
case '<':
current_lexema_position = current_position;
current_position.column_number++;
return LEFT_ANGLE_BRACKET;
case '>':
current_lexema_position = current_position;
current_position.column_number++;
return RIGHT_ANGLE_BRACKET;
case ';':
current_lexema_position = current_position;