Sie sind auf Seite 1von 2

%{

#include<stdio.h>
#include<math.h>
#define YYSTYPE double
YYSTYPE last_value=0;
int yyerror(const char *s);
extern int yylex(void);
%}
%token NUMBER
%token LAST
%left '+' '-' '*' '/' '^'

%%list:
| list '\n'
| list expr '\n' {printf("%.10g\n",last_value=$2);
}
;

expr: term {$$ = $1; }


| expr '+' expr {$$ = $1 + $3;}
| expr '-' expr {$$ = $1 - $3;}
| expr '*' expr {$$ = $1 * $3;}
| expr '/' expr {$$ = $1 / $3;}
| expr '^' expr {$$ = pow($1,$3);}
;term: NUMBER { $$ = $1; }
| LAST { $$ = last_value; }
| '(' expr ')' { $$ = $2; }

;
%%

#include<stdlib.h>
#include<string.h>
#include<unistd.h>
int lineno;
char *fname = "-stdin-";
int yyerror(const char *s)
{
fprintf(stderr,"%s(%d):%s\n",fname,lineno,s);
return 0;
}
main()
{
yyparse();
return 0;
}

////////////****************************////////////////

%{
#include "stdio.h"
#include "unistd.h"
#include "stdlib.h"
#include "math.h"
#define YYSTYPE double
#include "y.tab.h"
extern int lineno; /* current line number */
extern YYSTYPE yylval; /* value of numeric token */
%}

digit [0-9]
space [ \t]

%%

{space} { ; } /* spaces are ignored */


{digit}+\.?|{digit}*\.{digit}+ {
yylval = strtod(yytext,0);
return NUMBER; }
\n { lineno++; return '\n'; }
. { return yytext[0]; }
%%

void *fun(void *arg)


{
pthread_t tid2;
int i=(int *)arg;
n=i*2;
pthread_create(&tid2,NULL,fun2,(void*)i);
pthread_join(tid2,NULL);
return NULL;

main()
{
yylex();
scanf("%d",&n);
pthread_t tid;
pthread_create(&tid,NULL,fun,(void*)n);
pthread_join(tid,NULL);

printf("After Thread %d \n",n);


exit(0);

Das könnte Ihnen auch gefallen