Browse Source

Sol Part 4: This Time with Passion!

master
Graham Northup 7 years ago
parent
commit
e3beb9139b
  1. 7
      ast.h
  2. 8
      astprint.c
  3. 6
      builtins.c
  4. 7
      dsdebug.gdb
  5. 1
      dummypow.c
  6. 382
      lex.yy.c
  7. 137
      object.c
  8. 9165
      parser.output
  9. 2052
      parser.tab.c
  10. 147
      parser.tab.h
  11. 22
      parser.y
  12. 42
      runtime.c
  13. 8
      sol.h
  14. 8
      solrun.c
  15. 8
      state.c
  16. 8
      tokenizer.lex

7
ast.h

@ -11,7 +11,7 @@ typedef struct tag_expr_node expr_node;
struct tag_stmt_node;
typedef struct tag_stmt_node stmt_node;
typedef enum {LIT_INT, LIT_FLOAT, LIT_STRING} lit_t;
typedef enum {LIT_INT, LIT_FLOAT, LIT_STRING, LIT_NONE} lit_t;
typedef struct {
lit_t type;
union {
@ -28,7 +28,7 @@ typedef struct {
expr_node *right;
} binop_node;
typedef enum {OP_NEG, OP_BNOT, OP_LNOT} unop_t;
typedef enum {OP_NEG, OP_BNOT, OP_LNOT, OP_LEN} unop_t;
typedef struct {
unop_t type;
expr_node *expr;
@ -177,7 +177,7 @@ typedef struct tag_stmt_node {
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 *);
sol_object_t *sol_new_func(sol_state_t *, identlist_node *, stmt_node *, char *);
// runtime.c
@ -191,6 +191,7 @@ void ex_free(expr_node *);
void st_print(stmt_node *);
void ex_print(expr_node *);
void ob_print(sol_object_t *);
sol_object_t *sol_eval(sol_state_t *, expr_node *);
void sol_exec(sol_state_t *, stmt_node *);

8
astprint.c

@ -106,6 +106,10 @@ void prex(expr_node *node, int lev) {
case LIT_STRING:
prlev(lev, "String: %s", node->lit->str);
break;
case LIT_NONE:
prlev(lev, "None");
break;
}
break;
@ -216,6 +220,10 @@ void prex(expr_node *node, int lev) {
case OP_LNOT:
prlev(lev, "Op: !");
break;
case OP_LEN:
prlev(lev, "Op: #");
break;
}
prlev(lev, "Expr:");
prex(node->unop->expr, lev+1);

6
builtins.c

@ -143,7 +143,11 @@ void ob_print(sol_object_t *obj) {
break;
case SOL_FUNCTION:
printf("<Function>");
if(obj->fname) {
printf("<Function %s>", obj->fname);
} else {
printf("<Function>");
}
break;
case SOL_CFUNCTION:

7
dsdebug.gdb

@ -0,0 +1,7 @@
break object.c:265
condition $bpnum sol_validate_list(state, *list)
break object.c:294
condition $bpnum sol_validate_list(state, *list)
break object.c:183
condition $bpnum sol_validate_list(state, list)
watch state->error

1
dummypow.c

@ -0,0 +1 @@
double pow(double a, double b) { return 0.0; }

382
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 39
#define YY_FLEX_SUBMINOR_VERSION 35
#if YY_FLEX_SUBMINOR_VERSION > 0
#define FLEX_BETA
#endif
@ -161,12 +161,7 @@ typedef unsigned int flex_uint32_t;
typedef struct yy_buffer_state *YY_BUFFER_STATE;
#endif
#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 int yyleng;
extern FILE *yyin, *yyout;
@ -175,7 +170,6 @@ 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) \
@ -193,6 +187,11 @@ 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
@ -210,7 +209,7 @@ struct yy_buffer_state
/* Number of characters read into yy_ch_buf, not including EOB
* characters.
*/
yy_size_t yy_n_chars;
int 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
@ -280,8 +279,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 yy_size_t yy_n_chars; /* number of characters read into yy_ch_buf */
yy_size_t yyleng;
static int yy_n_chars; /* number of characters read into yy_ch_buf */
int yyleng;
/* Points to current character in buffer. */
static char *yy_c_buf_p = (char *) 0;
@ -309,7 +308,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,yy_size_t len );
YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len );
void *yyalloc (yy_size_t );
void *yyrealloc (void *,yy_size_t );
@ -369,8 +368,8 @@ static void yy_fatal_error (yyconst char msg[] );
*yy_cp = '\0'; \
(yy_c_buf_p) = yy_cp;
#define YY_NUM_RULES 55
#define YY_END_OF_BUFFER 56
#define YY_NUM_RULES 58
#define YY_END_OF_BUFFER 59
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
@ -378,19 +377,20 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[101] =
static yyconst flex_int16_t yy_accept[109] =
{ 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
0, 0, 59, 58, 57, 29, 58, 54, 23, 58,
48, 49, 20, 18, 53, 19, 50, 21, 2, 51,
52, 40, 30, 41, 55, 55, 46, 47, 25, 55,
55, 55, 55, 55, 55, 55, 55, 55, 44, 24,
45, 26, 57, 0, 3, 27, 36, 0, 4, 22,
33, 31, 0, 32, 34, 1, 2, 42, 39, 43,
55, 55, 38, 55, 55, 11, 55, 55, 55, 55,
5, 10, 55, 55, 55, 37, 28, 35, 0, 56,
1, 55, 55, 55, 55, 16, 9, 55, 55, 55,
55, 17, 55, 55, 7, 12, 55, 6, 55, 14,
55, 55, 8, 55, 13, 55, 15, 0
} ;
static yyconst flex_int32_t yy_ec[256] =
@ -398,17 +398,17 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1, 1, 1, 1, 2, 3,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 2, 4, 5, 6, 1, 1, 7, 1, 8,
9, 10, 11, 12, 13, 14, 15, 16, 16, 16,
16, 16, 16, 16, 16, 16, 16, 17, 18, 19,
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, 26, 27, 28, 29,
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, 2, 4, 5, 6, 1, 1, 7, 8, 9,
10, 11, 12, 13, 14, 15, 16, 17, 17, 17,
17, 17, 17, 17, 17, 17, 17, 18, 19, 20,
21, 22, 1, 1, 23, 23, 23, 23, 23, 23,
23, 23, 23, 23, 23, 23, 23, 24, 23, 23,
23, 23, 23, 23, 23, 23, 23, 23, 23, 23,
25, 1, 26, 27, 23, 1, 28, 29, 30, 31,
32, 33, 23, 34, 35, 23, 36, 37, 23, 38,
39, 23, 23, 40, 41, 42, 43, 23, 44, 23,
23, 23, 45, 46, 47, 48, 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,
@ -425,89 +425,93 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst flex_int32_t yy_meta[47] =
static yyconst flex_int32_t yy_meta[49] =
{ 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,
1, 1, 1, 1, 1, 1, 2, 1, 1, 1,
1, 1, 2, 2, 1, 1, 1, 2, 2, 2,
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
2, 2, 1, 1, 1, 1
2, 2, 2, 2, 1, 1, 1, 1
} ;
static yyconst flex_int16_t yy_base[104] =
static yyconst flex_int16_t yy_base[113] =
{ 0,
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
0, 0, 126, 127, 47, 127, 120, 127, 44, 116,
127, 127, 41, 102, 127, 39, 127, 101, 39, 127,
127, 100, 99, 98, 0, 79, 127, 127, 96, 76,
76, 75, 20, 16, 28, 81, 78, 77, 127, 42,
127, 127, 65, 105, 127, 127, 127, 101, 127, 87,
127, 127, 104, 127, 127, 89, 54, 127, 127, 127,
0, 67, 127, 72, 65, 0, 61, 70, 60, 61,
0, 0, 56, 65, 61, 127, 127, 127, 92, 127,
70, 54, 57, 42, 51, 0, 0, 52, 38, 42,
42, 0, 42, 42, 0, 0, 36, 0, 43, 0,
36, 35, 0, 29, 0, 38, 0, 127, 88, 90,
62, 92
} ;
static yyconst flex_int16_t yy_def[104] =
static yyconst flex_int16_t yy_def[113] =
{ 0,
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
108, 1, 108, 108, 108, 108, 109, 108, 108, 110,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 111, 111, 108, 108, 108, 111,
111, 111, 111, 111, 111, 111, 111, 111, 108, 108,
108, 108, 108, 109, 108, 108, 108, 110, 108, 108,
108, 108, 112, 108, 108, 108, 108, 108, 108, 108,
111, 111, 108, 111, 111, 111, 111, 111, 111, 111,
111, 111, 111, 111, 111, 108, 108, 108, 112, 108,
108, 111, 111, 111, 111, 111, 111, 111, 111, 111,
111, 111, 111, 111, 111, 111, 111, 111, 111, 111,
111, 111, 111, 111, 111, 111, 111, 0, 108, 108,
108, 108
} ;
static yyconst flex_int16_t yy_nxt[164] =
static yyconst flex_int16_t yy_nxt[176] =
{ 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, 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
23, 24, 25, 26, 27, 28, 29, 25, 30, 31,
32, 33, 34, 25, 35, 25, 25, 25, 25, 36,
25, 37, 25, 38, 39, 40, 41, 42, 43, 43,
46, 50, 53, 56, 69, 57, 67, 68, 70, 54,
71, 51, 76, 61, 47, 72, 43, 43, 56, 107,
57, 106, 105, 104, 103, 102, 101, 100, 99, 98,
97, 96, 95, 94, 93, 92, 81, 77, 44, 44,
48, 48, 79, 79, 80, 91, 90, 89, 88, 87,
86, 85, 84, 83, 82, 81, 80, 78, 49, 45,
75, 74, 73, 66, 65, 64, 63, 62, 60, 59,
58, 55, 52, 49, 45, 108, 3, 108, 108, 108,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 108
} ;
static yyconst flex_int16_t yy_chk[164] =
static yyconst flex_int16_t yy_chk[176] =
{ 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, 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
1, 1, 1, 1, 1, 1, 1, 1, 5, 5,
9, 13, 16, 19, 34, 19, 33, 33, 34, 16,
35, 13, 40, 111, 9, 35, 43, 43, 57, 106,
57, 104, 102, 101, 99, 97, 94, 93, 91, 90,
89, 88, 85, 84, 83, 82, 81, 40, 109, 109,
110, 110, 112, 112, 79, 75, 74, 73, 70, 69,
68, 67, 65, 64, 62, 56, 53, 50, 48, 44,
38, 37, 36, 32, 31, 30, 29, 26, 24, 23,
22, 18, 14, 10, 7, 3, 108, 108, 108, 108,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 108, 108, 108, 108, 108, 108,
108, 108, 108, 108, 108
} ;
static yy_state_type yy_last_accepting_state;
@ -573,7 +577,7 @@ void str_putc(char c) {
<STRING>. { str_putc(*yytext); }
*/
#line 577 "lex.yy.c"
#line 581 "lex.yy.c"
#define INITIAL 0
@ -612,7 +616,7 @@ FILE *yyget_out (void );
void yyset_out (FILE * out_str );
yy_size_t yyget_leng (void );
int yyget_leng (void );
char *yyget_text (void );
@ -760,6 +764,11 @@ YY_DECL
register char *yy_cp, *yy_bp;
register int yy_act;
#line 57 "tokenizer.lex"
#line 771 "lex.yy.c"
if ( !(yy_init) )
{
(yy_init) = 1;
@ -786,12 +795,6 @@ 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);
@ -808,7 +811,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;
@ -817,13 +820,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 >= 101 )
if ( yy_current_state >= 109 )
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] != 117 );
while ( yy_base[yy_current_state] != 127 );
yy_find_action:
yy_act = yy_accept[yy_current_state];
@ -864,268 +867,284 @@ YY_RULE_SETUP
{ yylval = strdup(yytext+1); ((char *) yylval)[yyleng-2] = 0; return STRING; }
YY_BREAK
case 4:
/* rule 4 can match eol */
YY_RULE_SETUP
#line 65 "tokenizer.lex"
{ return IF; }
{ yylval = strdup(yytext+1); ((char *) yylval)[yyleng-2] = 0; return STRING; }
YY_BREAK
case 5:
YY_RULE_SETUP
#line 67 "tokenizer.lex"
{ return THEN; }
{ return IF; }
YY_BREAK
case 6:
YY_RULE_SETUP
#line 69 "tokenizer.lex"
{ return ELSE; }
{ return THEN; }
YY_BREAK
case 7:
YY_RULE_SETUP
#line 71 "tokenizer.lex"
{ return WHILE; }
{ return ELSE; }
YY_BREAK
case 8:
YY_RULE_SETUP
#line 73 "tokenizer.lex"
{ return FOR; }
{ return WHILE; }
YY_BREAK
case 9:
YY_RULE_SETUP
#line 75 "tokenizer.lex"
{ return IN; }
{ return FOR; }
YY_BREAK
case 10:
YY_RULE_SETUP
#line 77 "tokenizer.lex"
{ return DO; }
{ return IN; }
YY_BREAK
case 11:
YY_RULE_SETUP
#line 79 "tokenizer.lex"
{ return FUNC; }
{ return DO; }
YY_BREAK
case 12:
YY_RULE_SETUP
#line 81 "tokenizer.lex"
{ return RETURN; }
{ return FUNC; }
YY_BREAK
case 13:
YY_RULE_SETUP
#line 83 "tokenizer.lex"
{ return BREAK; }
{ return RETURN; }
YY_BREAK
case 14:
YY_RULE_SETUP
#line 85 "tokenizer.lex"
{ return CONTINUE; }
{ return BREAK; }
YY_BREAK
case 15:
YY_RULE_SETUP
#line 87 "tokenizer.lex"
{ return END; }
{ return CONTINUE; }
YY_BREAK
case 16:
YY_RULE_SETUP
#line 89 "tokenizer.lex"
{ return PLUS; }
{ return END; }
YY_BREAK
case 17:
YY_RULE_SETUP
#line 91 "tokenizer.lex"
{ return MINUS; }
{ return NONE; }
YY_BREAK
case 18:
YY_RULE_SETUP
#line 93 "tokenizer.lex"
{ return STAR; }
{ return PLUS; }
YY_BREAK
case 19:
YY_RULE_SETUP
#line 95 "tokenizer.lex"
{ return SLASH; }
{ return MINUS; }
YY_BREAK
case 20:
YY_RULE_SETUP
#line 97 "tokenizer.lex"
{ return DSTAR; }
{ return STAR; }
YY_BREAK
case 21:
YY_RULE_SETUP
#line 99 "tokenizer.lex"
{ return BAND; }
{ return SLASH; }
YY_BREAK
case 22:
YY_RULE_SETUP
#line 101 "tokenizer.lex"
{ return BOR; }
{ return DSTAR; }
YY_BREAK
case 23:
YY_RULE_SETUP
#line 103 "tokenizer.lex"
{ return BXOR; }
{ return BAND; }
YY_BREAK
case 24:
YY_RULE_SETUP
#line 105 "tokenizer.lex"
{ return BNOT; }
{ return BOR; }
YY_BREAK
case 25:
YY_RULE_SETUP
#line 107 "tokenizer.lex"
{ return LAND; }
{ return BXOR; }
YY_BREAK
case 26:
YY_RULE_SETUP
#line 109 "tokenizer.lex"
{ return LOR; }
{ return BNOT; }
YY_BREAK
case 27:
YY_RULE_SETUP
#line 111 "tokenizer.lex"
{ return LNOT; }
{ return LAND; }
YY_BREAK
case 28:
YY_RULE_SETUP
#line 113 "tokenizer.lex"
{ return ASSIGN; }
{ return LOR; }
YY_BREAK
case 29:
YY_RULE_SETUP
#line 115 "tokenizer.lex"
{ return ASSIGNPLUS; }
{ return LNOT; }
YY_BREAK
case 30:
YY_RULE_SETUP
#line 117 "tokenizer.lex"
{ return ASSIGNMINUS; }
{ return ASSIGN; }
YY_BREAK
case 31:
YY_RULE_SETUP
#line 119 "tokenizer.lex"
{ return ASSIGNSTAR; }
{ return ASSIGNPLUS; }
YY_BREAK
case 32:
YY_RULE_SETUP
#line 121 "tokenizer.lex"
{ return ASSIGNSLASH; }
{ return ASSIGNMINUS; }
YY_BREAK
case 33:
YY_RULE_SETUP
#line 123 "tokenizer.lex"
{ return ASSIGNDSTAR; }
{ return ASSIGNSTAR; }
YY_BREAK
case 34:
YY_RULE_SETUP
#line 125 "tokenizer.lex"
{ return ASSIGNBAND; }
{ return ASSIGNSLASH; }
YY_BREAK
case 35:
YY_RULE_SETUP
#line 127 "tokenizer.lex"
{ return ASSIGNBOR; }
{ return ASSIGNDSTAR; }
YY_BREAK
case 36:
YY_RULE_SETUP
#line 129 "tokenizer.lex"
{ return ASSIGNBXOR; }
{ return ASSIGNBAND; }
YY_BREAK
case 37:
YY_RULE_SETUP
#line 131 "tokenizer.lex"
{ return EQUAL; }
{ return ASSIGNBOR; }
YY_BREAK
case 38:
YY_RULE_SETUP
#line 133 "tokenizer.lex"
{ return LESS; }
{ return ASSIGNBXOR; }
YY_BREAK
case 39:
YY_RULE_SETUP
#line 135 "tokenizer.lex"
{ return GREATER; }
{ return EQUAL; }
YY_BREAK
case 40:
YY_RULE_SETUP
#line 137 "tokenizer.lex"
{ return LESSEQ; }
{ return LESS; }
YY_BREAK
case 41:
YY_RULE_SETUP
#line 139 "tokenizer.lex"
{ return GREATEREQ; }
{ return GREATER; }
YY_BREAK
case 42:
YY_RULE_SETUP
#line 141 "tokenizer.lex"
{ return LBRACE; }
{ return LESSEQ; }
YY_BREAK
case 43:
YY_RULE_SETUP
#line 143 "tokenizer.lex"
{ return RBRACE; }
{ return GREATEREQ; }
YY_BREAK
case 44:
YY_RULE_SETUP
#line 145 "tokenizer.lex"
{ return LBRACKET; }
{ return LBRACE; }
YY_BREAK
case 45:
YY_RULE_SETUP
#line 147 "tokenizer.lex"
{ return RBRACKET; }
{ return RBRACE; }
YY_BREAK
case 46:
YY_RULE_SETUP
#line 149 "tokenizer.lex"
{ return LPAREN; }
{ return LBRACKET; }
YY_BREAK
case 47:
YY_RULE_SETUP
#line 151 "tokenizer.lex"
{ return RPAREN; }
{ return RBRACKET; }
YY_BREAK
case 48:
YY_RULE_SETUP
#line 153 "tokenizer.lex"
{ return DOT; }
{ return LPAREN; }
YY_BREAK
case 49:
YY_RULE_SETUP
#line 155 "tokenizer.lex"
{ return COLON; }
{ return RPAREN; }
YY_BREAK
case 50:
YY_RULE_SETUP
#line 157 "tokenizer.lex"
{ return SEMICOLON; }
{ return DOT; }
YY_BREAK
case 51:
YY_RULE_SETUP
#line 159 "tokenizer.lex"
{ return COMMA; }
{ return COLON; }
YY_BREAK
case 52:
YY_RULE_SETUP
#line 161 "tokenizer.lex"
{ yylval = strdup(yytext); return IDENT; }
{ return SEMICOLON; }
YY_BREAK
case 53:
/* rule 53 can match eol */
YY_RULE_SETUP
#line 163 "tokenizer.lex"
/* Skip comments */
{ return COMMA; }
YY_BREAK
case 54:
/* rule 54 can match eol */
YY_RULE_SETUP
#line 165 "tokenizer.lex"
/* Skip whitespace */
{ return POUND; }
YY_BREAK
case 55:
YY_RULE_SETUP
#line 167 "tokenizer.lex"
{ yylval = strdup(yytext); return IDENT; }
YY_BREAK
case 56:
/* rule 56 can match eol */
YY_RULE_SETUP
#line 169 "tokenizer.lex"
/* Skip comments */
YY_BREAK
case 57:
/* rule 57 can match eol */
YY_RULE_SETUP
#line 171 "tokenizer.lex"
/* Skip whitespace */
YY_BREAK
case 58:
YY_RULE_SETUP
#line 173 "tokenizer.lex"
ECHO;
YY_BREAK
#line 1129 "lex.yy.c"
#line 1148 "lex.yy.c"
case YY_STATE_EOF(INITIAL):
yyterminate();
@ -1256,7 +1275,6 @@ 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
@ -1312,21 +1330,21 @@ static int yy_get_next_buffer (void)
else
{
yy_size_t num_to_read =
int 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_LVALUE;
YY_BUFFER_STATE b = YY_CURRENT_BUFFER;
int yy_c_buf_p_offset =
(int) ((yy_c_buf_p) - b->yy_ch_buf);
if ( b->yy_is_our_buffer )
{
yy_size_t new_size = b->yy_buf_size * 2;
int new_size = b->yy_buf_size * 2;
if ( new_size <= 0 )
b->yy_buf_size += b->yy_buf_size / 8;
@ -1357,7 +1375,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), num_to_read );
(yy_n_chars), (size_t) num_to_read );
YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars);
}
@ -1418,7 +1436,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 >= 101 )
if ( yy_current_state >= 109 )
yy_c = yy_meta[(unsigned int) yy_c];
}
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
@ -1446,13 +1464,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 >= 101 )
if ( yy_current_state >= 109 )
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 == 100);
yy_is_jam = (yy_current_state == 108);
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 )
@ -1467,7 +1485,7 @@ static int yy_get_next_buffer (void)
if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 )
{ /* need to shift things up to make room */
/* +2 for EOB chars. */
register yy_size_t number_to_move = (yy_n_chars) + 2;
register int number_to_move = (yy_n_chars) + 2;
register char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[
YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2];
register char *source =
@ -1516,7 +1534,7 @@ static int yy_get_next_buffer (void)
else
{ /* need more input */
yy_size_t offset = (yy_c_buf_p) - (yytext_ptr);
int offset = (yy_c_buf_p) - (yytext_ptr);
++(yy_c_buf_p);
switch ( yy_get_next_buffer( ) )
@ -1676,6 +1694,10 @@ static void yy_load_buffer_state (void)
yyfree((void *) b );
}
#ifndef __cplusplus
extern int isatty (int );
#endif /* __cplusplus */
/* Initializes or reinitializes a buffer.
* This function is sometimes called more than once on the same buffer,
* such as during a yyrestart() or at EOF.
@ -1788,7 +1810,7 @@ void yypop_buffer_state (void)
*/
static void yyensure_buffer_stack (void)
{
yy_size_t num_to_alloc;
int num_to_alloc;
if (!(yy_buffer_stack)) {
@ -1885,12 +1907,12 @@ YY_BUFFER_STATE yy_scan_string (yyconst char * yystr )
*
* @return the newly allocated buffer state object.
*/
YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, yy_size_t _yybytes_len )
YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len )
{
YY_BUFFER_STATE b;
char *buf;
yy_size_t n;
yy_size_t i;
int i;
/* Get memory for full buffer, including space for trailing EOB's. */
n = _yybytes_len + 2;
@ -1972,7 +1994,7 @@ FILE *yyget_out (void)
/** Get the length of the current token.
*
*/
yy_size_t yyget_leng (void)
int yyget_leng (void)
{
return yyleng;
}
@ -2120,7 +2142,7 @@ void yyfree (void * ptr )
#define YYTABLES_NAME "yytables"
#line 166 "tokenizer.lex"
#line 173 "tokenizer.lex"

137
object.c

@ -2,6 +2,7 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
sol_object_t *sol_cast_int(sol_state_t *state, sol_object_t *obj) {
sol_object_t *res, *ls;
@ -156,31 +157,39 @@ int sol_list_len(sol_state_t *state, sol_object_t *list) {
sol_object_t *sol_list_sublist(sol_state_t *state, sol_object_t *list, int idx) {
int i = 0;
sol_object_t *cur = list;
sol_object_t *copy;
sol_object_t *copy, *res;
if(idx < 0) {
return sol_set_error_string(state, "Create sublist at negative index");
}
while(cur && cur->lvalue && i < idx) {
i++;
while(cur && i < idx) {
if(cur->lvalue) i++;
cur = cur->lnext;
}
copy = sol_new_list(state);
while(cur && cur->lvalue) {
copy->lvalue = sol_incref(cur->lvalue);
if(cur->lnext) {
copy->lnext = sol_alloc_object(state);
copy = copy->lnext;
copy->type = SOL_LIST;
copy->ops = &(state->ListOps);
res = copy;
while(cur) {
if(cur->lvalue) {
copy->lvalue = sol_incref(cur->lvalue);
if(cur->lnext) {
copy->lnext = sol_alloc_object(state);
copy = copy->lnext;
copy->type = SOL_LIST;
copy->ops = &(state->ListOps);
copy->lnext = NULL;
copy->lvalue = NULL;
}
}
cur = cur->lnext;
}
return copy;
return res;
}
sol_object_t *sol_list_get_index(sol_state_t *state, sol_object_t *list, int idx) {
sol_object_t *cur = list;
int i = 0;
if(!sol_is_list(list)) {
return sol_set_error_string(state, "Get index of non-list");
}
if(idx < 0) {
return sol_set_error_string(state, "Get negative index");
}
@ -188,7 +197,7 @@ sol_object_t *sol_list_get_index(sol_state_t *state, sol_object_t *list, int idx
i++;
cur = cur->lnext;
}
if(cur) {
if(cur && cur->lvalue) {
return sol_incref(cur->lvalue);
} else {
return sol_set_error_string(state, "Get out-of-bounds index");
@ -198,6 +207,10 @@ sol_object_t *sol_list_get_index(sol_state_t *state, sol_object_t *list, int idx
void sol_list_set_index(sol_state_t *state, sol_object_t *list, int idx, sol_object_t *obj) {
sol_object_t *cur = list;
int i = 0;
if(!sol_is_list(list)) {
sol_obj_free(sol_set_error_string(state, "Set index of non-list"));
return;
}
if(idx < 0) {
sol_obj_free(sol_set_error_string(state, "Set negative index"));
return;
@ -219,6 +232,10 @@ void sol_list_insert(sol_state_t *state, sol_object_t **list, int idx, sol_objec
sol_object_t *next = *list, *prev = NULL, *temp = sol_alloc_object(state);
int i = 0;
if(sol_has_error(state)) return;
if(!sol_is_list(*list)) {
sol_obj_free(sol_set_error_string(state, "Insert into non-list"));
return;
}
if(idx < 0) {
sol_obj_free(sol_set_error_string(state, "Insert at negative index"));
return;
@ -236,7 +253,6 @@ void sol_list_insert(sol_state_t *state, sol_object_t **list, int idx, sol_objec
if(prev) {
prev->lnext = temp;
} else {
free(*list);
*list = temp;
temp->lnext = next;
}
@ -323,6 +339,51 @@ sol_object_t *sol_f_list_free(sol_state_t *state, sol_object_t *list) {
}
}
int sol_test_cycle(sol_state_t *state, sol_object_t *seq) {
sol_object_t *seen[1024]={};
sol_object_t *cur = seq, **item;
while(cur) {
item = seen;
while(*item) {
if(*item == cur) return 1;
item++;
}
*item = cur;
if(sol_is_list(seq)) {
cur = cur->lnext;
} else {
cur = cur->mnext;
}
}
return 0;
}
int sol_validate_list(sol_state_t *state, sol_object_t *list) {
sol_object_t *cur = list;
int i = 0;
char msg[128];
while(cur) {
if(!sol_is_list(cur)) {
snprintf(msg, 128, "Node at index %d not a list node", i);
//sol_obj_free(sol_set_error_string(state, msg));
return 1;
}
if(cur->lnext && !cur->lvalue) {
snprintf(msg, 128, "Node at index %d has a next node but NULL value", i);
//sol_obj_free(sol_set_error_string(state, msg));
return 1;
}
cur = cur->lnext;
i++;
}
if(sol_test_cycle(state, list)) {
snprintf(msg, 128, "Cycle detected");
//sol_obj_free(sol_set_error_string(state, msg));
return 1;
}
return 0;
}
sol_object_t *sol_new_map(sol_state_t *state) {
sol_object_t *map = sol_alloc_object(state);
if(sol_has_error(state)) return sol_incref(state->None);
@ -350,8 +411,8 @@ sol_object_t *sol_map_submap(sol_state_t *state, sol_object_t *map, sol_object_t
if(cur->mkey) {
sol_list_insert(state, &list, 1, cur->mkey);
cmp = sol_cast_int(state, key->ops->cmp(state, list));
sol_obj_free(sol_list_remove(state, &list, 1));
if(cmp->ival) {
sol_list_remove(state, &list, 1);
if(cmp->ival == 0) {
res = cur;
break;
}
@ -370,7 +431,6 @@ sol_object_t *sol_map_get(sol_state_t *state, sol_object_t *map, sol_object_t *k
sol_object_t *res;
if(sol_is_map(submap)) {
res = sol_incref(submap->mval);
sol_obj_free(submap);
return res;
} else {
return sol_incref(state->None);
@ -384,23 +444,22 @@ void sol_map_set(sol_state_t *state, sol_object_t *map, sol_object_t *key, sol_o
if(cur->mkey) {
sol_list_insert(state, &list, 1, cur->mkey);
cmp = sol_cast_int(state, key->ops->cmp(state, list));
sol_obj_free(sol_list_remove(state, &list, 1));
if(cmp->ival) {
sol_list_remove(state, &list, 1);
if(cmp->ival == 0) {
sol_obj_free(cur->mval);
if(sol_is_none(state, val)) {
if(prev) {
prev->mnext = cur->mnext;
sol_obj_free(cur->mkey);
sol_obj_free(cur->mval);
sol_obj_free(cur);
free(cur);
} else {
sol_obj_free(cur->mkey);
sol_obj_free(cur->mval);
cur->mkey = NULL;
cur->mval = NULL;
}
}
cur->mval = sol_incref(val);
} else {
cur->mval = sol_incref(val);
}
return;
}
}
@ -426,22 +485,21 @@ void sol_map_set_existing(sol_state_t *state, sol_object_t *map, sol_object_t *k
sol_list_insert(state, &list, 1, cur->mkey);
cmp = sol_cast_int(state, key->ops->cmp(state, list));
sol_obj_free(sol_list_remove(state, &list, 1));
if(cmp->ival) {
if(cmp->ival == 0) {
sol_obj_free(cur->mval);
if(sol_is_none(state, val)) {
if(prev) {
prev->mnext = cur->mnext;
sol_obj_free(cur->mkey);
sol_obj_free(cur->mval);
sol_obj_free(cur);
free(cur);
} else {
sol_obj_free(cur->mkey);
sol_obj_free(cur->mval);
cur->mkey = NULL;
cur->mval = NULL;
}
}
cur->mval = sol_incref(val);
} else {
cur->mval = sol_incref(val);
}
return;
}
}
@ -503,6 +561,27 @@ sol_object_t *sol_f_map_free(sol_state_t *state, sol_object_t *map) {
return map;
}
int sol_validate_map(sol_state_t *state, sol_object_t *map) {
sol_object_t *cur = map;
int i = 0;
char msg[128];
while(cur) {
if(!sol_is_map(cur)) {
snprintf(msg, 128, "Node at index %d not a map node", i);
sol_obj_free(sol_set_error_string(state, msg));
return 1;
}
if(cur->mnext && (!cur->mkey || !cur->mval)) {
snprintf(msg, 128, "Node at index %d has a next node but NULL key or value", i);
sol_obj_free(sol_set_error_string(state, msg));
return 1;
}
cur = cur->mnext;
i++;
}
return 0;
}
sol_object_t *sol_new_cfunc(sol_state_t *state, sol_cfunc_t cfunc) {
sol_object_t *res = sol_alloc_object(state);
res->type = SOL_CFUNCTION;

9165
parser.output
File diff suppressed because it is too large
View File

2052
parser.tab.c
File diff suppressed because it is too large
View File

147
parser.tab.h

@ -1,19 +1,19 @@
/* A Bison parser, made by GNU Bison 3.0.2. */
/* A Bison parser, made by GNU Bison 2.7.12-4996. */
/* Bison interface for Yacc-like parsers in C
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
Copyright (C) 1984, 1989-1990, 2000-2013 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
@ -26,13 +26,13 @@
special exception, which will cause the skeleton and the resulting
Bison output files to be licensed under the GNU General Public
License without this special exception.
This special exception was added by the Free Software Foundation in
version 2.2 of Bison. */
#ifndef YY_YY_PARSER_TAB_H_INCLUDED
# define YY_YY_PARSER_TAB_H_INCLUDED
/* Debug traces. */
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG 1
#endif
@ -40,76 +40,91 @@
extern int yydebug;
#endif
/* Token type. */
/* Tokens. */
#ifndef YYTOKENTYPE
# define YYTOKENTYPE
enum yytokentype
{
IF = 258,
THEN = 259,
ELSE = 260,
WHILE = 261,
FOR = 262,
IN = 263,
DO = 264,
FUNC = 265,
RETURN = 266,
BREAK = 267,
CONTINUE = 268,
END = 269,
IDENT = 270,
INT = 271,
FLOAT = 272,
STRING = 273,
PLUS = 274,
MINUS = 275,
STAR = 276,
SLASH = 277,
DSTAR = 278,
BAND = 279,
BOR = 280,
BXOR = 281,
BNOT = 282,
LAND = 283,
LOR = 284,
LNOT = 285,
ASSIGN = 286,
ASSIGNPLUS = 287,
ASSIGNMINUS = 288,
ASSIGNSTAR = 289,
ASSIGNSLASH = 290,
ASSIGNDSTAR = 291,
ASSIGNBAND = 292,
ASSIGNBOR = 293,
ASSIGNBXOR = 294,
EQUAL = 295,
LESS = 296,
GREATER = 297,
LESSEQ = 298,
GREATEREQ = 299,
LBRACE = 300,
RBRACE = 301,
LPAREN = 302,
RPAREN = 303,
LBRACKET = 304,
RBRACKET = 305,
DOT = 306,
COLON = 307,
SEMICOLON = 308,
COMMA = 309
};
/* Put the tokens into the symbol table, so that GDB and other debuggers
know about them. */
enum yytokentype {
IF = 258,
THEN = 259,
ELSE = 260,
WHILE = 261,
FOR = 262,
IN = 263,
DO = 264,
FUNC = 265,
RETURN = 266,
BREAK = 267,
CONTINUE = 268,
END = 269,
NONE = 270,
IDENT = 271,
INT = 272,
FLOAT = 273,
STRING = 274,
PLUS = 275,
MINUS = 276,
STAR = 277,
SLASH = 278,
DSTAR = 279,
BAND = 280,
BOR = 281,
BXOR = 282,
BNOT = 283,
LAND = 284,
LOR = 285,
LNOT = 286,
ASSIGN = 287,
ASSIGNPLUS = 288,
ASSIGNMINUS = 289,
ASSIGNSTAR = 290,
ASSIGNSLASH = 291,
ASSIGNDSTAR = 292,
ASSIGNBAND = 293,
ASSIGNBOR = 294,
ASSIGNBXOR = 295,
EQUAL = 296,
LESS = 297,
GREATER = 298,
LESSEQ = 299,
GREATEREQ = 300,
LBRACE = 301,
RBRACE = 302,
LPAREN = 303,
RPAREN = 304,
LBRACKET = 305,
RBRACKET = 306,
DOT = 307,
COLON = 308,
SEMICOLON = 309,
COMMA = 310,
POUND = 311
};
#endif
/* Value type. */
#if ! defined YYSTYPE && ! defined YYSTYPE_IS_DECLARED
typedef int YYSTYPE;
# define YYSTYPE_IS_TRIVIAL 1
# define yystype YYSTYPE /* obsolescent; will be withdrawn */
# define YYSTYPE_IS_DECLARED 1
#endif
extern YYSTYPE yylval;
#ifdef YYPARSE_PARAM
#if defined __STDC__ || defined __cplusplus
int yyparse (void *YYPARSE_PARAM);
#else
int yyparse ();
#endif
#else /* ! YYPARSE_PARAM */
#if defined __STDC__ || defined __cplusplus
int yyparse (stmt_node **program);
#else
int yyparse ();
#endif
#endif /* ! YYPARSE_PARAM */
#endif /* !YY_YY_PARSER_TAB_H_INCLUDED */

22
parser.y

@ -13,13 +13,13 @@