8d2d2e93837565b1fe4f60085ee01623c377180f
1 /* Syntactic analyzer */
7 #include "global_vars.h"
8 #include "lexical_analyzer.h"
9 #include "print_helper.h"
13 /* Syntactic analyzer functions implementation */
15 enum TokenType tokenType
;
17 static void analyze_TEXT() {
19 fprintf(stdout
, "entering %s\n", __func__
);
21 if (tokenType
== MOT
) {
26 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
29 } else if (tokenType
!= MOTCLE
&& tokenType
!= NPARA
&& tokenType
!= SECTION
&& \
30 tokenType
!= SSECTION
&& tokenType
!= FIN
) {
31 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
36 fprintf(stdout
, "leaving %s\n", __func__
);
40 static void analyze_P() {
42 fprintf(stdout
, "entering %s\n", __func__
);
44 if (tokenType
== NPARA
) {
49 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
51 if (tokenType
== MOT
) {
56 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
60 } else if (tokenType
!= SECTION
&& tokenType
!= SSECTION
&& tokenType
!= FIN
) {
61 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
65 } else if (tokenType
!= SECTION
&& tokenType
!= SSECTION
&& tokenType
!= FIN
) {
66 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
71 fprintf(stdout
, "leaving %s\n", __func__
);
75 static void analyze_HEAD() {
77 fprintf(stdout
, "entering %s\n", __func__
);
79 if (tokenType
== MOTCLE
) {
84 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
87 if (tokenType
== MOTCLE
) {
91 #endif /* PRINT_TOKEN */
92 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
95 } else if (tokenType
!= NPARA
&& tokenType
!= SECTION
&& tokenType
!= FIN
) {
96 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
100 } else if (tokenType
!= NPARA
&& tokenType
!= SECTION
&& tokenType
!= FIN
) {
101 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
106 fprintf(stdout
, "leaving %s\n", __func__
);
110 static void analyze_H1() {
112 fprintf(stdout
, "entering %s\n", __func__
);
114 if (tokenType
== SECTION
) {
118 #endif /* PRINT_TOKEN */
119 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
124 fprintf(stdout
, "leaving %s\n", __func__
);
128 static void analyze_H2() {
130 fprintf(stdout
, "entering %s\n", __func__
);
132 if (tokenType
== SSECTION
) {
136 #endif /* PRINT_TOKEN */
137 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
142 fprintf(stdout
, "leaving %s\n", __func__
);
146 static void analyze_S2() {
148 fprintf(stdout
, "entering %s\n", __func__
);
150 if (tokenType
== SSECTION
) {
154 } else if (tokenType
!= SECTION
&& tokenType
!= FIN
) {
155 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
160 fprintf(stdout
, "leaving %s\n", __func__
);
164 static void analyze_S1() {
166 fprintf(stdout
, "entering %s\n", __func__
);
168 if (tokenType
== SECTION
) {
173 } else if (tokenType
!= FIN
) {
174 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
179 fprintf(stdout
, "leaving %s\n", __func__
);
183 static void analyze_BODY() {
185 fprintf(stdout
, "entering %s\n", __func__
);
190 fprintf(stdout
, "leaving %s\n", __func__
);
194 void analyze_AXIOME() {
196 fprintf(stdout
, "entering %s\n", __func__
);
199 /* print the lexical analysis result */
202 #endif /* PRINT_TOKEN */
203 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
207 if (tokenType
!= FIN
) {
208 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
212 fprintf(stdout
, "successful syntactic analysis\n");
214 fprintf(stdout
, "leaving %s\n", __func__
);