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
) {
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
);
52 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
) {
74 //FIXME: Check if the MOTCLE token value is set to >Titre
76 fputws(L
"<title>\n", target
);
82 fputws(L
"\n</title>\n", target
);
84 if (tokenType
== MOTCLE
) {
86 wprint_ctoken(stdout
);
87 #endif /* PRINT_TOKEN */
89 //The text contain the author
90 fputws(L
"<meta name=\"author\" content=\"", target
);
92 fputws(L
"\">", target
);
93 } else if (tokenType
!= NPARA
&& tokenType
!= SECTION
&& tokenType
!= FIN
) {
94 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
100 fprintf(stdout
, "leaving %s\n", __func__
);
104 static void analyze_H1() {
106 fprintf(stdout
, "entering %s\n", __func__
);
108 if (tokenType
== SECTION
) {
110 wprint_ctoken(stdout
);
111 #endif /* PRINT_TOKEN */
112 if (target
!= NULL
) {
113 fputws(L
"<h1>\n", target
);
117 if (target
!= NULL
) {
118 fputws(L
"\n</h1>\n", target
);
121 fprintf(stderr
, "%s error\n", __func__
);
126 fprintf(stdout
, "leaving %s\n", __func__
);
130 static void analyze_H2() {
132 fprintf(stdout
, "entering %s\n", __func__
);
134 if (tokenType
== SSECTION
) {
136 wprint_ctoken(stdout
);
137 #endif /* PRINT_TOKEN */
138 if (target
!= NULL
) {
139 fputws(L
"<h2>\n", target
);
143 if (target
!= NULL
) {
144 fputws(L
"\n</h2>\n", target
);
148 fprintf(stdout
, "leaving %s\n", __func__
);
152 static void analyze_S2() {
154 fprintf(stdout
, "entering %s\n", __func__
);
156 if (tokenType
== SSECTION
) {
160 } else if (tokenType
!= SECTION
&& tokenType
!= FIN
) {
161 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
166 fprintf(stdout
, "leaving %s\n", __func__
);
170 static void analyze_S1() {
172 fprintf(stdout
, "entering %s\n", __func__
);
174 if (tokenType
== SECTION
) {
179 } else if (tokenType
!= FIN
) {
180 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
185 fprintf(stdout
, "leaving %s\n", __func__
);
189 static void analyze_BODY() {
191 fprintf(stdout
, "entering %s\n", __func__
);
196 fprintf(stdout
, "leaving %s\n", __func__
);
200 void analyze_AXIOME() {
202 fprintf(stdout
, "entering %s\n", __func__
);
204 /* print the lexical analysis result */
206 wprint_ctoken(stdout
);
207 #endif /* PRINT_TOKEN */
208 if (target
!= NULL
) {
209 fputws(L
"<head>\n", target
);
212 if (target
!= NULL
) {
213 fputws(L
"\n</head>\n", target
);
215 if (target
!= NULL
) {
216 fputws(L
"<body>\n", target
);
219 if (target
!= NULL
) {
220 fputws(L
"\n<body>\n", target
);
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__
);