Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[Xcode] YACC & LEX - attached files (1/1)

2 réponses
Avatar
Vincent NICOLAS
Bonjour,

je suis le bouquin "Building Cocoa Applications with Obj-C".
Dans 2 des projets, on construit une 2e target qui est un evaluateur
d'expressions mathématiques.

Dans le 1er projet, ça s'est bien passé avec Project Builder sous Jaguar.
Dans le 2d, je suis passé à Panther / Xcode et là, pas moyen de lui
faire compiler mes 2 fichiers.

J'ai trouvé un contournement du problème en drag and droppant la target
du 1er projet sur le second. M'enfin, j'aimerais bien savoir comment
construire ça "à la main".

Des idées ?

--
Vincent Nicolas
En direct de Lyon
vintzSANSPAM@infonie.fr
%{
#include <libc.h>
#include <math.h>

int printingError = 0;
%}

%start list

%union
{
int ival;
double dval;
}

%token <dval> NUMBER
%token <dval> SIN COS TAN ASIN ACOS ATAN
%token <dval> SINH COSH TANH ASINH ACOSH ATANH
%token <dval> SQRT EXP MOD LN LOG PI
%type <dval> expr number

%left '+' '-'
%left '*' '/'
%left SIN COS TAN ASIN ACOS ATAN
%left SINH COSH TANH ASINH ACOSH ATANH
%left '^' SQRT EXP MOD LN LOG
%left UMINUS /* supplies precedence for unary minus */

%% /* beginning of rules section */

list : stat
| list stat
;

stat : expr '\n'
{
printf ("%10g\n",$1);
printingError = 0;
fflush(stdout);
}
| expr ',' expr '\n'
{
printf ("%g,%g\n", $1, $3);
printingError = 0;
fflush(stdout);
}
| error '\n' { yyerrok; printingError = 0; }
;

expr : '(' expr ')'
{
$$ = $2;
}
| expr '+' expr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; }
| expr '*' expr { $$ = $1 * $3; }
| expr '/' expr { $$ = $1 / $3; }
| SIN expr { $$ = sin($2); }
| COS expr { $$ = cos($2); }
| TAN expr { $$ = tan($2); }
| ASIN expr { $$ = asin($2); }
| ACOS expr { $$ = acos($2); }
| ATAN expr { $$ = atan($2); }
| SINH expr { $$ = sinh($2); }
| COSH expr { $$ = cosh($2); }
| TANH expr { $$ = tanh($2); }
| ASINH expr { $$ = asinh($2); }
| ACOSH expr { $$ = acosh($2); }
| ATANH expr { $$ = atanh($2); }
| expr '^' expr { $$ = pow($1,$3); }
| expr MOD expr { $$ = fmod($1,$3); }
| LN expr { $$ = log($2); }
| LOG expr { $$ = log10($2); }
| SQRT expr { $$ = sqrt($2); }
| EXP expr { $$ = exp($2); }
| '-' expr %prec UMINUS
{
$$ = -$2;
}
| number
;

number : NUMBER /* lex number */
| PI { $$ = M_PI; }
;

%%
/* beginning of functions section */

void yyerror(char *s)
{
if (printingError == 0) {
printf("%s\n", s);
fflush(stdout);
printingError = 1;
}
}

int main(int argc, char **argv)
{
while (!feof(stdin)) {
yyparse();
}
exit(0);
}

%{
#include "y.tab.h"
#include <stdlib.h>

#define YY_INPUT(buf,result,max_size) (buf[0])=getchar();result=1;

int yywrap(void);
int yywrap(){return 0;}

%}

%%

"\n" return('\n');

[0-9]*("."[0-9]*("e"[-+][0-9]+)?)? {yylval.dval = atof(yytext);
return(NUMBER);}

sin return(SIN);
cos return(COS);
tan return(TAN);
asin return(ASIN);
acos return(ACOS);
atan return(ATAN);
sinh return(SINH);
cosh return(COSH);
tanh return(TANH);
asinh return(ASINH);
acosh return(ACOSH);
atanh return(ATANH);
mod return(MOD);
ln return(LN);
log return(LOG);
sqrt return(SQRT);
exp return(EXP);
pi return(PI);

"+" {return (yytext[0]);}
"-" {return (yytext[0]);}
"*" {return (yytext[0]);}
"/" {return (yytext[0]);}
"^" {return (yytext[0]);}
"(" {return (yytext[0]);}
")" {return (yytext[0]);}
"," {return (yytext[0]);}

[ \t] ;

. {yyerror("Syntax Error");}

%%

2 réponses

Avatar
Vincent NICOLAS
In article ,
Vincent NICOLAS wrote:

Bonjour,

je suis le bouquin "Building Cocoa Applications with Obj-C".
Dans 2 des projets, on construit une 2e target qui est un evaluateur
d'expressions mathématiques.

Dans le 1er projet, ça s'est bien passé avec Project Builder sous Jaguar.
Dans le 2d, je suis passé à Panther / Xcode et là, pas moyen de lui
faire compiler mes 2 fichiers.

J'ai trouvé un contournement du problème en drag and droppant la target
du 1er projet sur le second. M'enfin, j'aimerais bien savoir comment
construire ça "à la main".

Des idées ?



A priori, c'est un bug de Xcode... en espérant que la version 1.1 qui ne
devrait pas tarder le corrige.


--
Vincent Nicolas
En direct de Lyon


Avatar
patrickl31
Le vendredi 21 Novembre 2003 à 11:25 par Vincent NICOLAS :
Bonjour,

je suis le bouquin "Building Cocoa Applications with Obj-C".
Dans 2 des projets, on construit une 2e target qui est un evaluateur
d'expressions mathématiques.

Dans le 1er projet, ça s'est bien passé avec Project Builder sous
Jaguar.
Dans le 2d, je suis passé à Panther / Xcode et là, pas
moyen de lui
faire compiler mes 2 fichiers.

J'ai trouvé un contournement du problème en drag and droppant la
target
du 1er projet sur le second. M'enfin, j'aimerais bien savoir comment
construire ça "à la main".

Des idées ?

--
Vincent Nicolas
En direct de Lyon

%{
#include
#include

int printingError = 0;
%}

%start list

%union
{
int ival;
double dval;
}

%token NUMBER
%token SIN COS TAN ASIN ACOS ATAN
%token SINH COSH TANH ASINH ACOSH ATANH
%token SQRT EXP MOD LN LOG PI
%type expr number

%left '+' '-'
%left '*' '/'
%left SIN COS TAN ASIN ACOS ATAN
%left SINH COSH TANH ASINH ACOSH ATANH
%left '^' SQRT EXP MOD LN LOG
%left UMINUS /* supplies precedence for unary minus */

%% /* beginning of rules section */

list : stat
| list stat
;

stat : expr 'n'
{
printf ("%10gn",$1);
printingError = 0;
fflush(stdout);
}
| expr ',' expr 'n'
{
printf ("%g,%gn", $1, $3);
printingError = 0;
fflush(stdout);
}
| error 'n' { yyerrok; printingError = 0; }
;

expr : '(' expr ')'
{
$$ = $2;
}
| expr '+' expr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; }
| expr '*' expr { $$ = $1 * $3; }
| expr '/' expr { $$ = $1 / $3; }
| SIN expr { $$ = sin($2); }
| COS expr { $$ = cos($2); }
| TAN expr { $$ = tan($2); }
| ASIN expr { $$ = asin($2); }
| ACOS expr { $$ = acos($2); }
| ATAN expr { $$ = atan($2); }
| SINH expr { $$ = sinh($2); }
| COSH expr { $$ = cosh($2); }
| TANH expr { $$ = tanh($2); }
| ASINH expr { $$ = asinh($2); }
| ACOSH expr { $$ = acosh($2); }
| ATANH expr { $$ = atanh($2); }
| expr '^' expr { $$ = pow($1,$3); }
| expr MOD expr { $$ = fmod($1,$3); }
| LN expr { $$ = log($2); }
| LOG expr { $$ = log10($2); }
| SQRT expr { $$ = sqrt($2); }
| EXP expr { $$ = exp($2); }
| '-' expr %prec UMINUS
{
$$ = -$2;
}
| number
;

number : NUMBER /* lex number */
| PI { $$ = M_PI; }
;

%%
/* beginning of functions section */

void yyerror(char *s)
{
if (printingError == 0) {
printf("%sn", s);
fflush(stdout);
printingError = 1;
}
}

int main(int argc, char **argv)
{
while (!feof(stdin)) {
yyparse();
}
exit(0);
}

%{
#include "y.tab.h"
#include

#define YY_INPUT(buf,result,max_size) (buf[0])=getchar();result=1;

int yywrap(void);
int yywrap(){return 0;}

%}

%%

"n" return('n');

[0-9]*("."[0-9]*("e"[-+][0-9]+)?)? {yylval.dval =
atof(yytext);
return(NUMBER);}

sin return(SIN);
cos return(COS);
tan return(TAN);
asin return(ASIN);
acos return(ACOS);
atan return(ATAN);
sinh return(SINH);
cosh return(COSH);
tanh return(TANH);
asinh return(ASINH);
acosh return(ACOSH);
atanh return(ATANH);
mod return(MOD);
ln return(LN);
log return(LOG);
sqrt return(SQRT);
exp return(EXP);
pi return(PI);

"+" {return (yytext[0]);}
"-" {return (yytext[0]);}
"*" {return (yytext[0]);}
"/" {return (yytext[0]);}
"^" {return (yytext[0]);}
"(" {return (yytext[0]);}
")" {return (yytext[0]);}
"," {return (yytext[0]);}

[ t] ;

. {yyerror("Syntax Error");}

%%


Bonjour,
je tombe sur cette réponse en essayant moi aussi de construire la démo du livre "building cocoa applications". 10 ans ont passé, mais le problème est toujours le même. S'il s'agit d'un bug de Xcode, il ne dérange pas grand monde... Mais j'aimerai bien trouver une solution. A priori, c'est un problème avec yyerror pour lequel Xcode m'affirme qu'il y a un conflit de types... Je cherche et pour le moment, je bute... Si quelqu'un a trouvé la solution, je suis preneur...;-)