summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/convert.c216
-rw-r--r--src/core/frame.c152
-rw-r--r--src/core/frame.h (renamed from src/core/scope.h)64
-rw-r--r--src/core/functions.c985
-rw-r--r--src/core/functions.h64
-rw-r--r--src/core/garbage.c144
-rw-r--r--src/core/interpret.c1227
-rw-r--r--src/core/interpret.h52
-rw-r--r--src/core/lambda.c98
-rw-r--r--src/core/lambda.h (renamed from src/core/convert.h)42
-rw-r--r--src/core/promise.c60
-rw-r--r--src/core/promise.h (renamed from src/core/function.c)36
-rw-r--r--src/core/scanner.c139
-rw-r--r--src/core/scanner.h14
-rw-r--r--src/core/scope.c169
-rw-r--r--src/core/symbol.c122
-rw-r--r--src/core/symbol.h71
-rw-r--r--src/core/token.c341
-rw-r--r--src/core/token.h144
-rw-r--r--src/core/tools.c (renamed from src/core/garbage.h)64
-rw-r--r--src/core/tools.h (renamed from src/core/function.h)26
-rw-r--r--src/core/variable.c (renamed from src/core/reference.c)40
-rw-r--r--src/core/variable.h (renamed from src/core/reference.h)38
23 files changed, 829 insertions, 3479 deletions
diff --git a/src/core/convert.c b/src/core/convert.c
deleted file mode 100644
index cf8987e..0000000
--- a/src/core/convert.c
+++ /dev/null
@@ -1,216 +0,0 @@
-/*:*
- *: File: ./src/core/convert.c
- *: A simple interpreter
- *:
- *: WWW : http://fype.buetow.org
- *: AUTHOR : http://paul.buetow.org
- *: E-Mail : fype at dev.buetow.org
- *:
- *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow
- *: All rights reserved.
- *:
- *: Redistribution and use in source and binary forms, with or without modi-
- *: fication, are permitted provided that the following conditions are met:
- *: * Redistributions of source code must retain the above copyright
- *: notice, this list of conditions and the following disclaimer.
- *: * Redistributions in binary form must reproduce the above copyright
- *: notice, this list of conditions and the following disclaimer in the
- *: documentation and/or other materials provided with the distribution.
- *: * Neither the name of buetow.org nor the names of its contributors may
- *: be used to endorse or promote products derived from this software
- *: without specific prior written permission.
- *:
- *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
- *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
- *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- *: POSSIBILITY OF SUCH DAMAGE.
- *:*/
-
-#include "convert.h"
-#include "../data/array.h"
-
-void
-convert_to_integer(Token *p_token) {
- switch (token_get_tt(p_token)) {
- case TT_INTEGER:
- break;
- case TT_DOUBLE:
- token_set_tt(p_token, TT_INTEGER);
- token_set_ival(p_token, (int)token_get_dval(p_token));
- break;
- case TT_STRING:
- token_set_tt(p_token, TT_INTEGER);
- token_set_ival(p_token, atoi(token_get_val(p_token)));
- break;
- case TT_ARRAY:
- token_set_tt(p_token, TT_INTEGER);
- token_set_ival(p_token, array_get_size(p_token->p_array));
- break;
- default:
- ERROR("Ouups(%s)", tt_get_name(token_get_tt(p_token)));
- break;
- }
-}
-
-int
-convert_to_integer_get(Token *p_token) {
- switch (token_get_tt(p_token)) {
- case TT_INTEGER:
- return (token_get_ival(p_token));
- case TT_DOUBLE:
- return ((int) token_get_dval(p_token));
- case TT_STRING:
- return (atoi(token_get_val(p_token)));
- case TT_ARRAY:
- return (array_get_size(p_token->p_array));
- break;
- default:
- ERROR("Ouups(%s)", tt_get_name(token_get_tt(p_token)));
- }
-
- return (0); /* Never reach this point */
-}
-
-void
-convert_to_double(Token *p_token) {
- switch (token_get_tt(p_token)) {
- case TT_INTEGER:
- token_set_tt(p_token, TT_DOUBLE);
- token_set_dval(p_token, token_get_ival(p_token));
- break;
- case TT_DOUBLE:
- break;
- case TT_STRING:
- token_set_tt(p_token, TT_DOUBLE);
- token_set_dval(p_token, atof(token_get_val(p_token)));
- break;
- case TT_ARRAY:
- token_set_tt(p_token, TT_DOUBLE);
- token_set_dval(p_token, array_get_size(p_token->p_array));
- break;
- default:
- token_print_val(p_token);
- ERROR("Datatype conversion error '%s'", token_get_val(p_token));
- break;
- }
-}
-
-void
-convert_to_string(Token *p_token) {
- switch (token_get_tt(p_token)) {
- case TT_INTEGER:
- {
- token_set_tt(p_token, TT_STRING);
- char c_tmp[1024];
- sprintf(c_tmp, "%d", token_get_ival(p_token));
- int i_len = strlen(c_tmp);
- p_token->c_val = realloc(p_token->c_val, sizeof(char) * (i_len + 1));
- strcpy(p_token->c_val, c_tmp);
- p_token->c_val[i_len] = 0;
- }
- break;
- case TT_DOUBLE:
- {
- token_set_tt(p_token, TT_STRING);
- char c_tmp[1024];
- sprintf(c_tmp, "%f", token_get_dval(p_token));
- int i_len = strlen(c_tmp);
- p_token->c_val = realloc(p_token->c_val, sizeof(char) * (i_len + 1));
- strcpy(p_token->c_val, c_tmp);
- p_token->c_val[i_len] = 0;
- }
- case TT_ARRAY:
- {
- token_set_tt(p_token, TT_STRING);
- char c_tmp[1024];
- sprintf(c_tmp, "%d", array_get_size(p_token->p_array));
- int i_len = strlen(c_tmp);
- p_token->c_val = realloc(p_token->c_val, sizeof(char) * (i_len + 1));
- strcpy(p_token->c_val, c_tmp);
- p_token->c_val[i_len] = 0;
- }
- break;
- case TT_STRING:
- break;
- default:
- ERROR("Datatype conversion error");
- break;
- }
-}
-
-void
-convert_to_array(Token *p_token) {
- ERROR("not yet implemented");
-}
-
-void
-convert_to_tt(Token *p_token, TokenType tt) {
- switch (tt) {
- case TT_INTEGER:
- convert_to_integer(p_token);
- break;
- case TT_DOUBLE:
- convert_to_double(p_token);
- break;
- case TT_STRING:
- convert_to_string(p_token);
- break;
- case TT_ARRAY:
- convert_to_array(p_token);
- break;
- default:
- ERROR("Ouups!");
- }
-}
-
-TokenType
-convert_to_highest(Token *p_token1, Token *p_token2) {
- TokenType tt_highest = token_get_tt(p_token1);
-
- if (tt_highest < token_get_tt(p_token2)) {
- tt_highest = token_get_tt(p_token2);
-
- convert_to_tt(p_token1, tt_highest);
-
- } else {
- convert_to_tt(p_token2, tt_highest);
- }
-
- return (tt_highest);
-}
-
-TokenType
-convert_function_arg_types_to_highest(Stack *p_stack_args, int i_args) {
-
- if (i_args <= 0)
- i_args = stack_size(p_stack_args);
-
- StackIterator *p_iter = stackiterator_new(p_stack_args);
- TokenType tt_highest = TT_INTEGER;
-
- for (int i = 0; i < i_args && stackiterator_has_next(p_iter); ++i) {
- Token *p_token = stackiterator_next(p_iter);
- if (token_get_tt(p_token) > tt_highest)
- tt_highest = token_get_tt(p_token);
- }
-
- stackiterator_delete(p_iter);
- p_iter = stackiterator_new(p_stack_args);
-
- for (int i = 0; i < i_args && stackiterator_has_next(p_iter); ++i) {
- Token *p_token = stackiterator_next(p_iter);
- convert_to_tt(p_token, tt_highest);
- }
-
- stackiterator_delete(p_iter);
-
- return (tt_highest);
-}
-
diff --git a/src/core/frame.c b/src/core/frame.c
new file mode 100644
index 0000000..fb4665d
--- /dev/null
+++ b/src/core/frame.c
@@ -0,0 +1,152 @@
+/*:*
+ *: File: ./src/core/frame.c
+ *: A simple Fype interpreter
+ *:
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
+ *:
+ *: The Fype Language; (c) 2005 - 2010 Paul Buetow
+ *:
+ *: Redistribution and use in source and binary forms, with or without modi-
+ *: fication, are permitted provided that the following conditions are met:
+ *: * Redistributions of source code must retain the above copyright
+ *: notice, this list of conditions and the following disclaimer.
+ *: * Redistributions in binary form must reproduce the above copyright
+ *: notice, this list of conditions and the following disclaimer in the
+ *: documentation and/or other materials provided with the distribution.
+ *: * Neither the name of buetow.org nor the names of its contributors may
+ *: be used to endorse or promote products derived from this software
+ *: without specific prior written permission.
+ *:
+ *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
+ *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
+ *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *: POSSIBILITY OF SUCH DAMAGE.
+ *:*/
+
+#include "frame.h"
+#include "lambda.h"
+#include "variable.h"
+
+unsigned _I_FRAME_ID_COUNT = 0;
+
+Symbol*
+symbol_new(SymbolType st, void *p_val) {
+ Symbol *p_symbol = malloc(sizeof(Symbol));
+
+ p_symbol->st = st;
+ p_symbol->p_val = p_val;
+
+ return (p_symbol);
+}
+
+void
+symbol_delete(Symbol *p_symbol) {
+ switch (p_symbol->st) {
+ case ST_LAMBDA:
+ lambda_delete(p_symbol->p_val);
+ break;
+ case ST_VARIABLE:
+ variable_delete(p_symbol->p_val);
+ break;
+ }
+
+ free(p_symbol);
+}
+
+void
+symbol_delete_cb(void *p_symbol) {
+ symbol_delete(p_symbol);
+}
+
+char*
+symbol_get_type_name(Symbol *p_symbol) {
+ switch (p_symbol->st) {
+ case ST_LAMBDA:
+ return ("ST_LAMBDA");
+ case ST_VARIABLE:
+ return ("ST_VARIABLE");
+ }
+
+ return ("ST_UNKNOWN");
+}
+
+Frame*
+frame_new(Frame *p_parent_frame) {
+ Frame *p_frame = malloc(sizeof(Frame));
+
+ p_frame->p_parent_frame = p_parent_frame;
+ p_frame->p_hash_symbols = hash_new(8);
+ p_frame->i_frame_id = _I_FRAME_ID_COUNT++;
+
+ return (p_frame);
+}
+
+void
+frame_delete(Frame *p_frame) {
+ Hash *p_hash_symbols = p_frame->p_hash_symbols;
+
+ hash_iterate(p_hash_symbols, symbol_delete_cb);
+ hash_delete(p_hash_symbols);
+}
+
+_Bool
+frame_add_symbol(Frame *p_frame, char *c_name, SymbolType st, void *p_val) {
+ Hash *p_hash_symbols = p_frame->p_hash_symbols;
+
+ if (hash_key_exists(p_hash_symbols, c_name))
+ return (false);
+
+
+ Symbol *p_symbol = symbol_new(st, p_val);
+ hash_insert(p_hash_symbols, c_name, p_symbol);
+
+ return (true);
+}
+
+Symbol*
+frame_get_symbol(Frame *p_frame, char *c_name) {
+ void *p_val = hash_get(p_frame->p_hash_symbols, c_name);
+
+ if (!p_val && p_frame->p_parent_frame)
+ return (frame_get_symbol(p_frame->p_parent_frame, c_name));
+
+ return (p_val);
+}
+
+void
+_symbol_print_cb(void *p_val, char *c_name) {
+ Symbol *p_symbol = p_val;
+ switch (p_symbol->st) {
+ case ST_LAMBDA:
+ lambda_print(p_symbol->p_val);
+ break;
+ case ST_VARIABLE:
+ variable_print(p_symbol->p_val);
+ break;
+ }
+}
+
+void
+_frame_print(Frame *p_frame, int i_frame_nr) {
+ printf("FRAME(id=%u) %d:\n", p_frame->i_frame_id, i_frame_nr);
+
+ Hash *p_hash_symbols = p_frame->p_hash_symbols;
+ hash_iterate_key(p_hash_symbols, _symbol_print_cb);
+
+ if (p_frame->p_parent_frame)
+ _frame_print(p_frame->p_parent_frame, i_frame_nr + 1);
+}
+
+void
+frame_print(Frame *p_frame) {
+ _frame_print(p_frame, 0);
+}
diff --git a/src/core/scope.h b/src/core/frame.h
index c1193c9..d9d3970 100644
--- a/src/core/scope.h
+++ b/src/core/frame.h
@@ -1,13 +1,12 @@
/*:*
- *: File: ./src/core/scope.h
- *: A simple interpreter
+ *: File: ./src/core/frame.h
+ *: A simple Fype interpreter
*:
- *: WWW : http://fype.buetow.org
- *: AUTHOR : http://paul.buetow.org
- *: E-Mail : fype at dev.buetow.org
+ *: WWW: http://fype.buetow.org
+ *: AUTHOR: http://paul.buetow.org
+ *: E-Mail: fype at dev.buetow.org
*:
- *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow
- *: All rights reserved.
+ *: The Fype Language; (c) 2005 - 2010 Paul Buetow
*:
*: Redistribution and use in source and binary forms, with or without modi-
*: fication, are permitted provided that the following conditions are met:
@@ -33,28 +32,37 @@
*: POSSIBILITY OF SUCH DAMAGE.
*:*/
-#ifndef SCOPE_H
-#define SCOPE_H
+#ifndef FRAME_H
+#define FRAME_H
-#include "../data/hash.h"
-#include "../data/stack.h"
#include "../defines.h"
-#include "symbol.h"
+#include "../data/hash.h"
+
+typedef enum {
+ ST_LAMBDA,
+ ST_VARIABLE,
+} SymbolType;
typedef struct {
- Hash *p_hash_global;
- Stack *p_stack_scopes;
-} Scope;
-
-Scope* scope_new(Hash *p_hash_syms);
-void scope_delete(Scope *p_scope);
-Symbol *scope_get(Scope *p_scope, char *c_key);
-Symbol *scope_remove(Scope *p_scope, char *c_key);
-_Bool scope_exists(Scope *p_scope, char *c_key);
-_Bool scope_newset(Scope *p_scope, char *c_key, Symbol *p_symbol);
-_Bool scope_reset(Scope *p_scope, char *c_key, Symbol *p_symbol);
-void scope_down(Scope *p_scope);
-void scope_up(Scope *p_scope);
-void scope_print(Scope *p_scope);
-
-#endif /* SCOPE_H */
+ SymbolType st;
+ void *p_val;
+} Symbol;
+
+typedef struct _Frame {
+ struct _Frame *p_parent_frame;
+ Hash *p_hash_symbols;
+ unsigned i_frame_id;
+} Frame;
+
+Symbol* symbol_new(SymbolType st, void *p_val);
+void symbol_delete(Symbol *p_symbol);
+void symbol_delete_cb(void *p_symbol);
+char* symbol_get_type_name(Symbol *p_symbol);
+
+Frame* frame_new(Frame *p_parent_frame);
+void frame_delete(Frame *p_frame);
+_Bool frame_add_symbol(Frame *p_frame, char *c_name, SymbolType st, void *p_val);
+Symbol *frame_get_symbol(Frame *p_frame, char *c_name);
+void frame_print(Frame *p_frame);
+
+#endif
diff --git a/src/core/functions.c b/src/core/functions.c
deleted file mode 100644
index 82efc4f..0000000
--- a/src/core/functions.c
+++ /dev/null
@@ -1,985 +0,0 @@
-/*:*
- *: File: ./src/core/functions.c
- *: A simple interpreter
- *:
- *: WWW : http://fype.buetow.org
- *: AUTHOR : http://paul.buetow.org
- *: E-Mail : fype at dev.buetow.org
- *:
- *: Copyright (c) 2005 - 2009, Dipl.-Inform. (FH) Paul C. Buetow
- *: All rights reserved.
- *:
- *: Redistribution and use in source and binary forms, with or without modi-
- *: fication, are permitted provided that the following conditions are met:
- *: * Redistributions of source code must retain the above copyright
- *: notice, this list of conditions and the following disclaimer.
- *: * Redistributions in binary form must reproduce the above copyright
- *: notice, this list of conditions and the following disclaimer in the
- *: documentation and/or other materials provided with the distribution.
- *: * Neither the name of buetow.org nor the names of its contributors may
- *: be used to endorse or promote products derived from this software
- *: without specific prior written permission.
- *:
- *: THIS SOFTWARE IS PROVIDED BY PAUL C. BUETOW AS IS'' AND ANY EXPRESS OR
- *: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- *: WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- *: DISCLAIMED. IN NO EVENT SHALL PAUL C. BUETOW BE LIABLE FOR ANY DIRECT,
- *: INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- *: (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
- *: SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- *: HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
- *: STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
- *: IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
- *: POSSIBILITY OF SUCH DAMAGE.
- *:*/
-
-#include <stdlib.h>
-#include <sys/types.h>
-#include <unistd.h>
-
-#include "functions.h"
-
-#include "convert.h"
-#include "scope.h"
-#include "symbol.h"
-
-#define _FUNCTIONS_ERROR(m,t) \
- ERROR(\
- "%s: Function error in %s line %d pos %d near '%s'", m, \
- token_get_filename(t), \
- token_get_line_nr(t), \
- token_get_pos_nr(t), \
- token_get_val(t) \
- )
-
-Functions*
-functions_new() {
- Functions *p_functions = malloc(sizeof(Functions));
-
- p_functions->p_hash_functions = hash_new(1024);
- functions_init(p_functions);
-
- return (p_functions);
-}
-
-void
-functions_delete(Functions *p_functions) {
- hash_delete(p_functions->p_hash_functions);
- free(p_functions);
-}
-
-
-void
-_process(Interpret *p_interpret, Token *p_token_store, Token *p_token_op,
- Token *p_token_op2, Token *p_token_next) {
-
- TokenType tt_op = token_get_tt(p_token_op);
- TokenType tt_op2 = p_token_op2 == NULL
- ? TT_NONE
- : token_get_tt(p_token_op2);
-
-#ifdef DEBUG_FUNCTION_PROCESS
- if (p_token_op2 == NULL)
- printf("DEBUG::FUNCTION::PROCESS: Operator %s\n", tt_get_name(tt_op));
- else
- printf("DEBUG::FUNCTION::PROCESS: Operator %s %s\n", tt_get_name(tt_op),
- tt_get_name(tt_op2));
-
- token_print(p_token_next);
- printf("\n");
- token_print(p_token_store);
- printf("\n");
-#endif /* DEBUG_FUNCTION_PROCESS */
-
- if (p_token_op2 != NULL) {
- switch (tt_op) {
- case TT_NOT:
- switch (tt_op2) {
- case TT_ASSIGN:
- tt_op = TT_NEQ;
- break;
- default:
- break;
- }
- break;
- case TT_ASSIGN:
- switch (tt_op2) {
- case TT_ASSIGN:
- tt_op = TT_EQ;
- break;
- default:
- break;
- }
- break;
- case TT_LT:
- switch (tt_op2) {
- case TT_ASSIGN:
- tt_op = TT_LE;
- break;
- default:
- break;
- }
- break;
- case TT_GT:
- switch (tt_op2) {
- case TT_ASSIGN:
- tt_op = TT_GE;
- break;
- default:
- break;
- }
- break;
- case TT_DDOT:
- switch (tt_op2) {
- case TT_LT:
- tt_op = TT_LSHIFT;
- break;
- case TT_GT:
- tt_op = TT_RSHIFT;
- break;
- default:
- break;
- }
- break;
- default:
- break;
- }
- } else {
- switch (tt_op) {
- case TT_ASSIGN:
- {
- Token *p_token_assign = p_interpret->p_token_temp;
- TokenType tt_assign = token_get_tt(p_token_assign);
-
- if (tt_assign != TT_IDENT) {
- _FUNCTIONS_ERROR("Can only assign to symbols",
- p_token_store);
- }
-
- Symbol *p_symbol = scope_get(p_interpret->p_scope,
- token_get_val(p_token_assign));
-
- if (p_symbol == NULL) {
- _FUNCTIONS_ERROR("No such symbol",
- p_token_assign);
- }
-
- symbol_set_val(p_symbol, p_token_store);
- symbol_set_sym(p_symbol, SYM_VARIABLE);
-
- return;
- }
-
- break;
- NO_DEFAULT;
- }
- }
-
- p_token_next = token_new_copy(p_token_next);
- TokenType tt_highest = convert_to_highest(p_token_store, p_token_next);
-
-#ifdef DEBUG_FUNCTION_PROCESS
- printf("DEBUG::FUNCTION::PROCESS: ===> %s %s %s\n",
- tt_get_name(tt_highest),
- tt_get_name(tt_op),
- tt_get_name(tt_highest));
-#endif /* DEBUG_FUNCTION_PROCESS */
-
- switch (tt_op) {
- case TT_ADD:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- token_get_ival(p_token_next) +
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_dval(p_token_store,
- token_get_dval(p_token_next) +
- token_get_dval(p_token_store));
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- atoi(token_get_val(p_token_next)) +
- atoi(token_get_val(p_token_store)));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- array_append(p_token_store->p_array,
- p_token_next->p_array);
- break;
- NO_DEFAULT;
- }
- break;
- case TT_SUB:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- token_get_ival(p_token_next) -
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_dval(p_token_store,
- token_get_dval(p_token_next) -
- token_get_dval(p_token_store));
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- atoi(token_get_val(p_token_next)) -
- atoi(token_get_val(p_token_store)));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("TT_ARRAY - TT_ARRAY not yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_MULT:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- token_get_ival(p_token_next) *
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_dval(p_token_store,
- token_get_dval(p_token_next) *
- token_get_dval(p_token_store));
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- atoi(token_get_val(p_token_next)) *
- atoi(token_get_val(p_token_store)));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("TT_ARRAY * TT_ARRAY not yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_DIV:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) /
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_dval(p_token_store,
- token_get_dval(p_token_next) /
- token_get_dval(p_token_store));
- break;
- case TT_STRING:
- token_set_dval(p_token_store,
- atof(token_get_val(p_token_next)) /
- atof(token_get_val(p_token_store)));
- token_set_tt(p_token_store, TT_DOUBLE);
- break;
- case TT_ARRAY:
- ERROR("TT_ARRAY / TT_ARRAY not yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_EQ:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) ==
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_ival(p_token_store,
- token_get_dval(p_token_next) ==
- token_get_dval(p_token_store));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- strcmp(token_get_val(p_token_next),
- token_get_val(p_token_store)) == 0);
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("TT_ARRAY eq TT_ARRAY not yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_NEQ:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) !=
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_ival(p_token_store,
- token_get_dval(p_token_next) !=
- token_get_dval(p_token_store));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- strcmp(token_get_val(p_token_next),
- token_get_val(p_token_store)) != 0);
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("ARRAY bla yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_LE:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) <=
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_ival(p_token_store,
- token_get_dval(p_token_next) <=
- token_get_dval(p_token_store));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- strcmp(token_get_val(p_token_next),
- token_get_val(p_token_store)) <= 0);
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("ARRAY bla yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_GE:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) >=
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_ival(p_token_store,
- token_get_dval(p_token_next) >=
- token_get_dval(p_token_store));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- strcmp(token_get_val(p_token_next),
- token_get_val(p_token_store)) >= 0);
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("ARRAY bla yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_LT:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) <
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_ival(p_token_store,
- token_get_dval(p_token_next) <
- token_get_dval(p_token_store));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- strcmp(token_get_val(p_token_next),
- token_get_val(p_token_store)) < 0);
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("ARRAY bla yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_GT:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) >
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_ival(p_token_store,
- token_get_dval(p_token_next) >
- token_get_dval(p_token_store));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- strcmp(token_get_val(p_token_next),
- token_get_val(p_token_store)) > 0);
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("ARRAY bla yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_AND:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) &
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_ival(p_token_store,
- (int) token_get_dval(p_token_next) &
- (int) token_get_dval(p_token_store));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- atoi(token_get_val(p_token_next)) &
- atoi(token_get_val(p_token_store)));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_ARRAY:
- ERROR("ARRAY bla yet implemented");
- break;
- NO_DEFAULT;
- }
- break;
- case TT_OR:
- switch (tt_highest) {
- case TT_INTEGER:
- token_set_ival(p_token_store,
- (int) token_get_ival(p_token_next) |
- token_get_ival(p_token_store));
- break;
- case TT_DOUBLE:
- token_set_ival(p_token_store,
- (int) token_get_dval(p_token_next) |
- (int) token_get_dval(p_token_store));
- token_set_tt(p_token_store, TT_INTEGER);
- break;
- case TT_STRING:
- token_set_ival(p_token_store,
- atoi(token_get_val(p_token_next)) |
- atoi(token_get_val(p_token_store)));
- token_set_tt(p_token_store, TT_INTEGER);
- break;