Aide:Sommaires : Différence entre versions

De Wicri Chanson de Roland
(Programme Lex)
(Programme Lex)
 
(6 révisions intermédiaires par le même utilisateur non affichées)
Ligne 10 : Ligne 10 :
 
%%
 
%%
 
^[ ]+[1-9][0-9]*\.[0-9]*[ ]  BEGIN Z1;
 
^[ ]+[1-9][0-9]*\.[0-9]*[ ]  BEGIN Z1;
<Z1>[0-9]+        strcpy(num, yytext);
+
<Z1>[0-9]+\.       strcpy(num, yytext);
 
<Z1>[ ]+          BEGIN Z2;
 
<Z1>[ ]+          BEGIN Z2;
<Z2>.+            strcpy(num, yytext);
+
<Z2>.+            strcpy(tit, yytext);
<Z2>\n            {printf ("* [[#%s %s|%s <i>%s</i>]]\n", num, tit, num, tit); BEGIN 0;}
+
<Z2>\n            {printf ("* \[\[#%s %s|%s <i>%s</i>\]\]\n", num, tit, num, tit); BEGIN 0;}
 
%%
 
%%
 
main()
 
main()
Ligne 24 : Ligne 24 :
 
...
 
...
  
lex Vers2Wiki.lex
+
lex SommaireListNotes.lex
  
 
gcc lex.yy.c -ll -o SommaireListNotes.o
 
gcc lex.yy.c -ll -o SommaireListNotes.o
  
 
</source>
 
</source>

Version actuelle datée du 20 mai 2022 à 17:23

Programme Lex

cat <<... > SommaireListNotes.lex
%{
  char *num;
  char *tit;
%}
%START Z1
%START Z2
%%
^[ ]+[1-9][0-9]*\.[0-9]*[ ]  BEGIN Z1;
<Z1>[0-9]+\.        strcpy(num, yytext);
<Z1>[ ]+           BEGIN Z2;
<Z2>.+            strcpy(tit, yytext);
<Z2>\n             {printf ("* \[\[#%s %s|%s <i>%s</i>\]\]\n", num, tit, num, tit); BEGIN 0;}
%%
main()
{
num=malloc(10);
tit=malloc(100);
yylex();
printf ("\n");
}
...

lex SommaireListNotes.lex

gcc lex.yy.c -ll -o SommaireListNotes.o