#ifndef lint static char const yyrcsid[] = "$FreeBSD: src/usr.bin/yacc/skeleton.c,v 1.28 2000/01/17 02:04:06 bde Exp $"; #endif #include #define YYBYACC 1 #define YYMAJOR 1 #define YYMINOR 9 #define YYLEX yylex() #define YYEMPTY -1 #define yyclearin (yychar=(YYEMPTY)) #define yyerrok (yyerrflag=0) #define YYRECOVERING() (yyerrflag!=0) static int yygrowstack(); #define YYPREFIX "yy" #line 2 "html.y" /* La structure permet de mémoriser pour chaque noeud de l'arbre * texte : la partie du source correspondante, * hauteur : la longueur de la branche la plus profonde. */ struct info { char *texte; int hauteur; }; #define YYSTYPE struct info /* Les options sont positionnées par les arguments de la ligne de commande * optionHauteur == 1 si la hauteur doit être affichée * optionMarque == 1 si le source doit être normalisé * optionExtraire == i pour extraire la première section Hi * extraction == 1 pendant l'extraction */ int optionHauteur = 0; int optionMarque = 0; int optionExtraire = 0; int extraction = 1; /* Pour éviter des "WARNING" à la compilation */ void yyerror(char *s); int yyparse(void); #line 43 "y.tab.c" #define YYERRCODE 256 #define HTML_O 257 #define HTML_F 258 #define HEAD_O 259 #define HEAD_F 260 #define TITLE_O 261 #define TITLE_F 262 #define BODY_O 263 #define BODY_F 264 #define H1_O 265 #define H1_F 266 #define H2_O 267 #define H2_F 268 #define H3_O 269 #define H3_F 270 #define H4_O 271 #define H4_F 272 #define H5_O 273 #define H5_F 274 #define H6_O 275 #define H6_F 276 #define EM_O 277 #define EM_F 278 #define B_O 279 #define B_F 280 #define P_O 281 #define P_F 282 #define OL_O 283 #define OL_F 284 #define LI_O 285 #define LI_F 286 #define CHAINE 287 const short yylhs[] = { -1, 0, 1, 3, 2, 4, 4, 4, 5, 5, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, }; const short yylen[] = { 2, 4, 3, 3, 3, 2, 2, 0, 3, 3, 3, 3, 3, 3, 2, 0, 1, 3, 3, 3, 2, 3, 2, 0, 3, 2, }; const short yydefred[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 14, 8, 9, 10, 11, 12, 13, 17, 18, 19, 0, 21, 22, 24, }; const short yydgoto[] = { 2, 4, 8, 6, 22, 23, 24, 25, 38, 39, }; const short yysindex[] = { -247, -241, 0, -235, -233, -259, -228, -218, -224, -223, 0, -246, -244, -239, -237, -231, -229, -275, -275, -275, -225, 0, -212, -218, -218, -275, 0, 0, -204, -195, -216, -208, -197, -198, -199, -200, -201, -275, -202, -225, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -203, 0, 0, 0, }; const short yyrindex[] = { 0, 0, 0, 0, 0, 0, 0, -180, 0, 0, 0, 0, 0, 0, 0, 0, 0, -193, -192, -240, -194, 0, 0, -180, -180, -240, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -264, -214, 0, -194, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -248, 0, 0, 0, }; const short yygindex[] = { 0, 0, 0, 0, 52, 0, 49, 0, 48, 0, }; #define YYTABLESIZE 90 const short yytable[] = { 20, 20, 17, 20, 18, 20, 19, 20, 20, 20, 1, 20, 21, 20, 20, 20, 20, 20, 3, 20, 20, 20, 20, 20, 15, 15, 5, 15, 9, 15, 7, 15, 10, 15, 26, 15, 25, 25, 15, 27, 15, 28, 15, 29, 15, 15, 15, 11, 30, 12, 31, 13, 40, 14, 46, 15, 32, 16, 33, 17, 37, 18, 44, 19, 47, 20, 34, 35, 36, 21, 15, 15, 15, 45, 43, 41, 42, 48, 49, 50, 51, 52, 54, 56, 7, 15, 53, 55, 15, 0, 23, }; const short yycheck[] = { 264, 265, 277, 267, 279, 269, 281, 271, 283, 273, 257, 275, 287, 277, 278, 279, 280, 281, 259, 283, 284, 285, 286, 287, 264, 265, 261, 267, 287, 269, 263, 271, 260, 273, 258, 275, 284, 285, 278, 262, 280, 287, 282, 287, 284, 285, 286, 265, 287, 267, 287, 269, 264, 271, 270, 273, 287, 275, 287, 277, 285, 279, 266, 281, 272, 283, 17, 18, 19, 287, 284, 285, 286, 268, 25, 23, 24, 274, 276, 278, 280, 282, 284, 286, 264, 278, 37, 39, 280, -1, 284, }; #define YYFINAL 2 #ifndef YYDEBUG #define YYDEBUG 0 #endif #define YYMAXTOKEN 287 #if YYDEBUG const char * const yyname[] = { "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,"HTML_O","HTML_F","HEAD_O", "HEAD_F","TITLE_O","TITLE_F","BODY_O","BODY_F","H1_O","H1_F","H2_O","H2_F", "H3_O","H3_F","H4_O","H4_F","H5_O","H5_F","H6_O","H6_F","EM_O","EM_F","B_O", "B_F","P_O","P_F","OL_O","OL_F","LI_O","LI_F","CHAINE", }; const char * const yyrule[] = { "$accept : Document", "Document : HTML_O Entete Corps HTML_F", "Entete : HEAD_O Titre HEAD_F", "Titre : TITLE_O CHAINE TITLE_F", "Corps : BODY_O Liste_Sections BODY_F", "Liste_Sections : Entete_De_Section Liste_Sections", "Liste_Sections : Texte Liste_Sections", "Liste_Sections :", "Entete_De_Section : H1_O CHAINE H1_F", "Entete_De_Section : H2_O CHAINE H2_F", "Entete_De_Section : H3_O CHAINE H3_F", "Entete_De_Section : H4_O CHAINE H4_F", "Entete_De_Section : H5_O CHAINE H5_F", "Entete_De_Section : H6_O CHAINE H6_F", "Texte : Element Texte", "Texte :", "Element : CHAINE", "Element : EM_O Texte EM_F", "Element : B_O Texte B_F", "Element : P_O Texte P_F", "Element : P_O Texte", "Element : OL_O Liste_Ord OL_F", "Liste_Ord : Liste_Items Liste_Ord", "Liste_Ord :", "Liste_Items : LI_O Texte LI_F", "Liste_Items : LI_O Texte", }; #endif #ifndef YYSTYPE typedef int YYSTYPE; #endif #if YYDEBUG #include #endif #ifdef YYSTACKSIZE #undef YYMAXDEPTH #define YYMAXDEPTH YYSTACKSIZE #else #ifdef YYMAXDEPTH #define YYSTACKSIZE YYMAXDEPTH #else #define YYSTACKSIZE 10000 #define YYMAXDEPTH 10000 #endif #endif #define YYINITSTACKSIZE 200 int yydebug; int yynerrs; int yyerrflag; int yychar; short *yyssp; YYSTYPE *yyvsp; YYSTYPE yyval; YYSTYPE yylval; short *yyss; short *yysslim; YYSTYPE *yyvs; int yystacksize; #line 76 "html.y" #include #include #include #include "lex.yy.c" int max(int a, int b) { return (a>b) ? a : b; } struct info semantique_TNNT(struct info s1,struct info s2,struct info s3,struct info s4) { struct info ss; if (extraction==1){ int len1 = strlen(s1.texte); int len2 = strlen(s2.texte); int len3 = strlen(s3.texte); ss.texte = malloc(len1+len2+len3+strlen(s4.texte)+1); strcpy(ss.texte,s1.texte); strcpy(ss.texte+len1,s2.texte); strcpy(ss.texte+len1+len2,s3.texte); strcpy(ss.texte+len1+len2+len3,s4.texte); } else { int len2 = strlen(s2.texte); ss.texte = malloc(len2+strlen(s3.texte)+1); strcpy(ss.texte,s2.texte); strcpy(ss.texte+len2,s3.texte); } ss.hauteur = max(s2.hauteur,s3.hauteur)+1; return ss; } struct info semantique_TNT(struct info s1,struct info s2,struct info s3) { struct info ss; if (extraction==1){ int len1 = strlen(s1.texte); int len2 = strlen(s2.texte); ss.texte = malloc(len1+len2+strlen(s3.texte)+1); strcpy(ss.texte,s1.texte); strcpy(ss.texte+len1,s2.texte); strcpy(ss.texte+len1+len2,s3.texte); } else ss.texte = strdup(s2.texte); ss.hauteur = s2.hauteur+1; return ss; } struct info semantique_TN(struct info s1,struct info s2,char *s3) { struct info ss; if (extraction==1){ if (optionMarque){ int len1 = strlen(s1.texte); int len2 = strlen(s2.texte); ss.texte = malloc(len1+len2+strlen(s3)+1); strcpy(ss.texte,s1.texte); strcpy(ss.texte+len1,s2.texte); strcpy(ss.texte+len1+len2,s3); } else { int len1 = strlen(s1.texte); ss.texte = malloc(len1+strlen(s2.texte)+1); strcpy(ss.texte,s1.texte); strcpy(ss.texte+len1,s2.texte); } } else ss.texte = ""; ss.hauteur = s2.hauteur+1; return ss; } struct info semantique_TTT(struct info s1,struct info s2,struct info s3) { struct info ss; if (extraction==1){ int len1 = strlen(s1.texte); int len2 = strlen(s2.texte); ss.texte = malloc(len1+len2+strlen(s3.texte)+1); strcpy(ss.texte,s1.texte); strcpy(ss.texte+len1,s2.texte); strcpy(ss.texte+len1+len2,s3.texte); } else ss.texte = ""; ss.hauteur = 1; return ss; } struct info semantique_NN(struct info s1, struct info s2) { struct info ss; int len1 = strlen(s1.texte); ss.texte = malloc(len1+strlen(s2.texte)+1); strcpy(ss.texte,s1.texte); strcpy(ss.texte+len1,s2.texte); ss.hauteur = max(s1.hauteur,s2.hauteur)+1; return ss; } struct info semantique_T(struct info s1) { struct info ss; if (extraction==1) ss.texte = strdup(s1.texte); else ss.texte = ""; ss.hauteur = 1; return ss; } struct info semantique_EPSILON() { struct info ss; ss.texte = ""; ss.hauteur = 1; return ss; } struct info semantique_Hi(int i,struct info s1,struct info s2,struct info s3) { if (optionExtraire==i || (optionExtraire>i && extraction==1)) extraction++; return semantique_TTT(s1,s2,s3); } void affiche_resultat(struct info ss) { if (optionHauteur) printf("Hauteur %d\n\n",ss.hauteur); if (optionExtraire > 0) if (optionMarque) printf("Premier niveau H%d normalise\n\n%s",optionExtraire,ss.texte); else printf("Premier niveau H%d\n\n%s",optionExtraire,ss.texte); else if (optionMarque) printf("Texte normalise\n\n%s",ss.texte); else printf("Texte\n\n%s",ss.texte); } int main(int argc, char **argv) { int i; for(i=0; i= YYMAXDEPTH) return -1; else if ((newsize *= 2) > YYMAXDEPTH) newsize = YYMAXDEPTH; i = yyssp - yyss; newss = yyss ? (short *)realloc(yyss, newsize * sizeof *newss) : (short *)malloc(newsize * sizeof *newss); if (newss == NULL) return -1; yyss = newss; yyssp = newss + i; newvs = yyvs ? (YYSTYPE *)realloc(yyvs, newsize * sizeof *newvs) : (YYSTYPE *)malloc(newsize * sizeof *newvs); if (newvs == NULL) return -1; yyvs = newvs; yyvsp = newvs + i; yystacksize = newsize; yysslim = yyss + newsize - 1; return 0; } #define YYABORT goto yyabort #define YYREJECT goto yyabort #define YYACCEPT goto yyaccept #define YYERROR goto yyerrlab #ifndef YYPARSE_PARAM #if defined(__cplusplus) || __STDC__ #define YYPARSE_PARAM_ARG void #define YYPARSE_PARAM_DECL #else /* ! ANSI-C/C++ */ #define YYPARSE_PARAM_ARG #define YYPARSE_PARAM_DECL #endif /* ANSI-C/C++ */ #else /* YYPARSE_PARAM */ #ifndef YYPARSE_PARAM_TYPE #define YYPARSE_PARAM_TYPE void * #endif #if defined(__cplusplus) || __STDC__ #define YYPARSE_PARAM_ARG YYPARSE_PARAM_TYPE YYPARSE_PARAM #define YYPARSE_PARAM_DECL #else /* ! ANSI-C/C++ */ #define YYPARSE_PARAM_ARG YYPARSE_PARAM #define YYPARSE_PARAM_DECL YYPARSE_PARAM_TYPE YYPARSE_PARAM; #endif /* ANSI-C/C++ */ #endif /* ! YYPARSE_PARAM */ int yyparse (YYPARSE_PARAM_ARG) YYPARSE_PARAM_DECL { register int yym, yyn, yystate; #if YYDEBUG register const char *yys; if ((yys = getenv("YYDEBUG"))) { yyn = *yys; if (yyn >= '0' && yyn <= '9') yydebug = yyn - '0'; } #endif yynerrs = 0; yyerrflag = 0; yychar = (-1); if (yyss == NULL && yygrowstack()) goto yyoverflow; yyssp = yyss; yyvsp = yyvs; *yyssp = yystate = 0; yyloop: if ((yyn = yydefred[yystate])) goto yyreduce; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, yystate, yychar, yys); } #endif } if ((yyn = yysindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { #if YYDEBUG if (yydebug) printf("%sdebug: state %d, shifting to state %d\n", YYPREFIX, yystate, yytable[yyn]); #endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; yychar = (-1); if (yyerrflag > 0) --yyerrflag; goto yyloop; } if ((yyn = yyrindex[yystate]) && (yyn += yychar) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yychar) { yyn = yytable[yyn]; goto yyreduce; } if (yyerrflag) goto yyinrecovery; #if defined(lint) || defined(__GNUC__) goto yynewerror; #endif yynewerror: yyerror("syntax error"); #if defined(lint) || defined(__GNUC__) goto yyerrlab; #endif yyerrlab: ++yynerrs; yyinrecovery: if (yyerrflag < 3) { yyerrflag = 3; for (;;) { if ((yyn = yysindex[*yyssp]) && (yyn += YYERRCODE) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == YYERRCODE) { #if YYDEBUG if (yydebug) printf("%sdebug: state %d, error recovery shifting\ to state %d\n", YYPREFIX, *yyssp, yytable[yyn]); #endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate = yytable[yyn]; *++yyvsp = yylval; goto yyloop; } else { #if YYDEBUG if (yydebug) printf("%sdebug: error recovery discarding state %d\n", YYPREFIX, *yyssp); #endif if (yyssp <= yyss) goto yyabort; --yyssp; --yyvsp; } } } else { if (yychar == 0) goto yyabort; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, error recovery discards token %d (%s)\n", YYPREFIX, yystate, yychar, yys); } #endif yychar = (-1); goto yyloop; } yyreduce: #if YYDEBUG if (yydebug) printf("%sdebug: state %d, reducing by rule %d (%s)\n", YYPREFIX, yystate, yyn, yyrule[yyn]); #endif yym = yylen[yyn]; yyval = yyvsp[1-yym]; switch (yyn) { case 1: #line 33 "html.y" { yyval=semantique_TNNT(yyvsp[-3],yyvsp[-2],yyvsp[-1],yyvsp[0]); affiche_resultat(yyval); } break; case 2: #line 38 "html.y" {yyval=semantique_TNT(yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 3: #line 40 "html.y" {yyval=semantique_TTT(yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 4: #line 42 "html.y" { if (optionExtraire>0 && extraction==1) extraction++; yyval=semantique_TNT(yyvsp[-2],yyvsp[-1],yyvsp[0]); } break; case 5: #line 48 "html.y" {yyval=semantique_NN(yyvsp[-1],yyvsp[0]);} break; case 6: #line 49 "html.y" {yyval=semantique_NN(yyvsp[-1],yyvsp[0]);} break; case 7: #line 50 "html.y" {yyval=semantique_EPSILON(yyval);} break; case 8: #line 52 "html.y" {yyval=semantique_Hi(1,yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 9: #line 53 "html.y" {yyval=semantique_Hi(2,yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 10: #line 54 "html.y" {yyval=semantique_Hi(3,yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 11: #line 55 "html.y" {yyval=semantique_Hi(4,yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 12: #line 56 "html.y" {yyval=semantique_Hi(5,yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 13: #line 57 "html.y" {yyval=semantique_Hi(6,yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 14: #line 59 "html.y" {yyval=semantique_NN(yyvsp[-1],yyvsp[0]);} break; case 15: #line 60 "html.y" {yyval=semantique_EPSILON(yyval);} break; case 16: #line 62 "html.y" {yyval=semantique_T(yyvsp[0]);} break; case 17: #line 63 "html.y" {yyval=semantique_TNT(yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 18: #line 64 "html.y" {yyval=semantique_TNT(yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 19: #line 65 "html.y" {yyval=semantique_TNT(yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 20: #line 66 "html.y" {yyval=semantique_TN(yyvsp[-1],yyvsp[0],"

");} break; case 21: #line 67 "html.y" {yyval=semantique_TNT(yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 22: #line 69 "html.y" {yyval=semantique_NN(yyvsp[-1],yyvsp[0]);} break; case 23: #line 70 "html.y" {yyval=semantique_EPSILON(yyval);} break; case 24: #line 72 "html.y" {yyval=semantique_TNT(yyvsp[-2],yyvsp[-1],yyvsp[0]);} break; case 25: #line 73 "html.y" {yyval=semantique_TN(yyvsp[-1],yyvsp[0],"");} break; #line 697 "y.tab.c" } yyssp -= yym; yystate = *yyssp; yyvsp -= yym; yym = yylhs[yyn]; if (yystate == 0 && yym == 0) { #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state 0 to\ state %d\n", YYPREFIX, YYFINAL); #endif yystate = YYFINAL; *++yyssp = YYFINAL; *++yyvsp = yyval; if (yychar < 0) { if ((yychar = yylex()) < 0) yychar = 0; #if YYDEBUG if (yydebug) { yys = 0; if (yychar <= YYMAXTOKEN) yys = yyname[yychar]; if (!yys) yys = "illegal-symbol"; printf("%sdebug: state %d, reading %d (%s)\n", YYPREFIX, YYFINAL, yychar, yys); } #endif } if (yychar == 0) goto yyaccept; goto yyloop; } if ((yyn = yygindex[yym]) && (yyn += yystate) >= 0 && yyn <= YYTABLESIZE && yycheck[yyn] == yystate) yystate = yytable[yyn]; else yystate = yydgoto[yym]; #if YYDEBUG if (yydebug) printf("%sdebug: after reduction, shifting from state %d \ to state %d\n", YYPREFIX, *yyssp, yystate); #endif if (yyssp >= yysslim && yygrowstack()) { goto yyoverflow; } *++yyssp = yystate; *++yyvsp = yyval; goto yyloop; yyoverflow: yyerror("yacc stack overflow"); yyabort: return (1); yyaccept: return (0); }