1 /* Syntactic analyzer */
6 #include "global_vars.h"
7 #include "lexical_analyzer.h"
8 #include "print_helper.h"
12 /* Syntactic analyzer functions implementation */
14 enum TokenType tokenType
;
16 static void analyze_TEXT() {
18 fprintf(stdout
, "entering %s\n", __func__
);
20 if (tokenType
== MOT
) {
22 wprint_ctoken(stdout
);
25 fputws((const wchar_t*)tokenValue
, target
);
30 } else if (tokenType
!= MOTCLE
&& tokenType
!= NPARA
&& tokenType
!= SECTION
&& \
31 tokenType
!= SSECTION
&& tokenType
!= FIN
) {
32 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
37 fprintf(stdout
, "leaving %s\n", __func__
);
41 static void analyze_P() {
43 fprintf(stdout
, "entering %s\n", __func__
);
45 if (tokenType
== NPARA
) {
47 wprint_ctoken(stdout
);
48 #endif /* PRINT_TOKEN */
50 fputws(L
"<p>\n", target
);
55 fputws(L
"\n</p>\n", target
);
58 } else if (tokenType
!= SECTION
&& tokenType
!= SSECTION
&& tokenType
!= FIN
) {
59 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
64 fprintf(stdout
, "leaving %s\n", __func__
);
68 static void analyze_HEAD() {
70 fprintf(stdout
, "entering %s\n", __func__
);
72 if (tokenType
== MOTCLE
&& wcscmp(L
">Titre", (const wchar_t*)tokenValue
) == 0) {
74 fputws(L
"<title>\n", target
);
80 fputws(L
"\n</title>\n", target
);
82 if (tokenType
== MOTCLE
&& wcscmp(L
">Auteur", (const wchar_t*)tokenValue
) == 0) {
84 wprint_ctoken(stdout
);
85 #endif /* PRINT_TOKEN */
86 fputws(L
"<meta name=\"author\" content=\"", target
);
89 fputws(L
"\">", target
);
90 } else if (tokenType
!= NPARA
&& tokenType
!= SECTION
&& tokenType
!= FIN
) {
91 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
97 fprintf(stdout
, "leaving %s\n", __func__
);
101 static void analyze_H1() {
103 fprintf(stdout
, "entering %s\n", __func__
);
105 if (tokenType
== SECTION
) {
107 wprint_ctoken(stdout
);
108 #endif /* PRINT_TOKEN */
109 if (target
!= NULL
) {
110 fputws(L
"<h1>\n", target
);
114 if (target
!= NULL
) {
115 fputws(L
"\n</h1>\n", target
);
118 fprintf(stderr
, "%s error\n", __func__
);
123 fprintf(stdout
, "leaving %s\n", __func__
);
127 static void analyze_H2() {
129 fprintf(stdout
, "entering %s\n", __func__
);
131 if (tokenType
== SSECTION
) {
133 wprint_ctoken(stdout
);
134 #endif /* PRINT_TOKEN */
135 if (target
!= NULL
) {
136 fputws(L
"<h2>\n", target
);
140 if (target
!= NULL
) {
141 fputws(L
"\n</h2>\n", target
);
145 fprintf(stdout
, "leaving %s\n", __func__
);
149 static void analyze_S2() {
151 fprintf(stdout
, "entering %s\n", __func__
);
153 if (tokenType
== SSECTION
) {
157 } else if (tokenType
!= SECTION
&& tokenType
!= FIN
) {
158 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
163 fprintf(stdout
, "leaving %s\n", __func__
);
167 static void analyze_S1() {
169 fprintf(stdout
, "entering %s\n", __func__
);
171 if (tokenType
== SECTION
) {
176 } else if (tokenType
!= FIN
) {
177 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
182 fprintf(stdout
, "leaving %s\n", __func__
);
186 static void analyze_BODY() {
188 fprintf(stdout
, "entering %s\n", __func__
);
193 fprintf(stdout
, "leaving %s\n", __func__
);
197 void analyze_AXIOME() {
199 fprintf(stdout
, "entering %s\n", __func__
);
201 /* print the lexical analysis result */
203 wprint_ctoken(stdout
);
204 #endif /* PRINT_TOKEN */
205 if (target
!= NULL
) {
206 fputws(L
"<head>\n", target
);
209 if (target
!= NULL
) {
210 fputws(L
"\n</head>\n", target
);
212 if (target
!= NULL
) {
213 fputws(L
"<body>\n", target
);
216 if (target
!= NULL
) {
217 fputws(L
"\n<body>\n", target
);
220 wprint_ctoken(stdout
);
221 #endif /* PRINT_TOKEN */
222 if (tokenType
!= FIN
) {
223 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
227 fprintf(stdout
, "successful syntactic analysis\n");
229 fprintf(stdout
, "leaving %s\n", __func__
);