Trabalho Prático 2
Processamento de Linguagens
commands.h
Ir para a documentação deste ficheiro.
1 /**
2  * @file commands.h
3  * @author
4  * - José Moura <a13742|at|alunos.ipca.pt>
5  * - Óscar Silva <a14383|at|alunos.ipca.pt>
6  * - Daniel Filipe <a17442|at|alunos.ipca.pt>
7  * @date 01 Jan 2020
8  * @brief
9  * Ficheiro Header
10  */
11 
12 #ifndef COMMANDS_H
13 #define COMMANDS_H
14 
15 #define DEBUG 1
16 /**
17  * @brief
18  * Estrutura que contem as variaveis e respectivos valores durante o runtime
19  */
20 typedef struct _varList {
21  char *var;
22  float val;
23  struct _varList* next;
24 } VarList;
25 
26 /**
27  * @brief
28  * Estrutura que contem um valor, que poderá ser uma variavel ou um valor inteiro
29  */
30 typedef struct _Value {
31  char *var; // if this is null, use val, else use var name
32  int val;
33 } Value;
34 
35 /**
36  * @brief
37  * Estrutura que contem uma dimensão ex. 10x20
38  */
39 typedef struct _Dimension {
40  Value x;
41  Value y;
42 } Dimension;
43 
44 /**
45  * @brief
46  * Estrutura/Lista que contem um ou vários Pontos ex. (1,2 3,4 6,5)
47  */
48 typedef struct _Point {
49  Value x;
50  Value y;
51  struct _Point* next;
52 } Point;
53 
54 /**
55  * @brief
56  * Estrutura que contem uma cor ex (255:255:255)
57  */
58 typedef struct _Colour {
59  Value r;
60  Value g;
61  Value b;
62 } Colour;
63 
64 /**
65  * @brief
66  * Estrutura/lista que contem um ou vários comando e seus argumentos
67  */
68 typedef struct _Command {
69  int command; // using grammar.tab.h enum (yytokentype)
70  Point *point;
71  Dimension *dimension;
72  Colour *color;
73  Value *val;
74  Value *val2;
75  Value *str;
76  Value *str2;
77  struct _Command *next;
78  struct _Command *child;
79 } Command;
80 
81 /**
82  * @brief
83  * Estrutura que contem a informação de uma imagem em runtime
84  */
85 typedef struct _Image {
86  int r,g,b;
88  VarList *vars;
89  int *img_data;
90 } Image;
91 
92 /*
93  * Assinaturas das funções
94  */
95 
96 Image *newImage();
97 Colour *parseColour(Value *r, Value *g, Value *b);
98 Dimension *parseDimension(Value *x, Value *y);
99 Point *parsePoint(Point *lst, Value *x, Value *y);
100 Command* newCommand(int command, Point *pt, Dimension *dim, Colour *col, Value *val, Value *val2 ,Value *str, Value *str2, Command *child) ;
101 Value *parseValue(int val, char* str);
102 void runCommands(Command *lst, Image *image);
103 void Run(Command *lst);
104 Command* newVariable(char *variable, Value* value);
105 Command* insertCommand(Command *lst, Command *cmd);
106 int gera_random(int min, int max);
107 
108 #endif /* COMMANDS_H */
_Image::b
int b
Definition: commands.h:86
newVariable
Command * newVariable(char *variable, Value *value)
_Command::val
Value * val
Definition: commands.h:73
_Image::vars
VarList * vars
Definition: commands.h:88
_varList::var
char * var
Definition: commands.h:21
gera_random
int gera_random(int min, int max)
Gera um numero random entre min e max.
Definition: commands.c:505
_Command::command
int command
Definition: commands.h:69
_Image::r
int r
Definition: commands.h:86
_Image::x_size
int x_size
Definition: commands.h:87
parseColour
Colour * parseColour(Value *r, Value *g, Value *b)
Recebe 3 valores e cria uma estrutura de cor.
Definition: commands.c:29
insertCommand
Command * insertCommand(Command *lst, Command *cmd)
Recebe uma lista de comandos e um comando e insere o mesmo na lista.
Definition: commands.c:118
_Command
Estrutura/lista que contem um ou vários comando e seus argumentos.
Definition: commands.h:68
newCommand
Command * newCommand(int command, Point *pt, Dimension *dim, Colour *col, Value *val, Value *val2, Value *str, Value *str2, Command *child)
Função que cria um comando e o devolve.
Definition: commands.c:95
_Colour::g
Value g
Definition: commands.h:60
Run
void Run(Command *lst)
Função chamada no final de fazer parsing à gramatica program : instructionList { Run($1); } A mesma c...
Definition: commands.c:208
_varList::val
float val
Definition: commands.h:22
_Point::y
Value y
Definition: commands.h:50
_Command::point
Point * point
Definition: commands.h:70
_Command::val2
Value * val2
Definition: commands.h:74
_Command::child
struct _Command * child
Definition: commands.h:78
parseDimension
Dimension * parseDimension(Value *x, Value *y)
Recebe 2 valores e devolve uma estrutura do tipo dimension (x x y)
Definition: commands.c:44
_Dimension::y
Value y
Definition: commands.h:41
_Command::dimension
Dimension * dimension
Definition: commands.h:71
_Colour
Estrutura que contem uma cor ex (255:255:255)
Definition: commands.h:58
_Value::val
int val
Definition: commands.h:32
_Value
Estrutura que contem um valor, que poderá ser uma variavel ou um valor inteiro.
Definition: commands.h:30
_Point
Estrutura/Lista que contem um ou vários Pontos ex. (1,2 3,4 6,5)
Definition: commands.h:48
_Colour::b
Value b
Definition: commands.h:61
_Command::str
Value * str
Definition: commands.h:75
_Command::str2
Value * str2
Definition: commands.h:76
_Point::x
Value x
Definition: commands.h:49
_Dimension
Estrutura que contem uma dimensão ex. 10x20.
Definition: commands.h:39
_Command::color
Colour * color
Definition: commands.h:72
_varList::next
struct _varList * next
Definition: commands.h:23
_Point::next
struct _Point * next
Definition: commands.h:51
runCommands
void runCommands(Command *lst, Image *image)
Função recursiva principal que corre os comandos pertencentes à lista de comandos que foi feito o par...
Definition: commands.c:219
newImage
Image * newImage()
Cria uma nova estrutura que irá servir para correr os comandos.
Definition: commands.c:190
parsePoint
Point * parsePoint(Point *lst, Value *x, Value *y)
Recebe 2 valores de x e y e uma lista de pontos.
Definition: commands.c:59
_Dimension::x
Value x
Definition: commands.h:40
_Image::y_size
int y_size
Definition: commands.h:87
_Colour::r
Value r
Definition: commands.h:59
_varList
Estrutura que contem as variaveis e respectivos valores durante o runtime.
Definition: commands.h:20
_Command::next
struct _Command * next
Definition: commands.h:77
_Image::img_data
int * img_data
Definition: commands.h:89
parseValue
Value * parseValue(int val, char *str)
Cria uma estutura do tipo value dependendo se enviamos uma string ou um valor.
Definition: commands.c:74
_Value::var
char * var
Definition: commands.h:31
_Image
Estrutura que contem a informação de uma imagem em runtime.
Definition: commands.h:85
_Image::g
int g
Definition: commands.h:86