Browse Source

Sol Part 3: Segfault City

master
Grissess 7 years ago
parent
commit
fc35dcfa9f
  1. 30
      ast.h
  2. BIN
      astprint
  3. 97
      astprint.c
  4. 188
      builtins.c
  5. 344
      lex.yy.c
  6. 281
      object.c
  7. 14554
      parser.output
  8. 2101
      parser.tab.c
  9. 142
      parser.tab.h
  10. 235
      parser.y
  11. 495
      runtime.c
  12. 158
      sol.h
  13. 19
      solrun.c
  14. 103
      state.c
  15. 6
      test.sol
  16. 7
      testbuild.sh
  17. 25
      tokenizer.lex

30
ast.h

@ -3,6 +3,8 @@
#include "sol.h"
#include <stdio.h>
struct tag_expr_node;
typedef struct tag_expr_node expr_node;
@ -13,7 +15,7 @@ typedef enum {LIT_INT, LIT_FLOAT, LIT_STRING} lit_t;
typedef struct {
lit_t type;
union {
int ival;
long ival;
double fval;
char *str;
};
@ -126,12 +128,16 @@ typedef struct {
stmt_node *loop;
} iter_node;
typedef struct {
expr_node *ret;
} ret_node;
typedef struct tag_stmtlist_node {
stmt_node *stmt;
struct tag_stmtlist_node *next;
} stmtlist_node;
typedef enum {ST_EXPR, ST_IFELSE, ST_LOOP, ST_ITER, ST_LIST} stmt_t;
typedef enum {ST_EXPR, ST_IFELSE, ST_LOOP, ST_ITER, ST_LIST, ST_RET, ST_CONT, ST_BREAK} stmt_t;
typedef struct tag_stmt_node {
stmt_t type;
union {
@ -140,6 +146,7 @@ typedef struct tag_stmt_node {
loop_node *loop;
iter_node *iter;
stmtlist_node *stmtlist;
ret_node *ret;
};
} stmt_node;
@ -168,7 +175,24 @@ typedef struct tag_stmt_node {
nd->binop->left->index->expr = obj; \
nd->binop->left->index->index = idx; \
nd->binop->right = val
#define BOOL_TO_INT(cond) ((cond)?1:0)
sol_object_t *sol_new_func(sol_state_t *, identlist_node *, stmt_node *);
#endif
// runtime.c
stmt_node *sol_compile(const char *);
stmt_node *sol_compile_file(FILE *);
expr_node *sol_comp_as_expr(stmt_node *);
void sol_compile_free(stmt_node *);
void st_free(stmt_node *);
void ex_free(expr_node *);
void st_print(stmt_node *);
void ex_print(expr_node *);
sol_object_t *sol_eval(sol_state_t *, expr_node *);
void sol_exec(sol_state_t *, stmt_node *);
#endif

BIN
astprint

97
astprint.c

@ -7,7 +7,7 @@
void prlev(int lev, const char *fmt, ...) {
va_list vl;
int i;
for(i = 0; i < lev; i++) putchar(' ');
va_start(vl, fmt);
vprintf(fmt, vl);
@ -27,7 +27,7 @@ void prst(stmt_node *node, int lev) {
prlev(lev, "Stmt<Expr>:");
prex(node->expr, lev+1);
break;
case ST_IFELSE:
prlev(lev, "Stmt<IfElse>:");
lev++;
@ -38,7 +38,7 @@ void prst(stmt_node *node, int lev) {
prlev(lev, "IfFalse:");
prst(node->ifelse->iffalse, lev+1);
break;
case ST_LOOP:
prlev(lev, "Stmt<Loop>:");
lev++;
@ -47,7 +47,7 @@ void prst(stmt_node *node, int lev) {
prlev(lev, "Loop:");
prst(node->loop->loop, lev+1);
break;
case ST_ITER:
prlev(lev, "Stmt<Iter>:");
lev++;
@ -57,7 +57,7 @@ void prst(stmt_node *node, int lev) {
prlev(lev, "Loop:");
prst(node->iter->loop, lev+1);
break;
case ST_LIST:
prlev(lev, "Stmt<List>:");
stmtlist_node *cur = node->stmtlist;
@ -66,6 +66,19 @@ void prst(stmt_node *node, int lev) {
cur = cur->next;
}
break;
case ST_RET:
prlev(lev, "Stmt<Ret>:");
prex(node->ret->ret, lev+1);
break;
case ST_CONT:
prlev(lev, "Stmt<Continue>");
break;
case ST_BREAK:
prlev(lev, "Stmt<Break>");
break;
}
}
@ -85,17 +98,17 @@ void prex(expr_node *node, int lev) {
case LIT_INT:
prlev(lev, "Int: %ld", node->lit->ival);
break;
case LIT_FLOAT:
prlev(lev, "Float: %f", node->lit->fval);
break;
case LIT_STRING:
prlev(lev, "String: %s", node->lit->str);
break;
}
break;
case EX_LISTGEN:
prlev(lev, "ListGen:");
cure = node->listgen->list;
@ -104,7 +117,7 @@ void prex(expr_node *node, int lev) {
cure = cure->next;
}
break;
case EX_MAPGEN:
prlev(lev, "MapGen:");
lev++;
@ -117,7 +130,7 @@ void prex(expr_node *node, int lev) {
cura = cura->next;
}
break;
case EX_BINOP:
prlev(lev, "BinOp:");
lev++;
@ -125,59 +138,59 @@ void prex(expr_node *node, int lev) {
case OP_ADD:
prlev(lev, "Op: +");
break;
case OP_SUB:
prlev(lev, "Op: -");
break;
case OP_MUL:
prlev(lev, "Op: *");
break;
case OP_DIV:
prlev(lev, "Op: /");
break;
case OP_POW:
prlev(lev, "Op: **");
break;
case OP_BAND:
prlev(lev, "Op: &");
break;
case OP_BOR:
prlev(lev, "Op: |");
break;
case OP_BXOR:
prlev(lev, "Op: ^");
break;
case OP_LAND:
prlev(lev, "Op: &&");
break;
case OP_LOR:
prlev(lev, "Op: ||");
break;
case OP_EQUAL:
prlev(lev, "Op: ==");
break;
case OP_LESS:
prlev(lev, "Op: <");
break;
case OP_GREATER:
prlev(lev, "Op: >");
break;
case OP_LESSEQ:
prlev(lev, "Op: <=");
break;
case OP_GREATEREQ:
prlev(lev, "Op: >=");
break;
@ -187,7 +200,7 @@ void prex(expr_node *node, int lev) {
prlev(lev, "Right:");
prex(node->binop->right, lev+1);
break;
case EX_UNOP:
prlev(lev, "UnOp:");
lev++;
@ -195,11 +208,11 @@ void prex(expr_node *node, int lev) {
case OP_NEG:
prlev(lev, "Op: -");
break;
case OP_BNOT:
prlev(lev, "Op: ~");
break;
case OP_LNOT:
prlev(lev, "Op: !");
break;
@ -207,7 +220,7 @@ void prex(expr_node *node, int lev) {
prlev(lev, "Expr:");
prex(node->unop->expr, lev+1);
break;
case EX_INDEX:
prlev(lev, "Index:");
lev++;
@ -216,7 +229,7 @@ void prex(expr_node *node, int lev) {
prlev(lev, "Index:");
prex(node->index->index, lev+1);
break;
case EX_SETINDEX:
prlev(lev, "SetIndex:");
lev++;
@ -227,7 +240,7 @@ void prex(expr_node *node, int lev) {
prlev(lev, "Value:");
prex(node->setindex->value, lev+1);
break;
case EX_ASSIGN:
prlev(lev, "Assign:");
lev++;
@ -235,11 +248,11 @@ void prex(expr_node *node, int lev) {
prlev(lev, "Value:");
prex(node->assign->value, lev+1);
break;
case EX_REF:
prlev(lev, "Ref: %s", node->ref->ident);
break;
case EX_CALL:
prlev(lev, "Call:");
lev++;
@ -252,7 +265,7 @@ void prex(expr_node *node, int lev) {
cure = cure->next;
}
break;
case EX_FUNCDECL:
prlev(lev, "FuncDecl:");
lev++;
@ -269,19 +282,27 @@ void prex(expr_node *node, int lev) {
}
}
int main(int argc, char **argv) {
void st_print(stmt_node *stmt) {
prst(stmt, 0);
}
void ex_print(expr_node *expr) {
prex(expr, 0);
}
/*int main(int argc, char **argv) {
stmt_node *program = NULL;
if(argc>1) yydebug = 1;
if(yyparse(&program)) {
printf("Syntax error (somewhere)\n");
printf("Partial tree:\n");
prst(program, 0);
return 1;
}
prst(program, 0);
return 0;
}
}*/

188
builtins.c

@ -1,19 +1,21 @@
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include "sol.h"
// This is supposedly a C99 trick.
// XXX hardcoded buffer sizes
static char *_itoa(int i) {
int n = sprintf(NULL, "%d", i) + 1;
char *s = malloc(n)
int n = 33;
char *s = malloc(n);
snprintf(s, n, "%d", i);
return s;
}
static char *_ftoa(double f) {
int n = sprintf(NULL, "%f", f) + 1;
char *s = malloc(n)
int n = 65;
char *s = malloc(n);
snprintf(s, n, "%f", f);
return s;
}
@ -22,8 +24,17 @@ sol_object_t *sol_f_not_impl(sol_state_t *state, sol_object_t *args) {
return sol_set_error_string(state, "Undefined method");
}
sol_object_t *sol_f_no_op(sol_state_t *state, sol_object *args) {
return sol_incref(state->None);
sol_object_t *sol_f_default_cmp(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1);
sol_object_t *res = sol_new_int(state, a!=b);
sol_obj_free(a);
sol_obj_free(b);
return res;
}
sol_object_t *sol_f_no_op(sol_state_t *state, sol_object_t *args) {
if(state) return sol_incref(state->None);
return NULL;
}
sol_object_t *sol_f_toint(sol_state_t *state, sol_object_t *args) {
@ -48,7 +59,7 @@ sol_object_t *sol_f_tostring(sol_state_t *state, sol_object_t *args) {
}
sol_object_t *sol_f_try(sol_state_t *state, sol_object_t *args) {
sol_object_t *func = sol_list_get_index(state, args, 0), fargs = sol_list_sublist(state, args, 1);
sol_object_t *func = sol_list_get_index(state, args, 0), *fargs = sol_list_sublist(state, args, 1);
sol_object_t *ls = sol_new_list(state), *one = sol_new_int(state, 1);
sol_object_t *res = func->ops->call(state, fargs);
sol_obj_free(func);
@ -56,22 +67,103 @@ sol_object_t *sol_f_try(sol_state_t *state, sol_object_t *args) {
if(sol_has_error(state)) {
sol_object_t *err = sol_get_error(state);
sol_object_t *zero = sol_new_int(state, 0);
sol_object_free(res);
sol_object_free(one);
sol_obj_free(res);
sol_obj_free(one);
sol_clear_error(state);
sol_list_insert(state, ls, 0, err);
sol_list_insert(state, &ls, 0, err);
sol_obj_free(err);
sol_list_insert(state, ls, 0, zero);
sol_list_insert(state, &ls, 0, zero);
sol_obj_free(zero);
return ls;
}
sol_list_insert(state, ls, 0, res);
sol_list_insert(state, &ls, 0, res);
sol_obj_free(res);
sol_list_insert(state, ls, 0, one);
sol_list_insert(state, &ls, 0, one);
sol_obj_free(one);
return ls;
}
static char *sol_TypeNames[] = {"singlet", "integer", "float", "string", "list", "map", "function", "cfunction", "cdata"};
sol_object_t *sol_f_type(sol_state_t *state, sol_object_t *args) {
sol_object_t *obj = sol_list_get_index(state, args, 0);
sol_object_t *res = sol_new_string(state, sol_TypeNames[obj->type]);
sol_obj_free(obj);
return res;
}
void ob_print(sol_object_t *obj) {
sol_object_t *cur;
switch(obj->type) {
case SOL_SINGLET:
printf("<Singlet>");
break;
case SOL_INTEGER:
printf("%ld", obj->ival);
break;
case SOL_FLOAT:
printf("%f", obj->fval);
break;
case SOL_STRING:
printf("\"%s\"", obj->str);
break;
case SOL_LIST:
printf("[");
cur = obj;
while(cur) {
if(cur->lvalue) {
ob_print(cur->lvalue);
}
if(cur->lnext) {
printf(", ");
}
cur = cur->lnext;
}
printf("]");
break;
case SOL_MAP:
printf("{");
cur = obj;
while(cur) {
if(cur->mkey) {
printf("[");
ob_print(cur->mkey);
printf("] = ");
ob_print(cur->mval);
}
if(cur->mnext) printf(", ");
cur = cur->mnext;
}
printf("}");
break;
case SOL_FUNCTION:
printf("<Function>");
break;
case SOL_CFUNCTION:
printf("<CFunction>");
break;
case SOL_CDATA:
printf("<CData>");
break;
}
}
sol_object_t *sol_f_prepr(sol_state_t *state, sol_object_t *args) {
sol_object_t *obj = sol_list_get_index(state, args, 0);
ob_print(obj);
printf("\n");
sol_obj_free(obj);
return sol_incref(state->None);
}
sol_object_t *sol_f_int_add(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_int(state, a->ival + b->ival);
@ -108,6 +200,15 @@ sol_object_t *sol_f_int_div(sol_state_t *state, sol_object_t *args) {
return res;
}
sol_object_t *sol_f_int_pow(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_int(state, (long) pow((double) a->ival, b->ival));
sol_obj_free(a);
sol_obj_free(b);
if(sol_has_error(state)) {sol_obj_free(res); return sol_incref(state->None);}
return res;
}
sol_object_t *sol_f_int_band(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_int(state, a->ival & b->ival);
@ -118,7 +219,7 @@ sol_object_t *sol_f_int_band(sol_state_t *state, sol_object_t *args) {
}
sol_object_t *sol_f_int_bor(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1)));
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_int(state, a->ival | b->ival);
sol_obj_free(a);
sol_obj_free(b);
@ -142,6 +243,14 @@ sol_object_t *sol_f_int_bnot(sol_state_t *state, sol_object_t *args) {
return res;
}
sol_object_t *sol_f_int_cmp(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_int(state, a->ival==b->ival? 0 : (a->ival<b->ival? -1 : 1));
sol_obj_free(a);
sol_obj_free(b);
return res;
}
sol_object_t *sol_f_int_toint(sol_state_t *state, sol_object_t *args) {
return sol_list_get_index(state, args, 0);
}
@ -181,7 +290,7 @@ sol_object_t *sol_f_float_sub(sol_state_t *state, sol_object_t *args) {
}
sol_object_t *sol_f_float_mul(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1)));
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_float(state, a->fval * b->fval);
sol_obj_free(a);
sol_obj_free(b);
@ -198,6 +307,23 @@ sol_object_t *sol_f_float_div(sol_state_t *state, sol_object_t *args) {
return res;
}
sol_object_t *sol_f_float_pow(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_float(state, pow(a->fval, b->fval));
sol_obj_free(a);
sol_obj_free(b);
if(sol_has_error(state)) {sol_obj_free(res); return sol_incref(state->None);}
return res;
}
sol_object_t *sol_f_float_cmp(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_float(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_int(state, a->fval==b->fval? 0 : (a->fval<b->fval? -1 : 1));
sol_obj_free(a);
sol_obj_free(b);
return res;
}
sol_object_t *sol_f_float_toint(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0);
sol_object_t *res = sol_new_int(state, (int) a->fval);
@ -206,7 +332,7 @@ sol_object_t *sol_f_float_toint(sol_state_t *state, sol_object_t *args) {
}
sol_object_t *sol_f_float_tofloat(sol_state_t *state, sol_object_t *args) {
return sol_list_get_index(state, args, 0)
return sol_list_get_index(state, args, 0);
}
sol_object_t *sol_f_float_tostring(sol_state_t *state, sol_object_t *args) {
@ -219,10 +345,10 @@ sol_object_t *sol_f_float_tostring(sol_state_t *state, sol_object_t *args) {
}
sol_object_t *sol_f_str_add(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_string(state, sol_list_get_index(state, args, 1)));
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_string(state, sol_list_get_index(state, args, 1));
int n = strlen(a->str) + strlen(b->str) + 1;
char *s = malloc(n);
sol_object_t *res = sol_new_string(state, strncat(strncpy(s, n, a->str), n, b->str));
sol_object_t *res = sol_new_string(state, strncat(strncpy(s, a->str, n), b->str, n));
sol_obj_free(a);
sol_obj_free(b);
free(s);
@ -236,7 +362,7 @@ sol_object_t *sol_f_str_mul(sol_state_t *state, sol_object_t *args) {
char *s = malloc(n);
int i;
s[0]='\0';
for(i = 0; i < b->ival; i++) strncat(s, n, a->str);
for(i = 0; i < b->ival; i++) strncat(s, a->str, n);
sol_object_t *res = sol_new_string(state, s);
sol_obj_free(a);
sol_obj_free(b);
@ -245,29 +371,37 @@ sol_object_t *sol_f_str_mul(sol_state_t *state, sol_object_t *args) {
return res;
}
sol_object_t *sol_f_str_cmp(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0), *b = sol_cast_string(state, sol_list_get_index(state, args, 1));
sol_object_t *res = sol_new_int(state, strcmp(a->str, b->str));
sol_obj_free(a);
sol_obj_free(b);
return res;
}
sol_object_t *sol_f_str_len(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0);
sol_object_t *ret = sol_new_int(state, strlen(a->str));
sol_object_t *res = sol_new_int(state, strlen(a->str));
sol_obj_free(a);
return res;
}
sol_object_t *sol_f_str_toint(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0);
sol_object_t *ret = sol_new_int(state, atoi(a->str));
sol_object_t *res = sol_new_int(state, atoi(a->str));
sol_obj_free(a);
return res;
}
sol_object_t *sol_f_str_tofloat(sol_state_t *state, sol_object_t *args) {
sol_object_t *a = sol_list_get_index(state, args, 0);
sol_object_t *ret = sol_new_float(state, atof(a->str));
sol_object_t *res = sol_new_float(state, atof(a->str));
sol_obj_free(a);
return res;
}
sol_object_t *sol_f_str_tostring(sol_state_t *state, sol_object_t *args) {
return sol_list_get_index(state, args, 0)
return sol_list_get_index(state, args, 0);
}
sol_object_t *sol_f_list_add(sol_state_t *state, sol_object_t *args) {
@ -314,7 +448,7 @@ sol_object_t *sol_f_list_index(sol_state_t *state, sol_object_t *args) {
sol_object_t *sol_f_list_setindex(sol_state_t *state, sol_object_t *args) {
sol_object_t *ls = sol_list_get_index(state, args, 0), *b = sol_cast_int(state, sol_list_get_index(state, args ,1));
sol_objcet_t *val = sol_list_get_index(state, args, 2);
sol_object_t *val = sol_list_get_index(state, args, 2);
sol_list_set_index(state, ls, b->ival, val);
sol_obj_free(ls);
sol_obj_free(b);
@ -349,7 +483,7 @@ sol_object_t *sol_f_map_add(sol_state_t *state, sol_object_t *args) {
sol_object_t *sol_f_map_index(sol_state_t *state, sol_object_t *args) {
sol_object_t *map = sol_list_get_index(state, args, 0), *b = sol_list_get_index(state, args, 1);
sel_object_t *res = sol_map_get(state, map, b);
sol_object_t *res = sol_map_get(state, map, b);
sol_obj_free(map);
sol_obj_free(b);
return res;
@ -366,7 +500,7 @@ sol_object_t *sol_f_map_setindex(sol_state_t *state, sol_object_t *args) {
}
sol_object_t *sol_f_map_len(sol_state_t *state, sol_object_t *args) {
sol_object_t *map = sol_list_get_index(sate, args, 0);
sol_object_t *map = sol_list_get_index(state, args, 0);
sol_object_t *res = sol_new_int(state, sol_map_len(state, map));
sol_obj_free(map);
return res;

344
lex.yy.c

@ -8,7 +8,7 @@
#define FLEX_SCANNER
#define YY_FLEX_MAJOR_VERSION 2
#define YY_FLEX_MINOR_VERSION 5
#define YY_FLEX_SUBMINOR_VERSION 35
#define YY_FLEX_SUBMINOR_VERSION 39
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
@ -161,7 +161,12 @@ typedef unsigned int flex_uint32_t;
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
extern int yyleng;
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
extern yy_size_t yyleng;
extern FILE *yyin, *yyout;
@ -170,6 +175,7 @@ extern FILE *yyin, *yyout;
#define EOB_ACT_LAST_MATCH 2
#define YY_LESS_LINENO(n)
#define YY_LINENO_REWIND_TO(ptr)
/* Return all but the first "n" matched characters back to the input stream. */
#define yyless(n) \
@ -187,11 +193,6 @@ extern FILE *yyin, *yyout;
#define unput(c) yyunput( c, (yytext_ptr) )
#ifndef YY_TYPEDEF_YY_SIZE_T
#define YY_TYPEDEF_YY_SIZE_T
typedef size_t yy_size_t;
#endif
#ifndef YY_STRUCT_YY_BUFFER_STATE
#define YY_STRUCT_YY_BUFFER_STATE
struct yy_buffer_state
@ -209,7 +210,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
int yy_n_chars;
yy_size_t yy_n_chars;
/* Whether we "own" the buffer - i.e., we know we created it,
* and can realloc() it to grow it, and should free() it to
@ -279,8 +280,8 @@ static YY_BUFFER_STATE * yy_buffer_stack = 0; /**< Stack as an array. */
/* yy_hold_char holds the character lost when yytext is formed. */
static char yy_hold_char;
static int yy_n_chars; /* number of characters read into yy_ch_buf */
int yyleng;
static yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
yy_size_t yyleng;
/* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0;
@ -308,7 +309,7 @@ static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file );
YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size );
YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str );
YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len );
YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,yy_size_t len );
void *yyalloc (yy_size_t );
void *yyrealloc (void *,yy_size_t );
@ -368,8 +369,8 @@ static void yy_fatal_error (yyconst char msg[] );
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 52
#define YY_END_OF_BUFFER 53
#define YY_NUM_RULES 55
#define YY_END_OF_BUFFER 56
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@ -377,17 +378,19 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[82] =
static yyconst flex_int16_t yy_accept[101] =
{ 0,
0, 0, 53, 52, 51, 24, 52, 52, 18, 43,
44, 15, 13, 48, 14, 45, 16, 2, 46, 47,
35, 25, 36, 49, 41, 42, 20, 49, 49, 49,
49, 49, 49, 39, 19, 40, 21, 51, 0, 3,
0, 50, 22, 31, 17, 28, 26, 27, 29, 1,
2, 37, 34, 38, 49, 33, 10, 49, 49, 49,
49, 4, 9, 49, 49, 32, 23, 30, 1, 49,
12, 8, 49, 49, 49, 6, 11, 5, 49, 7,
0
0, 0, 56, 55, 54, 27, 55, 55, 21, 46,
47, 18, 16, 51, 17, 48, 19, 2, 49, 50,
38, 28, 39, 52, 44, 45, 23, 52, 52, 52,
52, 52, 52, 52, 52, 52, 42, 22, 43, 24,
54, 0, 3, 0, 53, 25, 34, 20, 31, 29,
30, 32, 1, 2, 40, 37, 41, 52, 36, 52,
52, 10, 52, 52, 52, 52, 4, 9, 52, 52,
52, 35, 26, 33, 1, 52, 52, 52, 15, 8,
52, 52, 52, 52, 52, 52, 6, 11, 52, 5,
52, 13, 52, 52, 7, 52, 12, 52, 14, 0
} ;
static yyconst flex_int32_t yy_ec[256] =
@ -401,11 +404,11 @@ static yyconst flex_int32_t yy_ec[256] =
20, 21, 1, 1, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
23, 1, 24, 25, 22, 1, 22, 22, 26, 27,
23, 1, 24, 25, 22, 1, 26, 27, 28, 29,
28, 29, 22, 30, 31, 22, 22, 32, 22, 33,
34, 22, 22, 35, 36, 37, 38, 22, 39, 22,
22, 22, 40, 41, 42, 43, 1, 1, 1, 1,
30, 31, 22, 32, 33, 22, 34, 35, 22, 36,
37, 22, 22, 38, 39, 40, 41, 22, 42, 22,
22, 22, 43, 44, 45, 46, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
@ -422,79 +425,89 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst flex_int32_t yy_meta[44] =
static yyconst flex_int32_t yy_meta[47] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 2, 1, 1, 1, 1,
1, 2, 1, 1, 1, 2, 2, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 1,
1, 1, 1
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 1, 1, 1, 1
} ;
static yyconst flex_int16_t yy_base[85] =
static yyconst flex_int16_t yy_base[104] =
{ 0,
0, 0, 97, 98, 42, 98, 91, 92, 39, 98,
98, 37, 74, 98, 73, 98, 72, 34, 98, 98,
71, 70, 69, 0, 98, 98, 68, 53, 19, 15,
25, 56, 55, 98, 35, 98, 98, 58, 79, 98,
80, 98, 98, 98, 62, 98, 98, 98, 98, 65,
48, 98, 98, 98, 0, 98, 0, 39, 47, 38,
39, 0, 0, 43, 39, 98, 98, 98, 53, 40,
0, 0, 41, 33, 33, 0, 0, 0, 35, 0,
98, 76, 78, 54
0, 0, 116, 117, 45, 117, 110, 111, 42, 117,
117, 40, 93, 117, 92, 117, 91, 37, 117, 117,
90, 89, 88, 0, 117, 117, 87, 68, 68, 67,
19, 15, 27, 73, 70, 69, 117, 37, 117, 117,
62, 95, 117, 96, 117, 117, 117, 78, 117, 117,
117, 117, 81, 45, 117, 117, 117, 0, 117, 66,
59, 0, 55, 64, 54, 55, 0, 0, 50, 59,
55, 117, 117, 117, 71, 60, 40, 49, 0, 0,
50, 36, 40, 40, 40, 40, 0, 0, 34, 0,
41, 0, 34, 33, 0, 27, 0, 37, 0, 117,
81, 83, 64
} ;
static yyconst flex_int16_t yy_def[85] =
static yyconst flex_int16_t yy_def[104] =
{ 0,
81, 1, 81, 81, 81, 81, 82, 83, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 84, 81, 81, 81, 84, 84, 84,
84, 84, 84, 81, 81, 81, 81, 81, 82, 81,
83, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 84, 81, 84, 84, 84, 84,
84, 84, 84, 84, 84, 81, 81, 81, 81, 84,
84, 84, 84, 84, 84, 84, 84, 84, 84, 84,
0, 81, 81, 81
100, 1, 100, 100, 100, 100, 101, 102, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 103, 100, 100, 100, 103, 103, 103,
103, 103, 103, 103, 103, 103, 100, 100, 100, 100,
100, 101, 100, 102, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 103, 100, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
103, 100, 100, 100, 100, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 103,
103, 103, 103, 103, 103, 103, 103, 103, 103, 0,
100, 100, 100
} ;
static yyconst flex_int16_t yy_nxt[142] =
static yyconst flex_int16_t yy_nxt[164] =
{ 0,
4, 5, 5, 6, 7, 8, 9, 10, 11, 12,
13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
23, 24, 25, 26, 27, 24, 28, 29, 30, 24,
31, 24, 24, 24, 24, 24, 32, 24, 33, 34,
35, 36, 37, 38, 38, 43, 45, 50, 60, 51,
58, 59, 61, 62, 66, 55, 46, 63, 44, 38,
38, 50, 80, 51, 79, 78, 77, 76, 69, 75,
74, 73, 72, 71, 70, 67, 39, 39, 41, 41,
69, 68, 42, 40, 65, 64, 57, 56, 54, 53,
52, 49, 48, 47, 42, 40, 81, 3, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81
23, 24, 25, 26, 27, 24, 28, 29, 30, 31,
32, 24, 33, 24, 24, 24, 24, 34, 24, 35,
24, 36, 37, 38, 39, 40, 41, 41, 46, 48,
53, 65, 54, 63, 64, 66, 72, 67, 53, 49,
54, 47, 68, 41, 41, 58, 99, 98, 97, 96,
95, 94, 93, 92, 91, 90, 89, 88, 87, 86,
73, 42, 42, 44, 44, 85, 75, 84, 83, 82,
81, 80, 79, 78, 77, 76, 75, 74, 45, 43,
71, 70, 69, 62, 61, 60, 59, 57, 56, 55,
52, 51, 50, 45, 43, 100, 3, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100
} ;
static yyconst flex_int16_t yy_chk[142] =
static yyconst flex_int16_t yy_chk[164] =
{ 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 5, 5, 9, 12, 18, 30, 18,
29, 29, 30, 31, 35, 84, 12, 31, 9, 38,
38, 51, 79, 51, 75, 74, 73, 70, 69, 65,
64, 61, 60, 59, 58, 35, 82, 82, 83, 83,
50, 45, 41, 39, 33, 32, 28, 27, 23, 22,
21, 17, 15, 13, 8, 7, 3, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81, 81, 81, 81, 81, 81, 81, 81, 81, 81,
81
1, 1, 1, 1, 1, 1, 5, 5, 9, 12,
18, 32, 18, 31, 31, 32, 38, 33, 54, 12,
54, 9, 33, 41, 41, 103, 98, 96, 94, 93,
91, 89, 86, 85, 84, 83, 82, 81, 78, 77,
38, 101, 101, 102, 102, 76, 75, 71, 70, 69,
66, 65, 64, 63, 61, 60, 53, 48, 44, 42,
36, 35, 34, 30, 29, 28, 27, 23, 22, 21,
17, 15, 13, 8, 7, 3, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
100, 100, 100
} ;
static yy_state_type yy_last_accepting_state;
@ -560,7 +573,7 @@ void str_putc(char c) {
<STRING>. { str_putc(*yytext); }
*/
#line 564 "lex.yy.c"
#line 577 "lex.yy.c"
#define INITIAL 0
@ -599,7 +612,7 @@ FILE *yyget_out (void );
void yyset_out (FILE * out_str );
int yyget_leng (void );
yy_size_t yyget_leng (void );
char *yyget_text (void );
@ -747,11 +760,6 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
#line 57 "tokenizer.lex"
#line 754 "lex.yy.c"
if ( !(yy_init) )
{
(yy_init) = 1;
@ -778,6 +786,12 @@ YY_DECL
yy_load_buffer_state( );
}
{
#line 57 "tokenizer.lex"
#line 794 "lex.yy.c"
while ( 1 ) /* loops until end-of-file is reached */
{
yy_cp = (yy_c_buf_p);
@ -794,7 +808,7 @@ YY_DECL
yy_match:
do
{
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)];
register YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ;
if ( yy_accept[yy_current_state] )
{
(yy_last_accepting_state) = yy_current_state;
@ -803,13 +817,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 82 )
if ( yy_current_state >= 101 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp;
}
while ( yy_base[yy_current_state] != 98 );
while ( yy_base[yy_current_state] != 117 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@ -892,211 +906,226 @@ YY_RULE_SETUP
case 12:
YY_RULE_SETUP
#line 81 "tokenizer.lex"
{ return END; }
{ return RETURN; }
YY_BREAK
case 13:
YY_RULE_SETUP
#line 83 "tokenizer.lex"
{ return PLUS; }
{ return BREAK; }
YY_BREAK
case 14:
YY_RULE_SETUP
#line 85 "tokenizer.lex"
{ return MINUS; }
{ return CONTINUE; }
YY_BREAK
case 15:
YY_RULE_SETUP
#line 87 "tokenizer.lex"
{ return STAR; }
{ return END; }
YY_BREAK
case 16:
YY_RULE_SETUP
#line 89 "tokenizer.lex"
{ return SLASH; }
{ return PLUS; }
YY_BREAK
case 17:
YY_RULE_SETUP
#line 91 "tokenizer.lex"
{ return DSTAR; }
{ return MINUS; }
YY_BREAK
case 18:
YY_RULE_SETUP
#line 93 "tokenizer.lex"
{ return BAND; }
{ return STAR; }
YY_BREAK
case 19:
YY_RULE_SETUP
#line 95 "tokenizer.lex"
{ return BOR; }
{ return SLASH; }
YY_BREAK
case 20:
YY_RULE_SETUP
#line 97 "tokenizer.lex"
{ return BXOR; }
{ return DSTAR; }
YY_BREAK
case 21:
YY_RULE_SETUP
#line 99 "tokenizer.lex"
{ return BNOT; }
{ return BAND; }
YY_BREAK
case 22:
YY_RULE_SETUP
#line 101 "tokenizer.lex"
{ return LAND; }
{ return BOR; }
YY_BREAK
case 23:
YY_RULE_SETUP
#line 103 "tokenizer.lex"
{ return LOR; }
{ return BXOR; }
YY_BREAK
case 24:
YY_RULE_SETUP
#line 105 "tokenizer.lex"
{ return LNOT; }
{ return BNOT; }
YY_BREAK
case 25:
YY_RULE_SETUP
#line 107 "tokenizer.lex"
{ return ASSIGN; }
{ return LAND; }
YY_BREAK
case 26:
YY_RULE_SETUP
#line 109 "tokenizer.lex"
{ return ASSIGNPLUS; }
{ return LOR; }
YY_BREAK
case 27:
YY_RULE_SETUP
#line 111 "tokenizer.lex"
{ return ASSIGNMINUS; }
{ return LNOT; }
YY_BREAK
case 28:
YY_RULE_SETUP
#line 113 "tokenizer.lex"
{ return ASSIGNSTAR; }
{ return ASSIGN; }
YY_BREAK
case 29:
YY_RULE_SETUP
#line 115 "tokenizer.lex"
{ return ASSIGNSLASH; }
{ return ASSIGNPLUS; }
YY_BREAK
case 30:
YY_RULE_SETUP
#line 117 "tokenizer.lex"
{ return ASSIGNDSTAR; }
{ return ASSIGNMINUS; }
YY_BREAK
case 31:
YY_RULE_SETUP
#line 119 "tokenizer.lex"
{ return ASSIGNBAND; }
{ return ASSIGNSTAR; }
YY_BREAK
case 32:
YY_RULE_SETUP
#line 121 "tokenizer.lex"
{ return ASSIGNBOR; }
{ return ASSIGNSLASH; }
YY_BREAK
case 33:
YY_RULE_SETUP
#line 123 "tokenizer.lex"
{ return ASSIGNBXOR; }
{ return ASSIGNDSTAR; }
YY_BREAK
case 34:
YY_RULE_SETUP
#line 125 "tokenizer.lex"
{ return EQUAL; }
{ return ASSIGNBAND; }
YY_BREAK
case 35:
YY_RULE_SETUP
#line 127 "tokenizer.lex"
{ return LESS; }
{ return ASSIGNBOR; }
YY_BREAK
case 36:
YY_RULE_SETUP
#line 129 "tokenizer.lex"
{ return GREATER; }
{ return ASSIGNBXOR; }
YY_BREAK
case 37:
YY_RULE_SETUP
#line 131 "tokenizer.lex"
{ return LESSEQ; }
{ return EQUAL; }
YY_BREAK
case 38:
YY_RULE_SETUP
#line 133 "tokenizer.lex"
{ return GREATEREQ; }
{ return LESS; }
YY_BREAK
case 39:
YY_RULE_SETUP
#line 135 "tokenizer.lex"
{ return LBRACE; }
{ return GREATER; }
YY_BREAK
case 40:
YY_RULE_SETUP
#line 137 "tokenizer.lex"
{ return RBRACE; }
{ return LESSEQ; }
YY_BREAK
case 41:
YY_RULE_SETUP
#line 139 "tokenizer.lex"
{ return LBRACKET; }
{ return GREATEREQ; }
YY_BREAK
case 42:
YY_RULE_SETUP
#line 141 "tokenizer.lex"
{ return RBRACKET; }
{ return LBRACE; }
YY_BREAK
case 43:
YY_RULE_SETUP
#line 143 "tokenizer.lex"
{ return LPAREN; }
{ return RBRACE; }
YY_BREAK
case 44:
YY_RULE_SETUP
#line 145 "tokenizer.lex"
{ return RPAREN; }
{ return LBRACKET; }
YY_BREAK
case 45:
YY_RULE_SETUP
#line 147 "tokenizer.lex"
{ return DOT; }
{ return RBRACKET; }
YY_BREAK
case 46:
YY_RULE_SETUP
#line 149 "tokenizer.lex"
{ return COLON; }
{ return LPAREN; }
YY_BREAK
case 47:
YY_RULE_SETUP
#line 151 "tokenizer.lex"
{ return SEMICOLON; }
{ return RPAREN; }
YY_BREAK
case 48:
YY_RULE_SETUP
#line 153 "tokenizer.lex"
{ return COMMA; }
{ return DOT; }
YY_BREAK
case 49:
YY_RULE_SETUP
#line 155 "tokenizer.lex"
{ yylval = strdup(yytext); return IDENT; }
{ return COLON; }
YY_BREAK
case 50:
/* rule 50 can match eol */
YY_RULE_SETUP
#line 157 "tokenizer.lex"
/* Skip comments */
{ return SEMICOLON; }
YY_BREAK
case 51:
/* rule 51 can match eol */
YY_RULE_SETUP
#line 159 "tokenizer.lex"
/* Skip whitespace */
{ return COMMA; }
YY_BREAK
case 52:
YY_RULE_SETUP
#line 161 "tokenizer.lex"
{ yylval = strdup(yytext); return IDENT; }
YY_BREAK
case 53:
/* rule 53 can match eol */
YY_RULE_SETUP
#line 163 "tokenizer.lex"
/* Skip comments */
YY_BREAK
case 54:
/* rule 54 can match eol */
YY_RULE_SETUP
#line 165 "tokenizer.lex"
/* Skip whitespace */
YY_BREAK
case 55:
YY_RULE_SETUP
#line 167 "tokenizer.lex"
ECHO;
YY_BREAK
#line 1100 "lex.yy.c"
#line 1129 "lex.yy.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
@ -1227,6 +1256,7 @@ case YY_STATE_EOF(INITIAL):
"fatal flex scanner internal error--no action found" );
} /* end of action switch */
} /* end of scanning one token */
} /* end of user's declarations */
} /* end of yylex */
/* yy_get_next_buffer - try to read in a new buffer
@ -1282,21 +1312,21 @@ static int yy_get_next_buffer (void)
else
{
int num_to_read =
yy_size_t num_to_read =
YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1;
while ( num_to_read <= 0 )
{ /* Not enough room in the buffer - grow it. */
/* just a shorter name for the current buffer */
YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE;
int yy_c_buf_p_offset =
(int) ((yy_c_buf_p) - b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
int new_size = b->yy_buf_size * 2;
yy_size_t new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
@ -1327,7 +1357,7 @@ static int yy_get_next_buffer (void)
/* Read in more data. */
YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]),
(yy_n_chars), (size_t) num_to_read );
(yy_n_chars), num_to_read );
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
}
@ -1388,7 +1418,7 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 82 )
if ( yy_current_state >= 101 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1416,13 +1446,13 @@ static int yy_get_next_buffer (void)
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{
yy_current_state = (int) yy_def[yy_current_state];
if ( yy_current_state >= 82 )
if ( yy_current_state >= 101 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
yy_is_jam = (yy_current_state == 81);
yy_is_jam = (yy_current_state == 100);
return yy_is_jam ? 0 : yy_current_state;
return yy_is_jam ? 0 : yy_current_state;
}
static void yyunput (int c, register char * yy_bp )
@ -1437,7 +1467,7 @@ static int yy_get_next_buffer (void)
if ( yy_cp < YY_CURRENT_BUFFER_LVALUE-