1 /* Syntactic analyzer */
6 #include "global_vars.h"
7 #include "print_helper.h"
8 #include "syntactic_analyzer.h"
9 #include "lexical_analyzer.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
) {
23 wprint_ctoken(stdout
);
26 fputws((const wchar_t*)tokenValue
, target
);
31 } else if (tokenType
!= MOTCLE
&& tokenType
!= NPARA
&& tokenType
!= SECTION
&& \
32 tokenType
!= SSECTION
&& tokenType
!= FIN
) {
33 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
38 fprintf(stdout
, "leaving %s\n", __func__
);
42 static void analyze_P() {
44 fprintf(stdout
, "entering %s\n", __func__
);
46 if (tokenType
== NPARA
) {
48 wprint_ctoken(stdout
);
49 #endif /* PRINT_TOKEN */
51 fputws(L
"<p>\n", target
);
56 fputws(L
"\n</p>\n", target
);
59 } else if (tokenType
!= SECTION
&& tokenType
!= SSECTION
&& tokenType
!= FIN
) {
60 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
65 fprintf(stdout
, "leaving %s\n", __func__
);
69 static void analyze_HEAD() {
71 fprintf(stdout
, "entering %s\n", __func__
);
73 if (tokenType
== MOTCLE
&& wcscmp(L
">Titre", (const wchar_t*)tokenValue
) == 0) {
75 fputws(L
"<title>\n", target
);
81 fputws(L
"\n</title>\n", target
);
83 if (tokenType
== MOTCLE
&& wcscmp(L
">Auteur", (const wchar_t*)tokenValue
) == 0) {
85 wprint_ctoken(stdout
);
86 #endif /* PRINT_TOKEN */
87 fputws(L
"<meta name=\"author\" content=\"", target
);
90 fputws(L
"\">", target
);
91 } else if (tokenType
!= NPARA
&& tokenType
!= SECTION
&& tokenType
!= FIN
) {
92 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
98 fprintf(stdout
, "leaving %s\n", __func__
);
102 static void analyze_H1() {
104 fprintf(stdout
, "entering %s\n", __func__
);
106 if (tokenType
== SECTION
) {
108 wprint_ctoken(stdout
);
109 #endif /* PRINT_TOKEN */
110 if (target
!= NULL
) {
111 fputws(L
"<h1>\n", target
);
115 if (target
!= NULL
) {
116 fputws(L
"\n</h1>\n", target
);
119 fprintf(stderr
, "%s error\n", __func__
);
124 fprintf(stdout
, "leaving %s\n", __func__
);
128 static void analyze_H2() {
130 fprintf(stdout
, "entering %s\n", __func__
);
132 if (tokenType
== SSECTION
) {
134 wprint_ctoken(stdout
);
135 #endif /* PRINT_TOKEN */
136 if (target
!= NULL
) {
137 fputws(L
"<h2>\n", target
);
141 if (target
!= NULL
) {
142 fputws(L
"\n</h2>\n", target
);
146 fprintf(stdout
, "leaving %s\n", __func__
);
150 static void analyze_S2() {
152 fprintf(stdout
, "entering %s\n", __func__
);
154 if (tokenType
== SSECTION
) {
158 } else if (tokenType
!= SECTION
&& tokenType
!= FIN
) {
159 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
164 fprintf(stdout
, "leaving %s\n", __func__
);
168 static void analyze_S1() {
170 fprintf(stdout
, "entering %s\n", __func__
);
172 if (tokenType
== SECTION
) {
177 } else if (tokenType
!= FIN
) {
178 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
183 fprintf(stdout
, "leaving %s\n", __func__
);
187 static void analyze_BODY() {
189 fprintf(stdout
, "entering %s\n", __func__
);
194 fprintf(stdout
, "leaving %s\n", __func__
);
198 void analyze_AXIOME(void) {
200 fprintf(stdout
, "entering %s\n", __func__
);
202 /* print the lexical analysis result */
204 wprint_ctoken(stdout
);
205 #endif /* PRINT_TOKEN */
206 if (target
!= NULL
) {
207 fputws(L
"<head>\n", target
);
210 if (target
!= NULL
) {
211 fputws(L
"\n</head>\n", target
);
213 if (target
!= NULL
) {
214 fputws(L
"<body>\n", target
);
217 if (target
!= NULL
) {
218 fputws(L
"\n<body>\n", target
);
221 wprint_ctoken(stdout
);
222 #endif /* PRINT_TOKEN */
223 if (tokenType
!= FIN
) {
224 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
228 fprintf(stdout
, "successful syntactic analysis\n");
230 fprintf(stdout
, "leaving %s\n", __func__
);