(Courriels de diversion: <attente@sous-chef-touche.com> <extenuerais@alliance-excedera.com> <misions@club-indexa.com> <impopulaire@reflechisse-entachant.com> <cautionnerez@reecrivait-monteront.com> <passereau@preconisait-tergiversais.com> <ironiseraient@devots-redisions.com> <chercher@renflouerions-insinuons.com> <rivalise@alarmeront-donnaient.com> <assouvisses@electivite-pliures.com> )
Voici un petit example. Pour passer le fichier a lex, il suffit d'affecter
le FILE *yyin defini par lex. Regardes la fonction parse() de config.y :
----------------config.y :----------------------------------
%{
#include <stdio.h>
/* includes to come here */
int yyerror (const char *);
extern FILE *yyin;
%}
%union {
int val;
double dval;
char * name;
}
%token ROB_CON
%token SICK_CON
%token LD_MAP
%token ROB_VAR
%token SICK_VAR
%token IDEN
%token NUM
%token REAL
%start load_options
%%
load_options : /*nothing or ...*/
| load_options connect_robot
| load_options load_map
;
/* connecting to the robot . syntax : CONNECT_ROBOT robot_name port_number robot_id */
connect_robot : ROB_CON IDEN NUM NUM {ConnectServer2Robot($<name>2,$<val>3,$<val>4); }
| connect_robot set_robot_variance
| connect_robot connect_sick
;
/*
sets the parameters for robot moving error in this order (3 doubles) :
- percentage of translation error
- percentage of rotation error
- number of degrees of ortientation error by meter travelled
*/
set_robot_variance : ROB_VAR REAL REAL REAL {SetAccuracyMove($<dval>2, $<dval>3,$<dval>4);}
/*connecting to the sick on indicated port */
connect_sick : SICK_CON IDEN {SetSickComPort($<name>2); InitSick();};
load_map : LD_MAP IDEN {ReadMapFile ($<name>2);}
%%
int parseConfigFile(char * conf_file)
{
if(!(yyin = fopen(conf_file,"r")))
return 1;
if (yyparse()){
fclose(yyin);
return 1;
}
fclose (yyin);
return 0;
}
int yyerror (const char *s)
{
printf("%s\n",s);
}
-----------------config.lex -----------------------------
%{
#include "config.h"
%}
%x comment
REAL ([0-9]*\.[0-9]+)
NBR ([0-9]+)
ID [a-zA-Z_/]+[@:.a-zA-Z0-9_/]*[^ \n]*
STRING "\"".*"\""
%%
ConnectRobot return ROB_CON;
ConnectSick return SICK_CON;
LoadMapFile return LD_MAP;
SetRobotDrift return ROB_VAR;
SetSickAccuracy return SICK_VAR;
{ID} { yylval.name = strtok(yytext," "); return IDEN;}
{REAL} {yylval.dval = atof(yytext); return REAL;}
{NBR} {yylval.val = atoi(yytext); return NUM;}
.|\n
%%
#ifndef WIN32
int yywrap()
{
return 1;
}
#endif
-------------------------------
Lionel GACHES <lgaches@oci.fr> writes:
> bonjour a tous
>
> je recherche des informations pour pouvoir interpréter un fichier de
> configuration (avec flex et bison).
> si quelqu'un a de la doc sur ce type d'utilisation ou a un exemple
> simple je suis preneur.
>
> une autre petite question:
> comment bison peut dire a flex d'utiliser un fichier en entré pour
> son analyse.
>
> Merci
> Lionel Gaches
> lgaches@oci.fr>
>
>
> _______________________________________________________________________
> Le CULTe sur le ouebe: http://savage.iut-blagnac.fr/
_______________________________________________________________________
Le CULTe sur le ouebe: http://savage.iut-blagnac.fr/