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
]);
35 fprintf(stdout
, "leaving %s\n", __func__
);
39 static void analyze_P() {
41 fprintf(stdout
, "entering %s\n", __func__
);
43 if (tokenType
== NPARA
) {
48 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
50 if (tokenType
== MOT
) {
55 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
59 } else if (tokenType
!= SECTION
&& tokenType
!= SSECTION
&& tokenType
!= FIN
) {
60 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
63 } else if (tokenType
!= SECTION
&& tokenType
!= SSECTION
&& tokenType
!= FIN
) {
64 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
68 fprintf(stdout
, "leaving %s\n", __func__
);
72 static void analyze_HEAD() {
74 fprintf(stdout
, "entering %s\n", __func__
);
76 if (tokenType
== MOTCLE
) {
81 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
84 if (tokenType
== MOTCLE
) {
88 #endif /* PRINT_TOKEN */
89 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
92 } else if (tokenType
!= NPARA
&& tokenType
!= SECTION
&& tokenType
!= FIN
) {
93 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
96 } else if (tokenType
!= NPARA
&& tokenType
!= SECTION
&& tokenType
!= FIN
) {
97 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
101 fprintf(stdout
, "leaving %s\n", __func__
);
105 static void analyze_H1() {
107 fprintf(stdout
, "entering %s\n", __func__
);
109 if (tokenType
== SECTION
) {
113 #endif /* PRINT_TOKEN */
114 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
119 fprintf(stdout
, "leaving %s\n", __func__
);
123 static void analyze_H2() {
125 fprintf(stdout
, "entering %s\n", __func__
);
127 if (tokenType
== SSECTION
) {
131 #endif /* PRINT_TOKEN */
132 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
137 fprintf(stdout
, "leaving %s\n", __func__
);
141 static void analyze_S2() {
143 fprintf(stdout
, "entering %s\n", __func__
);
145 if (tokenType
== SSECTION
) {
149 } else if (tokenType
!= SECTION
&& tokenType
!= FIN
) {
150 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
154 fprintf(stdout
, "leaving %s\n", __func__
);
158 static void analyze_S1() {
160 fprintf(stdout
, "entering %s\n", __func__
);
162 if (tokenType
== SECTION
) {
167 } else if (tokenType
!= FIN
) {
168 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
172 fprintf(stdout
, "leaving %s\n", __func__
);
176 static void analyze_BODY() {
178 fprintf(stdout
, "entering %s\n", __func__
);
183 fprintf(stdout
, "leaving %s\n", __func__
);
187 void analyze_AXIOME() {
189 fprintf(stdout
, "entering %s\n", __func__
);
192 /* print the lexical analysis result */
195 #endif /* PRINT_TOKEN */
196 token
[tokenFound
].type
= tokenTypestr
[tokenType
];
200 if (tokenType
!= FIN
) {
201 fprintf(stderr
, "%s follows error on %s\n", __func__
, tokenTypestr
[tokenType
]);
204 fprintf(stdout
, "successful syntactic analysis\n");
206 fprintf(stdout
, "leaving %s\n", __func__
);