%{
void parser_process(struct Node* node);
+char* __dw_strdup(const char* a);
%}
%%
$<node>$.nodes[0]->nodes = NULL;
$<node>$.nodes[0]->ident = NULL;
$<node>$.nodes[0]->string = NULL;
- if($<node>1.ident != NULL) $<node>$.nodes[0]->ident = strdup($<node>1.ident);
- if($<node>1.string != NULL) $<node>$.nodes[0]->string = strdup($<node>1.string);
+ if($<node>1.ident != NULL) $<node>$.nodes[0]->ident = __dw_strdup($<node>1.ident);
+ if($<node>1.string != NULL) $<node>$.nodes[0]->string = __dw_strdup($<node>1.string);
if($<node>1.nodes != NULL) $<node>$.nodes[0]->nodes = $<node>1.nodes;
$<node>$.nodes[1] = NULL;
}
$<node>$.nodes[i]->nodes = NULL;
$<node>$.nodes[i]->ident = NULL;
$<node>$.nodes[i]->string = NULL;
- if($<node>3.ident != NULL) $<node>$.nodes[i]->ident = strdup($<node>3.ident);
- if($<node>3.string != NULL) $<node>$.nodes[i]->string = strdup($<node>3.string);
+ if($<node>3.ident != NULL) $<node>$.nodes[i]->ident = __dw_strdup($<node>3.ident);
+ if($<node>3.string != NULL) $<node>$.nodes[i]->string = __dw_strdup($<node>3.string);
if($<node>3.nodes != NULL) $<node>$.nodes[i]->nodes = $<node>3.nodes;
$<node>$.nodes[i + 1] = NULL;
free(old_nodes);
#if defined(YYBISON)
const char* yaccver = "GNU Bison " YYBISON_VERSION;
+#error "GNU Bison does not work. Use Berkeley Yacc."
#elif defined(YYBYACC)
#define XSTR(x) #x
#define STR(x) XSTR(x)
#include <stdbool.h>
-int __dw_parser_parse(const char* str, bool top);
+#include "../Grammar/dw.tab.h"
+
+struct Node* __dw_parser_parse(const char* str, bool top);
#ifdef __cplusplus
}
r->error = false;
r->value = NULL;
- int err;
- if((err = __dw_parser_parse(code, dolog)) != DW_ERR_SUCCESS) {
+ struct Node* node;
+ if((node = __dw_parser_parse(code, dolog)) == NULL) {
r->error = true;
- r->errnum = err;
+ r->errnum = DW_ERR_PARSER_FAIL;
}
return r;
}
}
-int __dw_parser_parse(const char* str, bool top) {
+struct Node* __dw_parser_parse(const char* str, bool top) {
+ extern YYSTYPE yyval;
#ifdef PARSER_DEBUG
yydebug = 1;
#endif
void* buf = yy_scan_string(str);
if(yyparse() != 0) {
yy_delete_buffer(buf);
- return DW_ERR_PARSER_FAIL;
- } else {
- extern YYSTYPE yyval;
- parser_process(&yyval.node);
+ return NULL;
}
+ parser_process(&yyval.node);
yy_delete_buffer(buf);
- return DW_ERR_SUCCESS;
+ return &yyval.node;
}