Contents
- alan.bison
- yash0.flex
- yash0.bison
- vect.h
- vect.data
- Astar.c
- genrom.c
alan.bison 1/7
[top][prev][next]
%{
#include <stdio.h>
int yyerror (char const *message) {
fprintf(stderr,"<%s>\n", message);
return 0;
}
/* analyse lexicale minimale : utilise uniquement les */
/* tokens implicites de bisons sur 1 car. ASCII */
int yylex(){ return(getchar()); }
%}
%error-verbose
%token 'a' 'b' 'c' '\n'
%%
Lignes :
| Lignes Langage '\n'
| Lignes error '\n' {yyerrok;}
;
Langage : 'a' 'b' 'c'
;
%%
int main(void) { yyparse(); }
yash0.flex 2/7
[top][prev][next]
%{ /* Prologue C */
#ifdef FLEXALONE
enum Return_Token_Values { NEWLINE=1000, BYE, HELLO, THANKS, FUCK, CMD_SEP};
#else
#include "yyparse.h"
#endif
#include "proto-color.h"
void echo(char *lex_cat) {
// fprintf(stdout,GREEN("[%s:%s]"), lex_cat, yytext);
}
void echonl() {
// fprintf(stdout,BLUE("[\\n]")"\n");
}
%} /*end Prologue C */
/* Options Flex*/
%option nounput noinput
/* Macro-Definition */
newline \n|\r|\r\n
%%
hi|hello echo("Builtin"); return(HELLO);
thanks echo("Builtin"); return(THANKS);
fuck|shit|"3-" echo("Builtin"); return(FUCK);
bye|quit|exit echo("Builtin"); return(BYE);
{newline} echonl(); return(NEWLINE);
. echo("Unknown"); return(yytext[0]);
%%
int yywrap (void) {return 1;}
#ifdef FLEXALONE
int main(int argc, char *argv[]) { while (yylex()!=0) ; return 0; }
#endif
yash0.bison 3/7
[top][prev][next]
%{
#include <stdio.h>
#include "proto-color.h"
extern int yylex();
int yyerror (char const *message) {
fprintf(stderr,RED("<%s>")"\n", message);
return 0;
}
void Prompt(){ printf("yash> "); } /* Yet Another Shell */
%}
%error-verbose
%token HELLO THANKS FUCK BYE
%token NEWLINE
%%
Shell : {}
| Shell Line NEWLINE {}
| Shell error NEWLINE {yyerrok; printf(BLUE("Ligne invalide")"\n");}
;
Line : Command
;
Command :
| Builtin
// | Others
;
Builtin : HELLO {printf("Nice to meet you\n");}
| THANKS {printf("You are welcome\n");}
| FUCK {yyerror("Semantic Error : Censored !"); YYERROR;}
| BYE {printf("See you\n"); return(0);}
;
%%
int main(void) { return yyparse(); }
vect.h 4/7
[top][prev][next]
#define MAX_TAILLE 5
typedef struct {
int taille;
int vect[MAX_TAILLE];
} Type_Vect;
/* utilisation pour bison :
1) #include "vect.h" dans le prologue bison
2) IMPORTANT : #include "vect.h" aussi dans la prologue flex avant #include "yyparse.h"
3) %union { ... ; Type_Vect vector; ...}
4) %type <vector> Vectexp
5) Vectexp : Vectexp '+' Vectexp
{ // verifier la semantique ...
$$.taille = $1.taille;
for(i=0;i<$$.taille;i++)
$$.vect[i]=$1.vect[i]+$3.vect[i];
}
*/
vect.data 5/7
[top][prev][next]
hello
1 # SCAL= 1
-2 # SCAL= -2
--2 # Error token '-' inconnu
1+-2 # SCAL= -1
1 + 2 * 3 # SCAL= 7
2 * 3 + 1 # SCAL= 7
2 * (3 + 1) # SCAL= 8
[] # VECT_0= []
[ -2 ] # VECT_1= [-2]
[3,2,1] # VECT_3= [3, 2, 1]
[1,2,3,4,5,6] # error semantique taille_max=5
[1+2*3,3*2+1,3*(2+1)] # VECT_3= [7, 7, 9]
[1,2]+[3,4] # VECT_2= [4, 6]
[1,2,3]+[3,4] # error semantique tailles incompatibles
[1,2]+[3,4]+[-1,-2] # VECT_2= [3, 4]
3*[1,2]*4 # VECT_2= [12, 24]
[1]*[2] # erreur de syntaxe
3*[]+[] # VECT_0= []
dim([]) # SCAL= 0
dim([1,2]) # SCAL= 2
[dim(2*dim([1,2+1,3])*[1,2]),1,1] # VECT_3= [2, 1, 1]
bye #fuck shit
Astar.c 6/7
[top][prev][next]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define TAILLE_MAX 236
char *alphabet;
char result[TAILLE_MAX];
void recurse(int index, int Taille, int Card) {
int i;
if ( index == Taille ) {
result[Taille]='\0';
printf("%s\n",result);
}
else {
for ( i = 0; i < Card; i++ ) {
result[index] = alphabet[i];
recurse( index + 1 ,Taille,Card);
}
}
}
int main(int argc, char **argv ){
int C,N,i;
if (argc!=3) {
printf("Syntaxe :\n");
printf("> Astar str N #mots de taille =N \n");
printf("> Astar str -N #mots de taille <=N \n");
printf(" et str = alphabet = string de char. ASCII\n");
printf("Exemples:\n");
printf("> Astar 01 13 => les nombres binaires de 13 bits\n");
printf("> Astar abc -10 => les mots sur {a,b,c} de taille 1 a 10\n");
} else {
alphabet=argv[1];
C=strlen(alphabet);
N=atoi(argv[2]);
if (N>TAILLE_MAX) {
printf("Taille trop grande\n");
} else {
if (N<0) {
for (i=1; i<=-N; i++)
recurse(0, i, C);
} else
recurse(0, N, C);
}
}
}
genrom.c 7/7
[top][prev][next]
#include "stdio.h"
char *U[]={"","I","II","III","IV","V","VI","VII","VIII","IX"};
char *D[]={"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC"};
char *C[]={"","C","CC","CCC","CD","D","DC","DCC","DCCC","CM"};
char *M[]={"","M","MM","MMM","MMMM"};
int main(int argc, char **argv ){
int max=4999;
if (argc==2) max=atoi(argv[1]);
if (max>4999) max=4999;
int i,j,k,l;
for(l=0;l<5;l++)
for(i=0;i<10;i++)
for(j=0;j<10;j++)
for(k=0;k<10;k++)
if (1000*l+100*i+10*j+k<=max)
// if (1000*l+100*i+10*j+k!=max) /* supprime 0=ligne vide */
printf("%s%s%s%s\n",M[l],C[i],D[j],U[k]);
}
Generated by GNU enscript 1.6.4.