- debugged/fixed some issues.

- issue with functions causing stack overflow (ex function and linked lists)
master
xerox 5 years ago
parent dbad021b15
commit 02183ac8e3

@ -120,7 +120,6 @@ print:
VARNAME { $$ = create_print_var_node($1); }
| expr { $$ = create_print_statement(1, $1, NULL); }
| STRING { $$ = create_print_statement(2, 0, $1); }
| ',' print { $$ = $2; }
;
%%

@ -1,6 +1,7 @@
def Main : {
if[ 10 > 4 ] : {
printf["Hello world!"];
};
printf["hello world"];
printf["wtf2"];
printf["wtf1"];
};
call Main;
call Main;

@ -15,6 +15,7 @@
node_info *create_function(char *p_name, node_info *p_stmts)
{
node_info *new_node = malloc(sizeof(node_info));
new_node->opperation = 7;
new_node->type = FUNCTION;
new_node->name = p_name;
new_node->_function_body = malloc(sizeof(node_info));
@ -32,6 +33,7 @@ node_info *create_function(char *p_name, node_info *p_stmts)
node_info *create_function_call(char *p_name)
{
node_info *new_node = malloc(sizeof(node_info));
new_node->opperation = 7;
new_node->type = FUNCTION_CALL;
new_node->name = p_name;
new_node->next = NULL;
@ -67,4 +69,4 @@ node_info *create_compound_statement(node_info *new_statement_list, node_info *s
p->next->next = NULL;
}
return statement_head;
}
}

@ -2,6 +2,7 @@
#define INCLUDE_H
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>
#include "../hashmap/map.h"
@ -80,4 +81,4 @@ typedef struct node_info
struct node_info *local_list;
struct map_void_t *_var_list;
} node_info;
#endif
#endif

1945
lex.yy.c

File diff suppressed because it is too large Load Diff

@ -1,4 +1,3 @@
#include <stdlib.h>
#include "linked_list.h"
/**
@ -6,9 +5,11 @@
* @param head of linked list to be freed
* @return void
*/
void _free_linked_list(node_info *p_list) {
void _free_linked_list(node_info *p_list)
{
node_info *temp;
while(p_list->next) {
while(p_list->next)
{
temp = p_list;
p_list = p_list->next;
free(temp);
@ -20,11 +21,13 @@ void _free_linked_list(node_info *p_list) {
* @param nodeInfo list to be copied
* @return copied list
*/
node_info *copy_linked_list(node_info *p_list) {
node_info *copy_linked_list(node_info *p_list)
{
node_info *new_list = malloc(sizeof(node_info));
new_list->next = NULL;
node_info *copy_list = new_list;
while(p_list->next) {
while(p_list->next)
{
p_list = p_list->next;
copy_list->next = p_list;
copy_list = copy_list->next;
@ -65,4 +68,4 @@ bool linked_list_remove(node_info* p_head, node_info* delete_node)
}
}
return false;
}
}

@ -5,5 +5,5 @@
void _free_linked_list(node_info *p_list);
node_info *copy_linked_list(node_info *p_list);
void linked_list_add(node_info* p_head, node_info* new_node);
bool linked_list_remove(node_info* p_head, node_info* delete_node)
#endif
bool linked_list_remove(node_info* p_head, node_info* delete_node);
#endif

@ -1,5 +1,6 @@
#include <stdio.h>
#include <stdlib.h>
#include "parser.h"
#include "../vars/vars.c"
//hashmaps/link list heads
@ -12,9 +13,9 @@ node_info* create_var_assignment_string(char *p_name, char *value)
{
node_info *new_node = malloc(sizeof(node_info));
variable *new_var = make_variable_string(p_name, value);
newNode->type = ASSIGNMENT;
newNode->opperation = 1;
newNode->var = new_var;
new_node->type = ASSIGNMENT;
new_node->opperation = 1;
new_node->var = new_var;
return new_node;
}
@ -22,9 +23,9 @@ node_info* create_var_assignment_int(char *p_name, int value)
{
node_info *new_node = malloc(sizeof(node_info));
variable *new_var = make_variable_int(p_name, value);
newNode->type = ASSIGNMENT;
newNode->opperation = 1;
newNode->var = new_var;
new_node->type = ASSIGNMENT;
new_node->opperation = 1;
new_node->var = new_var;
return new_node;
}
@ -32,9 +33,9 @@ node_info* create_var_assignment_char(char *p_name, char value)
{
node_info *new_node = malloc(sizeof(node_info));
variable *new_var = make_variable_char(p_name, value);
newNode->type = ASSIGNMENT;
newNode->opperation = 1;
newNode->var = new_var;
new_node->type = ASSIGNMENT;
new_node->opperation = 1;
new_node->var = new_var;
return new_node;
}
@ -43,9 +44,9 @@ node_info* create_var_assignment_double(char *p_name, double value)
node_info *new_node = malloc(sizeof(node_info));
variable *new_var = make_variable_double(p_name, value);
//new node stuff
newNode->type = ASSIGNMENT;
newNode->opperation = 1;
newNode->var = newVar;
new_node->type = ASSIGNMENT;
new_node->opperation = 1;
new_node->var = new_var;
return new_node;
}
@ -120,8 +121,8 @@ void ex(node_info *exec_node)
printf("{ERROR} CHECK YACC FILE FOR INCORRECT PRINT\n");
}
break;
//logic (if, while, for, etc)
case 4:
{
switch(exec_node->logicalExpression.opperation) {
case 1:
if (exec_node->logicalExpression.expr == 1)
@ -135,15 +136,18 @@ void ex(node_info *exec_node)
printf("{ERROR} SOMETHING WRONG WITH LOGICAL EXPRESSION CHECK YACC\n");
}
break;
}
case 5:
while(exec_node->next != NULL)
{
while(exec_node->next)
{
exec_node = exec_node->next;
ex(exec_node);
ex(exec_node);
}
break;
}
case 6:
;
{
variable_values *value = get_value(exec_node->name, _var_map);
switch(value->type)
{
@ -165,23 +169,23 @@ void ex(node_info *exec_node)
printf("{ERROR} NO SUCH VARIABLE TYPE CHECK YACC!\n");
}
break;
//TODO update default to case 7 for functions
default:
;
}
case 7:
{
switch(exec_node->type)
{
case FUNCTION_CALL:
;
//gets the statements of a function with the provided name
{
node_info *_stmts = *map_get(&*((map_void_t* ) _function_list), exec_node->name);
while (_stmts->next != NULL) { //loop over all the statements and execute them
while (_stmts->next != NULL)
{
_stmts = _stmts->next;
ex(_stmts);
}
break;
}
case FUNCTION:
;
{
//if the list of functions already defined is null then we malloc space for it.
if (!_function_list)
{
@ -196,10 +200,12 @@ void ex(node_info *exec_node)
} else //else we dont malloc, we just put the function inside of the hashmap.
map_set(&*((map_void_t* ) _function_list), exec_node->name, &*exec_node->_function_body);
break;
}
default:
;
//TODO add error here and close
}
break;
}
}
}
}

@ -8,4 +8,4 @@ node_info* create_var_assignment_char(char *pName, char value);
node_info* create_var_assignment_double(char *pName, double value);
node_info* add_to_compound_statement(node_info *new_statement, node_info *statement_head);
void ex(node_info *exec_node);
#endif
#endif

@ -29,12 +29,11 @@ node_info *create_print_statement(int opperation, int value, char *string)
switch(opperation)
{
case 1:
n->opperation = 3;//this needs to not be a magic number lol
n->opperation = 3;
a.value = value;
a.opperation = 1;
n->printExpression = a;
return n;
//else we are printing a string
case 2:
n->opperation = 3;
a.string = string;
@ -51,4 +50,4 @@ node_info *create_print_statement(int opperation, int value, char *string)
default:
printf("{ERROR} PRINT STATEMENT ERROR IN YACC\n");
}
}
}

@ -1,8 +1,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "../includes/include.h"
#include "vars.h"
/**
* Version: 0.2
@ -16,7 +15,7 @@
void add_var(char *p_name, variable_values *p_values, map_void_t* p_var_map)
{
//if variable map is null
if(!p_var_map)
if(!p_var_map)
{
p_var_map = malloc(sizeof(map_void_t));
map_init(&*((map_void_t *) p_var_map));

@ -1,9 +1,10 @@
#ifndef VARS_H
#define VARS_H
#include "../includes/include.h"
void add_var(char *name, variable_values *values, map_void_t* p_var_map);
variable_values *get_value(char *p_name, map_void_t* p_var_map);
variable* make_variable_int(char *p_name, int value);
variable* make_variable_double(char *p_name, double value);
variable* make_variable_char(char *p_name, char value);
variable* make_variable_string(char *p_name, char *value);
#endif
#endif

1757
y.tab.c

File diff suppressed because it is too large Load Diff

@ -0,0 +1,116 @@
/* A Bison parser, made by GNU Bison 3.0.4. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2015 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* As a special exception, you may create a larger work that contains
part or all of the Bison parser skeleton and distribute that work
under terms of your choice, so long as that work isn't itself a
parser generator using the skeleton or a modified version thereof
as a parser skeleton. Alternatively, if you modify or redistribute
the parser skeleton itself, you may (at your option) remove this
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_YY_Y_TAB_H_INCLUDED
# define YY_YY_Y_TAB_H_INCLUDED
/* Debug traces. */
#ifndef YYDEBUG
# define YYDEBUG 0
#endif
#if YYDEBUG
extern int yydebug;
#endif
/* Token type. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
INCREASE = 258,
DECREASE = 259,
PRINTF = 260,
IF = 261,
END = 262,
KEYWORD_S = 263,
KEYWORD_I = 264,
KEYWORD_C = 265,
QUOTE = 266,
ELSE = 267,
WHILE = 268,
DEF = 269,
CALL = 270,
INTEGER = 271,
STRING = 272,
VARNAME = 273,
CHAR = 274,
DOUBLEVAR = 275
};
#endif
/* Tokens. */
#define INCREASE 258
#define DECREASE 259
#define PRINTF 260
#define IF 261
#define END 262
#define KEYWORD_S 263
#define KEYWORD_I 264
#define KEYWORD_C 265
#define QUOTE 266
#define ELSE 267
#define WHILE 268
#define DEF 269
#define CALL 270
#define INTEGER 271
#define STRING 272
#define VARNAME 273
#define CHAR 274
#define DOUBLEVAR 275
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
union YYSTYPE
{
#line 38 "deon.y" /* yacc.c:1909 */
char *str;
int num;
char character;
double Double;
struct node_info *nPtr;
#line 104 "y.tab.h" /* yacc.c:1909 */
};
typedef union YYSTYPE YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
int yyparse (void);
#endif /* !YY_YY_Y_TAB_H_INCLUDED */
Loading…
Cancel
Save