26 * POSSIBILITY OF SUCH DAMAGE. |
26 * POSSIBILITY OF SUCH DAMAGE. |
27 */ |
27 */ |
28 |
28 |
29 #include <cx/string.h> |
29 #include <cx/string.h> |
30 #include <cx/linked_list.h> |
30 #include <cx/linked_list.h> |
|
31 #include <cx/array_list.h> |
31 #include <cx/compare.h> |
32 #include <cx/compare.h> |
32 |
33 |
33 #include "../public/nsapi.h" |
34 #include "../public/nsapi.h" |
34 |
35 |
35 #include "object.h" |
36 #include "object.h" |
249 NSAPIExpression* expr_parser_pop(ExprParser *parser) { |
250 NSAPIExpression* expr_parser_pop(ExprParser *parser) { |
250 CxList *stack = parser->ex_stack; |
251 CxList *stack = parser->ex_stack; |
251 if(stack->size == 0) { |
252 if(stack->size == 0) { |
252 return NULL; |
253 return NULL; |
253 } |
254 } |
254 NSAPIExpression *ret = cxListAt(stack, stack->size-1); |
255 NSAPIExpression *ret = *((NSAPIExpression**)cxListAt(stack, stack->size-1)); |
255 cxListRemove(stack, stack->size-1); |
256 cxListRemove(stack, stack->size-1); |
256 return ret; |
257 return ret; |
257 } |
258 } |
258 |
259 |
259 // takes items from ex_stack and adds a new operator expression to ex_stack |
260 // takes items from ex_stack and adds a new operator expression to ex_stack |
307 exp->left = NULL; |
308 exp->left = NULL; |
308 exp->right = NULL; |
309 exp->right = NULL; |
309 exp->value.str = func->identifier; |
310 exp->value.str = func->identifier; |
310 |
311 |
311 if(parser->ex_stack->size > 0) { |
312 if(parser->ex_stack->size > 0) { |
312 NSAPIExpression *top = cxListAt(parser->ex_stack, parser->ex_stack->size - 1); |
313 NSAPIExpression *top = *((NSAPIExpression**)cxListAt(parser->ex_stack, parser->ex_stack->size - 1)); |
313 if(top && top->operator == NSAPI_EXPRESSION_ARG) { |
314 if(top && top->operator == NSAPI_EXPRESSION_ARG) { |
314 exp->left = top; |
315 exp->left = top; |
315 cxListRemove(parser->ex_stack, parser->ex_stack->size - 1); |
316 cxListRemove(parser->ex_stack, parser->ex_stack->size - 1); |
316 } |
317 } |
317 } |
318 } |
318 |
319 |
319 if(cxListAdd(parser->ex_stack, exp)) { |
320 if(cxListAdd(parser->ex_stack, &exp)) { |
320 return 1; |
321 return 1; |
321 } |
322 } |
322 parser->expect_value = FALSE; |
323 parser->expect_value = FALSE; |
323 return 0; |
324 return 0; |
324 } |
325 } |
331 ZERO(exp, sizeof(NSAPIExpression)); |
332 ZERO(exp, sizeof(NSAPIExpression)); |
332 if(expr_set_value(parser->pool, exp, token)) { |
333 if(expr_set_value(parser->pool, exp, token)) { |
333 return 1; |
334 return 1; |
334 } |
335 } |
335 |
336 |
336 cxListAdd(parser->ex_stack, exp); |
337 cxListAdd(parser->ex_stack, &exp); |
337 if(parser->expect_arg) { |
338 if(parser->expect_arg) { |
338 ExprOpStackItem argList; |
339 ExprOpStackItem argList; |
339 argList.expect_value = TRUE; |
340 argList.expect_value = TRUE; |
340 argList.identifier = (cxstring){NULL, 0}; |
341 argList.identifier = (cxstring){NULL, 0}; |
341 argList.open_parenthesis = FALSE; |
342 argList.open_parenthesis = FALSE; |
480 |
481 |
481 if(ex_stack->size != 1) { |
482 if(ex_stack->size != 1) { |
482 return NULL; |
483 return NULL; |
483 } |
484 } |
484 |
485 |
485 return cxListAt(ex_stack, 0); |
486 NSAPIExpression **ret = cxListAt(ex_stack, 0); |
|
487 return *ret; |
486 } |
488 } |
487 |
489 |
488 NSAPIExpression* expr_parse_logical_expr(pool_handle_t *pool, CxList *tokens, size_t *pos) { |
490 NSAPIExpression* expr_parse_logical_expr(pool_handle_t *pool, CxList *tokens, size_t *pos) { |
489 CxList *op_stack = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(ExprOpStackItem)); |
491 CxList *op_stack = cxArrayListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(ExprOpStackItem), 32); |
490 CxList *ex_stack = cxPointerLinkedListCreate(pool_allocator(pool), cx_cmp_ptr); |
492 CxList *ex_stack = cxArrayListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(NSAPIExpression*), 32); |
491 |
493 |
492 ExprParser parser; |
494 ExprParser parser; |
493 parser.pool = pool; |
495 parser.pool = pool; |
494 parser.op_stack = op_stack; |
496 parser.op_stack = op_stack; |
495 parser.ex_stack = ex_stack; |
497 parser.ex_stack = ex_stack; |