summaryrefslogtreecommitdiff
path: root/src/core/interpret.c
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2008-12-15 20:57:29 +0000
committerPaul Buetow <paul@buetow.org>2008-12-15 20:57:29 +0000
commit44c97ead68a274e462460eef33d67e7442c2fa47 (patch)
tree2d7347fa25eb8d0c61a090f84983c64d055ea11f /src/core/interpret.c
parent117201ad10df2859fb3510e8437d776f3a691f69 (diff)
say foo[1] works
Diffstat (limited to 'src/core/interpret.c')
-rw-r--r--src/core/interpret.c55
1 files changed, 38 insertions, 17 deletions
diff --git a/src/core/interpret.c b/src/core/interpret.c
index 906e0b3..5c2ad02 100644
--- a/src/core/interpret.c
+++ b/src/core/interpret.c
@@ -1,14 +1,14 @@
/*:*
*: File: ./src/core/interpret.c
*: A simple interpreter
- *:
+ *:
*: WWW : http://fype.buetow.org
*: AUTHOR : http://paul.buetow.org
*: E-Mail : fype at dev.buetow.org
- *:
- *: Copyright (c) 2005 2006 2007 2008, Paul C. Buetow
+ *:
+ *: Copyright (c) 2005 2006 2007 2008, 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
@@ -16,20 +16,20 @@
*: * 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 P. B. Labs nor the names of its contributors may
- *: be used to endorse or promote products derived from this software
+ *: * Neither the name of P. B. Labs 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
+ *:
+ *: 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)
+ *: 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
+ *: 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.
*:*/
@@ -53,6 +53,7 @@
#define _HAS_NEXT listiterator_has_next(p_interpret->p_iter)
#define _NEXT_ORG _next(p_interpret);
#define _NEXT if (!_next(p_interpret)) { return (2); }
+#define _NEXT2 _NEXT _NEXT
#define _NEXT_TT _next_tt(p_interpret)
#define _SKIP _next(p_interpret);
@@ -802,10 +803,10 @@ _term(Interpret *p_interpret) {
_CHECK TRACK
switch (p_interpret->tt) {
+ case TT_ARRAY:
case TT_STRING:
case TT_INTEGER:
case TT_DOUBLE:
- case TT_ARRAY:
stack_push(p_interpret->p_stack, p_interpret->p_token);
// Checks if the term is the last element of an array
// say ["element"] # The "element"
@@ -818,7 +819,27 @@ _term(Interpret *p_interpret) {
case TT_IDENT:
{
if (_NEXT_TT != TT_ASSIGN) {
- if (function_is_buildin(p_interpret->p_token)) {
+ if (_NEXT_TT == TT_PARANT_AL) {
+ Token *p_token_var = p_interpret->p_token;
+ char *c_name = token_get_val(p_token_var);
+ Symbol *p_symbol = scope_get(p_interpret->p_scope, c_name);
+
+ if (p_symbol == NULL)
+ _INTERPRET_ERROR("No such symbol", p_token_var);
+ Token *p_token_array = symbol_get_val(p_symbol);
+ Array *p_array = TOKEN_GET_ARRAY(p_token_array);
+ if (p_array == NULL)
+ _INTERPRET_ERROR("Expected an array", p_interpret->p_token);
+
+ _NEXT2
+ Token *p_token_val = array_get(p_array,
+ convert_to_integer_get(p_interpret->p_token));
+ stack_push(p_interpret->p_stack, p_token_val);
+ _NEXT
+
+ return (1);
+
+ } else if (function_is_buildin(p_interpret->p_token)) {
Token *p_token = p_interpret->p_token;
Stack *p_stack = p_interpret->p_stack;
p_interpret->p_stack = stack_new();