Index: trunk/src_plugins/order/const_gram.c =================================================================== --- trunk/src_plugins/order/const_gram.c (revision 36860) +++ trunk/src_plugins/order/const_gram.c (revision 36861) @@ -25,55 +25,54 @@ }; static const pcb_ordc_int_t pcb_ordc_defred[] = { 0, 0, 0, 0, 0, 3, 4, 5, 0, 0, 0, - 0, 2, 18, 0, 20, 0, 0, 0, 0, 0, - 0, 0, 25, 0, 0, 0, 6, 0, 21, 0, + 0, 2, 18, 19, 0, 20, 0, 0, 0, 0, + 0, 0, 0, 25, 0, 0, 0, 6, 0, 21, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, - 0, 0, 0, 16, 17, 26, 0, 24, 22, 23, - 0, 27, + 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, + 0, 0, 0, 0, 16, 17, 26, 0, 23, 22, + 24, 0, 27, }; static const pcb_ordc_int_t pcb_ordc_dgoto[] = { 4, - 21, 5, 6, 7, 8, + 22, 5, 6, 7, 8, }; static const pcb_ordc_int_t pcb_ordc_sindex[] = { -121, - -28, -27, -121, 0, 0, 0, 0, -121, -36, -243, - -110, 0, 0, -22, 0, -20, -18, -36, -36, -241, - -35, -21, 0, -36, -36, -36, 0, -24, 0, -36, - -36, -36, -36, -36, -36, -36, -36, -36, -36, -121, - -236, -16, -8, 1, 0, 64, 64, 64, 64, 64, - 64, -38, -42, 0, 0, 0, -15, 0, 0, 0, - -31, 0, + -33, -28, -121, 0, 0, 0, 0, -121, -36, -247, + -110, 0, 0, 0, -22, 0, -20, -18, -36, -36, + -245, -35, -21, 0, -36, -36, -36, 0, -24, 0, + -36, -36, -36, -36, -36, -36, -36, -36, -36, -36, + -121, -236, -16, -8, 1, 0, 56, 56, 56, 56, + 56, 56, -32, -42, 0, 0, 0, -15, 0, 0, + 0, -31, 0, }; static const pcb_ordc_int_t pcb_ordc_rindex[] = { 30, 0, 0, 0, 0, 0, 0, 0, 30, 0, 0, - 0, 0, 0, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 33, 39, 45, 51, 57, - 63, 17, 25, 0, 0, 0, 0, 0, 0, 0, - 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 25, 31, 37, 43, + 49, 55, 9, 17, 0, 0, 0, 0, 0, 0, + 0, 0, 0, }; static const pcb_ordc_int_t pcb_ordc_gindex[] = { 23, - 87, 0, 0, 0, 8, + 78, 0, 0, 0, 2, }; -#define pcb_ordc_TABLESIZE 332 -static const pcb_ordc_int_t pcb_ordc_table[] = { 20, - 38, 3, 39, 19, 38, 40, 39, 38, 18, 39, - 11, 9, 10, 22, 23, 29, 45, 24, 38, 25, - 39, 26, 41, 57, 58, 61, 38, 62, 39, 1, - 12, 0, 59, 0, 38, 0, 39, 0, 0, 0, - 0, 60, 0, 38, 0, 39, 0, 56, 0, 19, - 0, 19, 0, 19, 0, 0, 0, 14, 0, 0, - 0, 0, 0, 0, 0, 15, 0, 0, 0, 0, - 0, 0, 0, 8, 0, 0, 0, 0, 0, 9, - 0, 0, 0, 0, 0, 10, 0, 0, 0, 0, - 0, 11, 0, 0, 0, 0, 0, 12, 0, 0, - 0, 0, 0, 13, 27, 28, 38, 0, 39, 0, - 42, 43, 44, 0, 0, 0, 46, 47, 48, 49, - 50, 51, 52, 53, 54, 55, 0, 0, 0, 0, +#define pcb_ordc_TABLESIZE 325 +static const pcb_ordc_int_t pcb_ordc_table[] = { 21, + 39, 3, 40, 20, 11, 41, 9, 39, 19, 40, + 39, 10, 40, 23, 24, 30, 46, 25, 39, 26, + 40, 27, 42, 58, 59, 62, 39, 63, 40, 1, + 12, 0, 60, 0, 39, 0, 40, 0, 0, 0, + 0, 61, 57, 39, 0, 40, 0, 0, 0, 14, + 0, 0, 0, 0, 0, 0, 0, 15, 0, 0, + 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, + 0, 9, 0, 0, 0, 0, 0, 10, 0, 0, + 0, 0, 0, 11, 0, 0, 0, 0, 0, 12, + 0, 0, 0, 0, 0, 13, 28, 29, 39, 0, + 40, 0, 43, 44, 45, 0, 0, 0, 47, 48, + 49, 50, 51, 52, 53, 54, 55, 56, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, @@ -80,36 +79,35 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 13, 14, 15, 36, 30, 31, 32, 33, 34, - 35, 36, 37, 0, 16, 17, 30, 31, 32, 33, - 34, 35, 36, 37, 30, 31, 32, 33, 34, 35, - 36, 37, 30, 31, 32, 33, 34, 35, 36, 37, - 0, 30, 31, 32, 33, 34, 35, 36, 37, 19, - 19, 19, 19, 19, 19, 19, 19, 14, 14, 14, - 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, - 15, 0, 15, 8, 8, 8, 8, 8, 8, 9, - 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, - 10, 11, 11, 11, 11, 11, 11, 12, 12, 12, - 12, 12, 12, 13, 13, 13, 13, 13, 13, 0, - 36, 37, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 13, 14, 15, 16, 0, 37, 31, 32, 33, 34, + 35, 36, 37, 38, 0, 17, 18, 31, 32, 33, + 34, 35, 36, 37, 38, 31, 32, 33, 34, 35, + 36, 37, 38, 31, 32, 33, 34, 35, 36, 37, + 38, 0, 31, 32, 33, 34, 35, 36, 37, 38, + 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, + 15, 15, 15, 15, 0, 15, 8, 8, 8, 8, + 8, 8, 9, 9, 9, 9, 9, 9, 10, 10, + 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, + 12, 12, 12, 12, 12, 12, 13, 13, 13, 13, + 13, 13, 0, 37, 38, }; static const pcb_ordc_int_t pcb_ordc_check[] = { 36, - 43, 123, 45, 40, 43, 41, 45, 43, 45, 45, - 3, 40, 40, 257, 125, 257, 41, 40, 43, 40, + 43, 123, 45, 40, 3, 41, 40, 43, 45, 45, + 43, 40, 45, 261, 125, 261, 41, 40, 43, 40, 45, 40, 44, 260, 41, 41, 43, 59, 45, 0, 8, -1, 41, -1, 43, -1, 45, -1, -1, -1, - -1, 41, -1, 43, -1, 45, -1, 40, -1, 41, - -1, 43, -1, 45, -1, -1, -1, 41, -1, -1, + -1, 41, 41, 43, -1, 45, -1, -1, -1, 41, + -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, + -1, 41, -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, -1, 41, - -1, -1, -1, -1, -1, 41, -1, -1, -1, -1, - -1, 41, -1, -1, -1, -1, -1, 41, -1, -1, - -1, -1, -1, 41, 18, 19, 43, -1, 45, -1, - 24, 25, 26, -1, -1, -1, 30, 31, 32, 33, - 34, 35, 36, 37, 38, 39, -1, -1, -1, -1, + -1, -1, -1, -1, -1, 41, 19, 20, 43, -1, + 45, -1, 25, 26, 27, -1, -1, -1, 31, 32, + 33, 34, 35, 36, 37, 38, 39, 40, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, 269, 270, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 270, 271, -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, @@ -116,22 +114,22 @@ -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, 258, 259, 260, 267, 261, 262, 263, 264, 265, - 266, 267, 268, -1, 271, 272, 261, 262, 263, 264, - 265, 266, 267, 268, 261, 262, 263, 264, 265, 266, - 267, 268, 261, 262, 263, 264, 265, 266, 267, 268, - -1, 261, 262, 263, 264, 265, 266, 267, 268, 261, - 262, 263, 264, 265, 266, 267, 268, 261, 262, 263, - 264, 265, 266, 267, 268, 261, 262, 263, 264, 265, - 266, -1, 268, 261, 262, 263, 264, 265, 266, 261, - 262, 263, 264, 265, 266, 261, 262, 263, 264, 265, - 266, 261, 262, 263, 264, 265, 266, 261, 262, 263, - 264, 265, 266, 261, 262, 263, 264, 265, 266, -1, - 267, 268, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 257, 258, 259, 260, -1, 268, 262, 263, 264, 265, + 266, 267, 268, 269, -1, 272, 273, 262, 263, 264, + 265, 266, 267, 268, 269, 262, 263, 264, 265, 266, + 267, 268, 269, 262, 263, 264, 265, 266, 267, 268, + 269, -1, 262, 263, 264, 265, 266, 267, 268, 269, + 262, 263, 264, 265, 266, 267, 268, 269, 262, 263, + 264, 265, 266, 267, -1, 269, 262, 263, 264, 265, + 266, 267, 262, 263, 264, 265, 266, 267, 262, 263, + 264, 265, 266, 267, 262, 263, 264, 265, 266, 267, + 262, 263, 264, 265, 266, 267, 262, 263, 264, 265, + 266, 267, -1, 268, 269, }; #define pcb_ordc_FINAL 4 -#define pcb_ordc_MAXTOKEN 272 -#define pcb_ordc_UNDFTOKEN 280 +#define pcb_ordc_MAXTOKEN 274 +#define pcb_ordc_UNDFTOKEN 282 #define pcb_ordc_TRANSLATE(a) ((a) > pcb_ordc_MAXTOKEN ? pcb_ordc_UNDFTOKEN : (a)) #if pcb_ordc_DEBUG static const char *const pcb_ordc_name[] = { @@ -143,9 +141,9 @@ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, -0,0,0,0,0,0,0,0,0,0,"T_ID","T_INTEGER","T_FLOAT","T_QSTR","T_EQ","T_NEQ","T_GE", -"T_LE","T_GT","T_LT","T_AND","T_OR","T_IF","T_ERROR","T_INT","T_STRING",0,0,0,0, -0,0,0,"illegal-symbol", +0,0,0,0,0,0,0,0,0,0,"T_CINT","T_CFLOAT","T_STRING","T_QSTR","T_ID","T_EQ", +"T_NEQ","T_GE","T_LE","T_GT","T_LT","T_AND","T_OR","T_IF","T_ERROR","T_INT", +"T_FLOAT","T_STR",0,0,0,0,0,0,0,"illegal-symbol", }; static const char *const pcb_ordc_rule[] = { "$accept : file", @@ -166,8 +164,8 @@ "expr : expr T_OR expr", "expr : expr '+' expr", "expr : expr '-' expr", -"expr : T_INTEGER", -"expr : T_FLOAT", +"expr : T_CINT", +"expr : T_CFLOAT", "expr : T_QSTR", "expr : '$' T_ID", "expr : T_INT '(' expr ')'", @@ -180,7 +178,71 @@ }; #endif +#line 132 "../src_plugins/order/const_gram.y" +#include +#include +#include + +static pcb_ordc_node_t *new_node(pcb_ordc_node_type_t ty) +{ + pcb_ordc_node_t *n = calloc(sizeof(pcb_ordc_node_t), 1); + n->type = ty; + return n; +} + +static pcb_ordc_node_t *binop(pcb_ordc_node_type_t ty, pcb_ordc_node_t *a, pcb_ordc_node_t *b) +{ + pcb_ordc_node_t *n = new_node(ty); + assert((a == NULL) || (a->next == NULL)); + assert((b == NULL) || (b->next == NULL)); + n->ch_first = a; + if (a != NULL) + a->next = b; + return n; +} + +#define unop(ty, a) binop(ty, a, NULL) + +static pcb_ordc_node_t *id2node(char *s) +{ + pcb_ordc_node_t *n = new_node(PCB_ORDC_ID); + n->val.s = s; + return n; +} + +static pcb_ordc_node_t *qstr2node(char *s) +{ + pcb_ordc_node_t *n = new_node(PCB_ORDC_QSTR); + n->val.s = s; + return n; +} + +static pcb_ordc_node_t *int2node(long l) +{ + pcb_ordc_node_t *n = new_node(PCB_ORDC_CINT); + n->val.l = l; + return n; +} + +static pcb_ordc_node_t *float2node(double d) +{ + pcb_ordc_node_t *n = new_node(PCB_ORDC_CFLOAT); + n->val.d = d; + return n; +} + + +static void prepend(pcb_ordc_node_t *parent, pcb_ordc_node_t *newch) +{ + assert(newch->next == NULL); + + newch->next = parent->ch_first; + parent->ch_first = newch; +} + +#line 257 "../src_plugins/order/const_gram.c" + #if pcb_ordc_DEBUG #include /* needed for printf */ #endif @@ -384,95 +446,111 @@ memset(&yyctx->val, 0, sizeof yyctx->val); switch (yyctx->yyn) { +case 2: +#line 84 "../src_plugins/order/const_gram.y" + { prepend(ctx->root, yyctx->stack.l_mark[-1].un.tree); } +break; +case 3: +#line 88 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = yyctx->stack.l_mark[0].un.tree; } +break; +case 4: +#line 89 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = yyctx->stack.l_mark[0].un.tree; } +break; +case 5: +#line 90 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = yyctx->stack.l_mark[0].un.tree; } +break; case 6: -#line 96 "../src_plugins/order/const_gram.y" +#line 95 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = unop(PCB_ORDC_NEG, yyctx->stack.l_mark[0].un.tree); } break; case 7: -#line 97 "../src_plugins/order/const_gram.y" +#line 96 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = yyctx->stack.l_mark[-1].un.tree; } break; case 8: -#line 98 "../src_plugins/order/const_gram.y" +#line 97 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_EQ, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 9: -#line 99 "../src_plugins/order/const_gram.y" +#line 98 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_NEQ, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 10: -#line 100 "../src_plugins/order/const_gram.y" +#line 99 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_GE, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 11: -#line 101 "../src_plugins/order/const_gram.y" +#line 100 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_LE, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 12: -#line 102 "../src_plugins/order/const_gram.y" +#line 101 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_GT, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 13: -#line 103 "../src_plugins/order/const_gram.y" +#line 102 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_LT, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 14: -#line 104 "../src_plugins/order/const_gram.y" +#line 103 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_AND, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 15: -#line 105 "../src_plugins/order/const_gram.y" +#line 104 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_OR, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 16: -#line 107 "../src_plugins/order/const_gram.y" +#line 106 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_ADD, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 17: -#line 108 "../src_plugins/order/const_gram.y" +#line 107 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = binop(PCB_ORDC_SUB, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 18: -#line 110 "../src_plugins/order/const_gram.y" - { yyctx->val.un.tree = NULL; } +#line 109 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = int2node(yyctx->stack.l_mark[0].un.i); } break; case 19: -#line 111 "../src_plugins/order/const_gram.y" +#line 110 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = NULL; } break; case 20: -#line 112 "../src_plugins/order/const_gram.y" +#line 111 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = NULL; } break; case 21: -#line 113 "../src_plugins/order/const_gram.y" +#line 112 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = NULL; } break; case 22: -#line 115 "../src_plugins/order/const_gram.y" +#line 114 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = NULL; } break; case 23: -#line 116 "../src_plugins/order/const_gram.y" +#line 115 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = NULL; } break; case 24: -#line 117 "../src_plugins/order/const_gram.y" +#line 116 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = NULL; } break; case 25: -#line 122 "../src_plugins/order/const_gram.y" +#line 121 "../src_plugins/order/const_gram.y" { yyctx->val.un.tree = yyctx->stack.l_mark[-1].un.tree; } break; case 26: -#line 125 "../src_plugins/order/const_gram.y" - { yyctx->val.un.tree = NULL; } +#line 124 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = binop(PCB_ORDC_IF, yyctx->stack.l_mark[-2].un.tree, yyctx->stack.l_mark[0].un.tree); } break; case 27: -#line 129 "../src_plugins/order/const_gram.y" - { yyctx->val.un.tree = NULL; } +#line 128 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = binop(PCB_ORDC_ERROR, id2node(yyctx->stack.l_mark[-4].un.s), qstr2node(yyctx->stack.l_mark[-2].un.s)); } break; -#line 488 "../src_plugins/order/const_gram.c" +#line 566 "../src_plugins/order/const_gram.c" } yyctx->stack.s_mark -= yyctx->yym; yyctx->state = *yyctx->stack.s_mark; Index: trunk/src_plugins/order/const_gram.h =================================================================== --- trunk/src_plugins/order/const_gram.h (revision 36860) +++ trunk/src_plugins/order/const_gram.h (revision 36861) @@ -41,12 +41,9 @@ * lead developer: http://repo.hu/projects/pcb-rnd/contact.html * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") */ -#include #include "../src_plugins/order/const_gram.h" #include "../src_plugins/order/constraint.h" -#define binop(a, b, c) NULL -#define unop(a, b) NULL #line 8 "../src_plugins/order/const_gram.y" typedef union pcb_ordc_tokunion_u @@ -65,22 +62,24 @@ typedef pcb_ordc_tokstruct_t pcb_ordc_STYPE; -#define T_ID 257 -#define T_INTEGER 258 -#define T_FLOAT 259 +#define T_CINT 257 +#define T_CFLOAT 258 +#define T_STRING 259 #define T_QSTR 260 -#define T_EQ 261 -#define T_NEQ 262 -#define T_GE 263 -#define T_LE 264 -#define T_GT 265 -#define T_LT 266 -#define T_AND 267 -#define T_OR 268 -#define T_IF 269 -#define T_ERROR 270 -#define T_INT 271 -#define T_STRING 272 +#define T_ID 261 +#define T_EQ 262 +#define T_NEQ 263 +#define T_GE 264 +#define T_LE 265 +#define T_GT 266 +#define T_LT 267 +#define T_AND 268 +#define T_OR 269 +#define T_IF 270 +#define T_ERROR 271 +#define T_INT 272 +#define T_FLOAT 273 +#define T_STR 274 #define pcb_ordc_ERRCODE 256 #ifndef pcb_ordc_INITSTACKSIZE Index: trunk/src_plugins/order/const_gram.y =================================================================== --- trunk/src_plugins/order/const_gram.y (revision 36860) +++ trunk/src_plugins/order/const_gram.y (revision 36861) @@ -42,23 +42,22 @@ * lead developer: http://repo.hu/projects/pcb-rnd/contact.html * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") */ -#include #include "../src_plugins/order/const_gram.h" #include "../src_plugins/order/constraint.h" -#define binop(a, b, c) NULL -#define unop(a, b) NULL %} -/* Generic */ -%token T_ID T_INTEGER T_FLOAT T_QSTR +/* Constants */ +%token T_CINT T_CFLOAT T_STRING T_QSTR T_ID + +/* Operators */ %token T_EQ T_NEQ T_GE T_LE T_GT T_LT T_AND T_OR /* Keywords for builtin functions */ -%token T_IF T_ERROR -%token T_INT T_FLOAT T_STRING +%token T_IF T_ERROR T_INT T_FLOAT T_STR + %left T_EQ T_NEQ T_GE T_LE T_GT T_LT %left T_OR %left T_AND @@ -69,8 +68,8 @@ %type T_QSTR %type T_ID -%type T_INTEGER -%type T_FLOAT +%type T_CINT +%type T_CFLOAT %type expr %type stmt_if @@ -82,13 +81,13 @@ file: /* empty */ - |statement file + | statement file { prepend(ctx->root, $1); } ; statement: - stmt_if - | stmt_error - | stmt_block + stmt_if { $$ = $1; } + | stmt_error { $$ = $1; } + | stmt_block { $$ = $1; } ; /*** expressions ***/ @@ -107,8 +106,8 @@ | expr '+' expr { $$ = binop(PCB_ORDC_ADD, $1, $3); } | expr '-' expr { $$ = binop(PCB_ORDC_SUB, $1, $3); } - | T_INTEGER { $$ = NULL; } - | T_FLOAT { $$ = NULL; } + | T_CINT { $$ = int2node($1); } + | T_CFLOAT { $$ = NULL; } | T_QSTR { $$ = NULL; } | '$' T_ID { $$ = NULL; } @@ -122,9 +121,73 @@ '{' statement '}' { $$ = $2; } stmt_if: - T_IF '(' expr ')' statement { $$ = NULL; } + T_IF '(' expr ')' statement { $$ = binop(PCB_ORDC_IF, $3, $5); } ; stmt_error: - T_ERROR '(' T_ID ',' T_QSTR ')' ';' { $$ = NULL; } + T_ERROR '(' T_ID ',' T_QSTR ')' ';' { $$ = binop(PCB_ORDC_ERROR, id2node($3), qstr2node($5)); } ; + +%% + +#include +#include +#include + +static pcb_ordc_node_t *new_node(pcb_ordc_node_type_t ty) +{ + pcb_ordc_node_t *n = calloc(sizeof(pcb_ordc_node_t), 1); + n->type = ty; + return n; +} + +static pcb_ordc_node_t *binop(pcb_ordc_node_type_t ty, pcb_ordc_node_t *a, pcb_ordc_node_t *b) +{ + pcb_ordc_node_t *n = new_node(ty); + assert((a == NULL) || (a->next == NULL)); + assert((b == NULL) || (b->next == NULL)); + n->ch_first = a; + if (a != NULL) + a->next = b; + return n; +} + +#define unop(ty, a) binop(ty, a, NULL) + +static pcb_ordc_node_t *id2node(char *s) +{ + pcb_ordc_node_t *n = new_node(PCB_ORDC_ID); + n->val.s = s; + return n; +} + +static pcb_ordc_node_t *qstr2node(char *s) +{ + pcb_ordc_node_t *n = new_node(PCB_ORDC_QSTR); + n->val.s = s; + return n; +} + +static pcb_ordc_node_t *int2node(long l) +{ + pcb_ordc_node_t *n = new_node(PCB_ORDC_CINT); + n->val.l = l; + return n; +} + +static pcb_ordc_node_t *float2node(double d) +{ + pcb_ordc_node_t *n = new_node(PCB_ORDC_CFLOAT); + n->val.d = d; + return n; +} + + +static void prepend(pcb_ordc_node_t *parent, pcb_ordc_node_t *newch) +{ + assert(newch->next == NULL); + + newch->next = parent->ch_first; + parent->ch_first = newch; +} + Index: trunk/src_plugins/order/const_lex.c =================================================================== --- trunk/src_plugins/order/const_lex.c (revision 36860) +++ trunk/src_plugins/order/const_lex.c (revision 36861) @@ -103,7 +103,7 @@ case 0:{ #line 41 "const_lex.ul" lval->un.i = atoi(ULX_BUF); - return T_INTEGER; + return T_CINT; } return UREGLEX_NOP; @@ -110,7 +110,7 @@ case 1:{ #line 47 "const_lex.ul" lval->un.d = strtod(ULX_BUF, NULL); - return T_FLOAT; + return T_CFLOAT; } return UREGLEX_NOP; Index: trunk/src_plugins/order/const_lex.ul =================================================================== --- trunk/src_plugins/order/const_lex.ul (revision 36860) +++ trunk/src_plugins/order/const_lex.ul (revision 36861) @@ -39,13 +39,13 @@ regex [-]?[0-9]+ code lval->un.i = atoi(ULX_BUF); - return T_INTEGER; + return T_CINT; rule real regex [-]?[0-9]*[.][0-9Ee+-]* code lval->un.d = strtod(ULX_BUF, NULL); - return T_FLOAT; + return T_CFLOAT; rule id regex [a-zA-Z][a-zA-Z0-9_-]* Index: trunk/src_plugins/order/constraint.c =================================================================== --- trunk/src_plugins/order/constraint.c (revision 36860) +++ trunk/src_plugins/order/constraint.c (revision 36861) @@ -1,5 +1,6 @@ #include "config.h" #include +#include #include "const_gram.h" #include "constraint.h" #include "const_gram.h" Index: trunk/src_plugins/order/constraint.h =================================================================== --- trunk/src_plugins/order/constraint.h (revision 36860) +++ trunk/src_plugins/order/constraint.h (revision 36861) @@ -2,10 +2,20 @@ #define PCB_ORDER_CONSTRAINT typedef enum { + PCB_ORDC_ROOT, + PCB_ORDC_IF, PCB_ORDC_ERROR, - PCB_ORDC_INTEGER, + /* consts and variables */ + PCB_ORDC_CINT, + PCB_ORDC_CFLOAT, + PCB_ORDC_QSTR, + PCB_ORDC_ID, + PCB_ORDC_VAR, + + /* casts */ + PCB_ORDC_INT, PCB_ORDC_FLOAT, PCB_ORDC_STRING, @@ -26,15 +36,11 @@ struct pcb_ordc_node_s { pcb_ordc_node_type_t type; union { - struct { - pcb_ordc_node_t *o1, *o2; - } op; - union { - long i; - double d; - char *s; - } data; + long l; + double d; + char *s; } val; + pcb_ordc_node_t *ch_first, *next; }; typedef struct pcb_ordc_ctx_s {