29524f01f7b39d82d2328f3c773be5565941d30e
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
) {
24 fputws((const wchar_t*)token
[tokenFound
].value
, target
);
28 wprint_token_stdout();
30 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
33 } else if (tokenType
!= MOTCLE
&& tokenType
!= NPARA
&& tokenType
!= SECTION
&& \
34 tokenType
!= SSECTION
&& tokenType
!= FIN
) {
35 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
40 fprintf(stdout
, "leaving %s\n", __func__
);
44 static void analyze_P() {
46 fprintf(stdout
, "entering %s\n", __func__
);
48 if (tokenType
== NPARA
) {
51 wprint_token_stdout();
54 fputws(L
"<p>\n", target
);
55 fputws((const wchar_t*)token
[tokenFound
].value
, target
);
58 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
60 if (tokenType
== MOT
) {
63 wprint_token_stdout();
66 fputws((const wchar_t*)token
[tokenFound
].value
, target
);
69 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
73 fputws(L
"\n</p>\n", target
);
76 } else if (tokenType
!= SECTION
&& tokenType
!= SSECTION
&& tokenType
!= FIN
) {
77 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
83 fprintf(stdout
, "leaving %s\n", __func__
);
87 static void analyze_HEAD() {
89 fprintf(stdout
, "entering %s\n", __func__
);
91 if (tokenType
== MOTCLE
) {
94 wprint_token_stdout();
95 #endif /* PRINT_TOKEN */
96 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
98 //FIXME: Check if the MOTCLE token value is set to >Titre
100 fputws(L
"<title>\n", target
);
101 fputws((const wchar_t*)token
[tokenFound
].value
, target
);
102 fputws(L
" ", target
);
105 if (target
!= NULL
) {
106 fputws(L
"\n</title>\n", target
);
108 if (tokenType
== MOTCLE
) {
111 wprint_token_stdout();
112 #endif /* PRINT_TOKEN */
113 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
115 //The text contain the author
117 } else if (tokenType
!= NPARA
&& tokenType
!= SECTION
&& tokenType
!= FIN
) {
118 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
124 fprintf(stdout
, "leaving %s\n", __func__
);
128 static void analyze_H1() {
130 fprintf(stdout
, "entering %s\n", __func__
);
132 if (tokenType
== SECTION
) {
135 wprint_token_stdout();
136 #endif /* PRINT_TOKEN */
137 if (target
!= NULL
) {
138 fputws(L
"<h1>\n", target
);
139 fputws((const wchar_t*)token
[tokenFound
].value
, target
);
140 fputws(L
" ", target
);
142 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
145 if (target
!= NULL
) {
146 fputws(L
"\n</h1>\n", target
);
150 fprintf(stdout
, "leaving %s\n", __func__
);
154 static void analyze_H2() {
156 fprintf(stdout
, "entering %s\n", __func__
);
158 if (tokenType
== SSECTION
) {
161 wprint_token_stdout();
162 #endif /* PRINT_TOKEN */
163 if (target
!= NULL
) {
164 fputws(L
"<h2>\n", target
);
165 fputws((const wchar_t*)token
[tokenFound
].value
, target
);
166 fputws(L
" ", target
);
168 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
171 if (target
!= NULL
) {
172 fputws(L
"\n</h2>\n", target
);
176 fprintf(stdout
, "leaving %s\n", __func__
);
180 static void analyze_S2() {
182 fprintf(stdout
, "entering %s\n", __func__
);
184 //FIXME: This test is probably useless
185 if (tokenType
== SSECTION
) {
189 } else if (tokenType
!= SECTION
&& tokenType
!= FIN
) {
190 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
195 fprintf(stdout
, "leaving %s\n", __func__
);
199 static void analyze_S1() {
201 fprintf(stdout
, "entering %s\n", __func__
);
203 //FIXME: This test is probably useless
204 if (tokenType
== SECTION
) {
209 } else if (tokenType
!= FIN
) {
210 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
215 fprintf(stdout
, "leaving %s\n", __func__
);
219 static void analyze_BODY() {
221 fprintf(stdout
, "entering %s\n", __func__
);
226 fprintf(stdout
, "leaving %s\n", __func__
);
230 void analyze_AXIOME() {
232 fprintf(stdout
, "entering %s\n", __func__
);
235 /* print the lexical analysis result */
237 wprint_token_stdout();
238 #endif /* PRINT_TOKEN */
239 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
241 if (target
!= NULL
) {
242 fputws(L
"<head>\n", target
);
245 if (target
!= NULL
) {
246 fputws(L
"\n</head>\n", target
);
248 if (target
!= NULL
) {
249 fputws(L
"<body>\n", target
);
252 if (target
!= NULL
) {
253 fputws(L
"\n<body>\n", target
);
255 if (tokenType
!= FIN
) {
256 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
260 fprintf(stdout
, "successful syntactic analysis\n");
262 fprintf(stdout
, "leaving %s\n", __func__
);