Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Germanoa #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,18 @@ ADD_EXECUTABLE(main
src/iks_types.c
)
TARGET_LINK_LIBRARIES(main ${FLEX_LIBRARIES})
#ADD_EXECUTABLE(test
# ${FLEX_scanner_OUTPUTS}
# ${BISON_parser_OUTPUTS}
# src/tests/test.c
# src/comp_dict.c
# src/comp_list.c
# src/comp_tree.c
# src/comp_graph.c
# src/comp_grammar.c
# src/iks_ast.c
# src/iks_types.c
#)
#TARGET_LINK_LIBRARIES(test ${FLEX_LIBRARIES})
ADD_EXECUTABLE(test
${FLEX_scanner_OUTPUTS}
${BISON_parser_OUTPUTS}
src/tests/test.c
src/gv.c
src/comp_dict.c
src/comp_list.c
src/comp_tree.c
src/comp_graph.c
src/comp_stack.c
src/comp_grammar.c
src/iks_ast.c
src/iks_types.c
)
TARGET_LINK_LIBRARIES(test ${FLEX_LIBRARIES})
1 change: 1 addition & 0 deletions g3/GROUP
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
C
1 change: 1 addition & 0 deletions g3/main
37 changes: 37 additions & 0 deletions g3/report
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
*** g3 C
\begin{verbatim}
input/etapa4/s00.iks IKS_ERROR_UNDECLARED okay (w,r,c,l)=(0,0,0,0)
input/etapa4/s01.iks IKS_ERROR_UNDECLARED okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s02.iks IKS_ERROR_UNDECLARED okay (w,r,c,l)=(0,0,0,0)
input/etapa4/s03.iks IKS_ERROR_DECLARED okay (w,r,c,l)=(0,0,0,0)
input/etapa4/s04.iks IKS_ERROR_DECLARED okay (w,r,c,l)=(0,0,0,12)
input/etapa4/s05.iks IKS_ERROR_VARIABLE okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s06.iks IKS_ERROR_VECTOR okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s07.iks IKS_ERROR_FUNCTION okay (w,r,c,l)=(0,0,0,28)
input/etapa4/s08.iks IKS_ERROR_STRING_TO_X okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s09.iks IKS_ERROR_CHAR_TO_X okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s10.iks IKS_ERROR_MISSING_ARGS okay (w,r,c,l)=(0,0,0,0)
input/etapa4/s11.iks IKS_ERROR_EXCESS_ARGS okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s12.iks IKS_ERROR_WRONG_TYPE_ARGS okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s13.iks IKS_ERROR_WRONG_TYPE_ARGS okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s14.iks IKS_ERROR_WRONG_PAR_INPUT okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s15.iks IKS_ERROR_WRONG_PAR_OUTPUT okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s16.iks IKS_ERROR_WRONG_PAR_RETURN okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s17.iks IKS_ERROR_STRING_TO_X okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s18.iks IKS_ERROR_CHAR_TO_X okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s19.iks IKS_ERROR_WRONG_TYPE okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s20.iks IKS_ERROR_WRONG_TYPE okay (w,r,c,l)=(0,0,0,8)
input/etapa4/s21.iks IKS_ERROR_WRONG_TYPE okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s22.iks IKS_ERROR_WRONG_TYPE okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s23.iks IKS_ERROR_STRING_TO_X okay (w,r,c,l)=(0,0,0,24)
input/etapa4/s24.iks IKS_ERROR_CHAR_TO_X okay (w,r,c,l)=(0,0,0,24)
input/etapa4/s25.iks IKS_SUCCESS okay (w,r,c,l)=(0,0,0,12)
input/etapa4/s26.iks IKS_ERROR_CHAR_TO_X okay (w,r,c,l)=(0,0,0,16)
input/etapa4/s27.iks IKS_ERROR_STRING_TO_X okay (w,r,c,l)=(0,0,0,24)
input/etapa4/s28.iks IKS_ERROR_STRING_TO_X okay (w,r,c,l)=(0,0,0,36)
input/etapa4/s29.iks IKS_ERROR_CHAR_TO_X okay (w,r,c,l)=(0,0,0,36)
input/etapa4/s30.iks IKS_ERROR_WRONG_PAR_RETURN okay (w,r,c,l)=(0,0,0,12)
input/etapa4/s31.iks IKS_SUCCESS okay (w,r,c,l)=(0,0,0,12)
input/etapa4/s32.iks IKS_ERROR_UNDECLARED okay (w,r,c,l)=(0,0,0,12)
g3 10.00000000000000000000 7.80303030303030303030
\end{verbatim}
13 changes: 6 additions & 7 deletions include/comp_grammar.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ comp_grammar_symbol_t *new_comp_grammar_symbol();
/**
* free address memory used by grammar_symbol
*/
void comp_grammar_symbol_delete(comp_grammar_symbol_t *grammar_symbol);
void comp_grammar_symbol_delete(comp_grammar_symbol_t **grammar_symbol);

/**
* set grammar_symbol
Expand All @@ -67,6 +67,11 @@ void symbol_table_append(char *identifier, comp_grammar_symbol_t *symbol, comp_d
*/
void symbol_table_init();

/**
* delete symbol_table
*/
void symbol_table_delete(comp_dict_t *dict);

/**
* print the symbol_table
*/
Expand Down Expand Up @@ -95,10 +100,4 @@ int update_decl_symbol(comp_grammar_symbol_t *s, int decl_type, comp_grammar_sym
*/
int symbol_is_decl_type(comp_grammar_symbol_t *s,int decl_type);

/**
* handling errors
*/
int iks_error(comp_grammar_symbol_t *s, int error_type);


#endif /* COMP_GRAMMAR_H */
3 changes: 3 additions & 0 deletions include/comp_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ typedef struct comp_tree_t_struct {
// initialize tree with item and children as NULL
static inline __comp_tree_init(comp_tree_t *tree);

// verify is tree is empty
inline int comp_tree_is_empty(comp_tree_t *tree);

// create a tree, alloc mem and return address
comp_tree_t *new_comp_tree();

Expand Down
7 changes: 6 additions & 1 deletion include/iks_ast.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ void iks_ast_node_value_print(iks_ast_node_value_t *iks_ast_node_value);
*/
void iks_ast_append(comp_tree_t *parent, comp_tree_t *child);

/**
* delete ast
*/
void iks_ast_delete(comp_tree_t *ast);

/**
* append a ast_node_value as child(create one) to another ast_node
*/
Expand All @@ -92,7 +97,7 @@ void iks_ast_init();
/**
* collection of procedures to make a ast node
*/
comp_tree_t *iks_ast_new_node(int type, comp_grammar_symbol_t *symbol);
comp_tree_t *iks_ast_new_node(int type, comp_grammar_symbol_t *symbol, comp_tree_t *t);

/**
* collection of procedures to connect two ast nodes
Expand Down
14 changes: 14 additions & 0 deletions include/iks_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,18 @@ int verify_function_args(comp_grammar_symbol_t *s, comp_list_t *args);

int symbol_is_iks_type(comp_grammar_symbol_t *s,int iks_type);

/**
* return type inferred (only works with int, float and bool)
*/
int infer_type(comp_tree_t *type1, comp_tree_t *type2);

/**
* handling type errors
*/
int type_error(comp_grammar_symbol_t *s, int error_type);

void create_scope();
void delete_scope();
void ast_set_type(comp_tree_t *ast, int type);

#endif
25 changes: 25 additions & 0 deletions input/etapa4/errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#define IKS_SUCCESS 0 //caso não houver nenhum tipo de erro

/* Verificação de declarações */
#define IKS_ERROR_UNDECLARED 1 //identificador não declarado
#define IKS_ERROR_DECLARED 2 //identificador já declarado

/* Uso correto de identificadores */
#define IKS_ERROR_VARIABLE 3 //identificador deve ser utilizado como variável
#define IKS_ERROR_VECTOR 4 //identificador deve ser utilizado como vetor
#define IKS_ERROR_FUNCTION 5 //identificador deve ser utilizado como função

/* Tipos e tamanho de dados */
#define IKS_ERROR_WRONG_TYPE 6 //tipos incompatíveis
#define IKS_ERROR_STRING_TO_X 7 //coerção impossível do tipo string
#define IKS_ERROR_CHAR_TO_X 8 //coerção impossível do tipo char

/* Argumentos e parâmetros */
#define IKS_ERROR_MISSING_ARGS 9 //faltam argumentos
#define IKS_ERROR_EXCESS_ARGS 10 //sobram argumentos
#define IKS_ERROR_WRONG_TYPE_ARGS 11 //argumentos incompatíveis

/* Verificação de tipos em comandos */
#define IKS_ERROR_WRONG_PAR_INPUT 12 //parâmetro não é identificador
#define IKS_ERROR_WRONG_PAR_OUTPUT 13 //parâmetro não é literal string ou expressão
#define IKS_ERROR_WRONG_PAR_RETURN 14 //parâmetro não é expressão compatível com tipo do retorno
5 changes: 5 additions & 0 deletions input/etapa4/s00.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* IKS_ERROR_UNDECLARED */
int:f()
{
x = 1;
}
7 changes: 7 additions & 0 deletions input/etapa4/s01.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* IKS_ERROR_UNDECLARED */
int:f()
int:x;
{
x = 1;
y = 1;
}
5 changes: 5 additions & 0 deletions input/etapa4/s02.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* IKS_ERROR_UNDECLARED */
int:f()
{
g();
}
6 changes: 6 additions & 0 deletions input/etapa4/s03.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_DECLARED */
int:f()
int:x;
int:x;
{
}
3 changes: 3 additions & 0 deletions input/etapa4/s04.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* IKS_ERROR_DECLARED */
int:f(){}
int:f(){}
6 changes: 6 additions & 0 deletions input/etapa4/s05.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_VARIABLE */
int:f()
int:x;
{
x[10] = 1;
}
6 changes: 6 additions & 0 deletions input/etapa4/s06.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_VECTOR */
int:x[10];
int:f()
{
x = 1;
}
6 changes: 6 additions & 0 deletions input/etapa4/s07.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_FUNCTION */
int:x(){}
int:f()
{
x = 1;
}
7 changes: 7 additions & 0 deletions input/etapa4/s08.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* IKS_ERROR_STRING_TO_X */
int:x;
string:str;
int:f()
{
x = str;
}
7 changes: 7 additions & 0 deletions input/etapa4/s09.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* IKS_ERROR_CHAR_TO_X */
int:x;
char:c;
int:f()
{
x = c;
}
6 changes: 6 additions & 0 deletions input/etapa4/s10.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_MISSING_ARGS */
int:g(int:x){}
int:f()
{
g();
}
6 changes: 6 additions & 0 deletions input/etapa4/s11.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_EXCESS_ARGS */
int:g(int:x){}
int:f()
{
g(10, 12);
}
6 changes: 6 additions & 0 deletions input/etapa4/s12.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_WRONG_TYPE_ARGS */
int:g(int:x){}
int:f()
{
g('c');
}
6 changes: 6 additions & 0 deletions input/etapa4/s13.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_WRONG_TYPE_ARGS */
int:g(int:x){}
int:f()
{
g("str");
}
5 changes: 5 additions & 0 deletions input/etapa4/s14.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* IKS_ERROR_WRONG_PAR_INPUT */
int:f()
{
input 10;
}
5 changes: 5 additions & 0 deletions input/etapa4/s15.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* IKS_ERROR_WRONG_PAR_OUTPUT */
int:f()
{
output 'c';
}
5 changes: 5 additions & 0 deletions input/etapa4/s16.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* IKS_ERROR_WRONG_PAR_RETURN */
int:f()
{
return "str";
}
7 changes: 7 additions & 0 deletions input/etapa4/s17.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* IKS_ERROR_STRING_TO_X */
char:x;
string:str;
int:f()
{
x = str;
}
7 changes: 7 additions & 0 deletions input/etapa4/s18.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* IKS_ERROR_CHAR_TO_X */
char:x;
string:str;
int:f()
{
str = x;
}
6 changes: 6 additions & 0 deletions input/etapa4/s19.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_WRONG_TYPE */
int:f()
string:str;
{
str = f();
}
6 changes: 6 additions & 0 deletions input/etapa4/s20.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_WRONG_TYPE */
int:f()
char:c;
{
c = f();
}
6 changes: 6 additions & 0 deletions input/etapa4/s21.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_WRONG_TYPE */
int:f()
char:c;
{
c = 10.2;
}
6 changes: 6 additions & 0 deletions input/etapa4/s22.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_WRONG_TYPE */
int:f()
string:str;
{
str = 10.2;
}
6 changes: 6 additions & 0 deletions input/etapa4/s23.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_STRING_TO_X */
int:x[10];
int:f()
{
x["str"] = 3;
}
6 changes: 6 additions & 0 deletions input/etapa4/s24.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_CHAR_TO_X */
int:x[10];
int:f()
{
x['c'] = 3;
}
5 changes: 5 additions & 0 deletions input/etapa4/s25.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/* IKS_SUCCESS */
char:f()
{
return f();
}
6 changes: 6 additions & 0 deletions input/etapa4/s26.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_CHAR_TO_X */
int:f()
int:x;
{
x = 10 + 'c';
}
6 changes: 6 additions & 0 deletions input/etapa4/s27.iks
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/* IKS_ERROR_STRING_TO_X */
int:f()
int:x;
{
x = 10 + 3.4 * "str" + 2.3;
}
Loading