-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGramaticaTP.y
74 lines (52 loc) · 1.65 KB
/
GramaticaTP.y
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
%{
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "Excel.h"
int yylex();
int yyerror(char*);
double matriz [1000][26];
void Inicializa_matrix(double [1000][26]);
%}
%union {
char * string;
int inteiro;
double real;
}
%token <string> VAR
%token <real> DOUBLE
%type <real> operacao soma sub div mult arg
%token <real> RANDOM SQRT ABS SUM AVG
%token SHOW OP
%%
prog: expressao restoprog
;
restoprog:
|prog
;
expressao:VAR OP operacao';' {Define_valor_da_variavel($1,$3,matriz);}
|SHOW VAR ';' {printf("%f \n",Procurar_valor($2,matriz));}
;
operacao:soma {$$ = $1;}
|sub {$$ = $1;}
|mult {$$ = $1;}
|div {$$ = $1;}
|arg {$$ = $1;}
|RANDOM'('')' {$$ = Random();}
|ABS'('VAR'-'VAR')' {$$ = Abs($3,$5,matriz);}
|SQRT'('VAR')' {$$ = Raiz($3,matriz);}
|SUM'('VAR':'VAR')' {$$ = Sum($3,$5,matriz);}
|AVG'('VAR':'VAR')' {$$ = Avg($3,$5,matriz);}
;
soma:arg '+' operacao {$$ = Soma($1,$3);}
;
sub:arg '-' operacao {$$ = Sub($1,$3);}
;
mult:arg '*' operacao {$$ = Mult($1,$3);}
;
div:arg '/' operacao {$$ = Div($1,$3);}
;
arg:DOUBLE {$$ = $1;}
|VAR {$$ = Procurar_valor($1,matriz);}
;
%%