Index: Plug.tmpasm =================================================================== --- Plug.tmpasm (revision 36850) +++ Plug.tmpasm (revision 36851) @@ -6,8 +6,14 @@ put /local/pcb/mod/MENUVAR {order_menu} put /local/pcb/mod/OBJS [@ $(PLUGDIR)/order/order.o + $(PLUGDIR)/order/const_gram.o + $(PLUGDIR)/order/const_lex.o + $(PLUGDIR)/order/constraint.o @] +put /local/pcb/mod/BYACCIC {$(PLUGDIR)/order/const_gram} +put /local/pcb/mod/UREGLEX {$(PLUGDIR)/order/const_lex} + switch /local/pcb/order/controls case {buildin} include /local/pcb/tmpasm/buildin; end; case {plugin} include /local/pcb/tmpasm/plugin; end; Index: const_gram.c =================================================================== --- const_gram.c (nonexistent) +++ const_gram.c (revision 36851) @@ -0,0 +1,453 @@ + +#ifdef YY_QUERY_API_VER +#define YY_BYACCIC +#define YY_API_MAJOR 1 +#define YY_API_MINOR 0 +#endif /*YY_QUERY_API_VER*/ + +#define pcb_ordc_EMPTY (-1) +#define pcb_ordc_clearin (pcb_ordc_chr = pcb_ordc_EMPTY) +#define pcb_ordc_errok (pcb_ordc_errflag = 0) +#define pcb_ordc_RECOVERING() (pcb_ordc_errflag != 0) +#define pcb_ordc_ENOMEM (-2) +#define pcb_ordc_EOF 0 +#line 16 "../src_plugins/order/const_gram.c" +#include "../src_plugins/order/const_gram.h" +static const pcb_ordc_int_t pcb_ordc_lhs[] = { -1, + 0, 0, 5, 5, 5, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 4, 2, 3, +}; +static const pcb_ordc_int_t pcb_ordc_len[] = { 2, + 0, 2, 1, 1, 1, 2, 3, 3, 3, 3, + 3, 1, 1, 1, 2, 3, 5, 7, +}; +static const pcb_ordc_int_t pcb_ordc_defred[] = { 0, + 0, 0, 0, 0, 3, 4, 5, 0, 0, 0, + 0, 2, 12, 13, 14, 0, 0, 0, 0, 0, + 16, 6, 0, 15, 0, 0, 0, 0, 0, 0, + 7, 0, 0, 10, 11, 17, 0, 0, 18, +}; +static const pcb_ordc_int_t pcb_ordc_dgoto[] = { 4, + 19, 5, 6, 7, 8, +}; +static const pcb_ordc_int_t pcb_ordc_sindex[] = { -122, + -30, -29, -122, 0, 0, 0, 0, -122, -24, -239, + -106, 0, 0, 0, 0, -24, -24, -237, -41, -18, + 0, 0, -38, 0, -24, -24, -24, -24, -122, -233, + 0, -28, -28, 0, 0, 0, -13, -27, 0, +}; +static const pcb_ordc_int_t pcb_ordc_rindex[] = { 29, + 0, 0, 0, 0, 0, 0, 0, 29, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, -35, -33, 0, 0, 0, 0, 0, 0, +}; +static const pcb_ordc_int_t pcb_ordc_gindex[] = { 22, + -3, 0, 0, 0, 6, +}; +#define pcb_ordc_TABLESIZE 236 +static const pcb_ordc_int_t pcb_ordc_table[] = { 29, + 3, 27, 31, 28, 27, 8, 28, 9, 11, 9, + 10, 18, 22, 23, 27, 17, 28, 20, 21, 24, + 16, 32, 33, 34, 35, 30, 37, 38, 1, 12, + 0, 39, 0, 0, 36, 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, 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, + 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, 25, 26, 0, 25, 26, 0, 8, + 8, 9, 9, 13, 14, 15, +}; +static const pcb_ordc_int_t pcb_ordc_check[] = { 41, + 123, 43, 41, 45, 43, 41, 45, 41, 3, 40, + 40, 36, 16, 17, 43, 40, 45, 257, 125, 257, + 45, 25, 26, 27, 28, 44, 260, 41, 0, 8, + -1, 59, -1, -1, 29, -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, -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, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 261, 262, + -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, -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, 265, 266, -1, 265, 266, -1, 265, + 266, 265, 266, 258, 259, 260, +}; +#define pcb_ordc_FINAL 4 +#define pcb_ordc_MAXTOKEN 269 +#define pcb_ordc_UNDFTOKEN 277 +#define pcb_ordc_TRANSLATE(a) ((a) > pcb_ordc_MAXTOKEN ? pcb_ordc_UNDFTOKEN : (a)) +#if pcb_ordc_DEBUG +static const char *const pcb_ordc_name[] = { + +"end-of-file",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,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_IF", +"T_ERROR","T_INTVAL","T_FLOATVAL","\"==\"","\">=\"","\"<=\"","\"||\"","\"&&\"", +0,0,0,0,0,0,0,"illegal-symbol", +}; +static const char *const pcb_ordc_rule[] = { +"$accept : file", +"file :", +"file : statement file", +"statement : stmt_if", +"statement : stmt_error", +"statement : stmt_block", +"expr : '-' expr", +"expr : '(' expr ')'", +"expr : expr \"==\" expr", +"expr : expr \">=\" expr", +"expr : expr '+' expr", +"expr : expr '-' expr", +"expr : T_INTEGER", +"expr : T_FLOAT", +"expr : T_QSTR", +"expr : '$' T_ID", +"stmt_block : '{' statement '}'", +"stmt_if : T_IF '(' expr ')' statement", +"stmt_error : T_ERROR '(' T_ID ',' T_QSTR ')' ';'", + +}; +#endif + + +#if pcb_ordc_DEBUG +#include /* needed for printf */ +#endif + +#include /* needed for malloc, etc */ +#include /* needed for memset */ + +/* allocate initial stack or double stack size, up to yyctx->stack_max_depth */ +static int pcb_ordc_growstack(pcb_ordc_yyctx_t *yyctx, pcb_ordc_STACKDATA *data) +{ + int i; + unsigned newsize; + pcb_ordc_int_t *newss; + pcb_ordc_STYPE *newvs; + + if ((newsize = data->stacksize) == 0) + newsize = pcb_ordc_INITSTACKSIZE; + else if (newsize >= yyctx->stack_max_depth) + return pcb_ordc_ENOMEM; + else if ((newsize *= 2) > yyctx->stack_max_depth) + newsize = yyctx->stack_max_depth; + + i = (int)(data->s_mark - data->s_base); + newss = (pcb_ordc_int_t *) realloc(data->s_base, newsize * sizeof(*newss)); + if (newss == 0) + return pcb_ordc_ENOMEM; + + data->s_base = newss; + data->s_mark = newss + i; + + newvs = (pcb_ordc_STYPE *) realloc(data->l_base, newsize * sizeof(*newvs)); + if (newvs == 0) + return pcb_ordc_ENOMEM; + + data->l_base = newvs; + data->l_mark = newvs + i; + + data->stacksize = newsize; + data->s_last = data->s_base + newsize - 1; + return 0; +} + +static void pcb_ordc_freestack(pcb_ordc_STACKDATA *data) +{ + free(data->s_base); + free(data->l_base); + memset(data, 0, sizeof(*data)); +} + +#define pcb_ordc_ABORT goto yyabort +#define pcb_ordc_REJECT goto yyabort +#define pcb_ordc_ACCEPT goto yyaccept +#define pcb_ordc_ERROR goto yyerrlab + +int pcb_ordc_parse_init(pcb_ordc_yyctx_t *yyctx) +{ +#if pcb_ordc_DEBUG + const char *yys; + + if ((yys = getenv("pcb_ordc_DEBUG")) != 0) { + yyctx->yyn = *yys; + if (yyctx->yyn >= '0' && yyctx->yyn <= '9') + yyctx->debug = yyctx->yyn - '0'; + } +#endif + + memset(&yyctx->val, 0, sizeof(yyctx->val)); + memset(&yyctx->lval, 0, sizeof(yyctx->lval)); + + yyctx->yym = 0; + yyctx->yyn = 0; + yyctx->nerrs = 0; + yyctx->errflag = 0; + yyctx->chr = pcb_ordc_EMPTY; + yyctx->state = 0; + + memset(&yyctx->stack, 0, sizeof(yyctx->stack)); + + yyctx->stack_max_depth = pcb_ordc_INITSTACKSIZE > 10000 ? pcb_ordc_INITSTACKSIZE : 10000; + if (yyctx->stack.s_base == NULL && pcb_ordc_growstack(yyctx, &yyctx->stack) == pcb_ordc_ENOMEM) + return -1; + yyctx->stack.s_mark = yyctx->stack.s_base; + yyctx->stack.l_mark = yyctx->stack.l_base; + yyctx->state = 0; + *yyctx->stack.s_mark = 0; + yyctx->jump = 0; + return 0; +} + + +#define pcb_ordc_GETCHAR(labidx) \ +do { \ + if (used) { yyctx->jump = labidx; return pcb_ordc_RES_NEXT; } \ + getchar_ ## labidx:; yyctx->chr = tok; yyctx->lval = *lval; used = 1; \ +} while(0) + +pcb_ordc_res_t pcb_ordc_parse(pcb_ordc_yyctx_t *yyctx, pcb_ordc_ctx_t *ctx, int tok, pcb_ordc_STYPE *lval) +{ + int used = 0; +#if pcb_ordc_DEBUG + const char *yys; +#endif + +yyloop:; + if (yyctx->jump == 1) { yyctx->jump = 0; goto getchar_1; } + if (yyctx->jump == 2) { yyctx->jump = 0; goto getchar_2; } + + if ((yyctx->yyn = pcb_ordc_defred[yyctx->state]) != 0) + goto yyreduce; + if (yyctx->chr < 0) { + pcb_ordc_GETCHAR(1); + if (yyctx->chr < 0) + yyctx->chr = pcb_ordc_EOF; +#if pcb_ordc_DEBUG + if (yyctx->debug) { + if ((yys = pcb_ordc_name[pcb_ordc_TRANSLATE(yyctx->chr)]) == NULL) + yys = pcb_ordc_name[pcb_ordc_UNDFTOKEN]; + printf("yyctx->debug: state %d, reading %d (%s)\n", yyctx->state, yyctx->chr, yys); + } +#endif + } + if (((yyctx->yyn = pcb_ordc_sindex[yyctx->state]) != 0) && (yyctx->yyn += yyctx->chr) >= 0 && yyctx->yyn <= pcb_ordc_TABLESIZE && pcb_ordc_check[yyctx->yyn] == (pcb_ordc_int_t) yyctx->chr) { +#if pcb_ordc_DEBUG + if (yyctx->debug) + printf("yyctx->debug: state %d, shifting to state %d\n", yyctx->state, pcb_ordc_table[yyctx->yyn]); +#endif + if (yyctx->stack.s_mark >= yyctx->stack.s_last && pcb_ordc_growstack(yyctx, &yyctx->stack) == pcb_ordc_ENOMEM) + goto yyoverflow; + yyctx->state = pcb_ordc_table[yyctx->yyn]; + *++yyctx->stack.s_mark = pcb_ordc_table[yyctx->yyn]; + *++yyctx->stack.l_mark = yyctx->lval; + yyctx->chr = pcb_ordc_EMPTY; + if (yyctx->errflag > 0) + --yyctx->errflag; + goto yyloop; + } + if (((yyctx->yyn = pcb_ordc_rindex[yyctx->state]) != 0) && (yyctx->yyn += yyctx->chr) >= 0 && yyctx->yyn <= pcb_ordc_TABLESIZE && pcb_ordc_check[yyctx->yyn] == (pcb_ordc_int_t) yyctx->chr) { + yyctx->yyn = pcb_ordc_table[yyctx->yyn]; + goto yyreduce; + } + if (yyctx->errflag != 0) + goto yyinrecovery; + + pcb_ordc_error(ctx, yyctx->lval, "syntax error"); + + goto yyerrlab; /* redundant goto avoids 'unused label' warning */ +yyerrlab: + ++yyctx->nerrs; + +yyinrecovery: + if (yyctx->errflag < 3) { + yyctx->errflag = 3; + for(;;) { + if (((yyctx->yyn = pcb_ordc_sindex[*yyctx->stack.s_mark]) != 0) && (yyctx->yyn += pcb_ordc_ERRCODE) >= 0 && yyctx->yyn <= pcb_ordc_TABLESIZE && pcb_ordc_check[yyctx->yyn] == (pcb_ordc_int_t) pcb_ordc_ERRCODE) { +#if pcb_ordc_DEBUG + if (yyctx->debug) + printf("yyctx->debug: state %d, error recovery shifting to state %d\n", *yyctx->stack.s_mark, pcb_ordc_table[yyctx->yyn]); +#endif + if (yyctx->stack.s_mark >= yyctx->stack.s_last && pcb_ordc_growstack(yyctx, &yyctx->stack) == pcb_ordc_ENOMEM) + goto yyoverflow; + yyctx->state = pcb_ordc_table[yyctx->yyn]; + *++yyctx->stack.s_mark = pcb_ordc_table[yyctx->yyn]; + *++yyctx->stack.l_mark = yyctx->lval; + goto yyloop; + } + else { +#if pcb_ordc_DEBUG + if (yyctx->debug) + printf("yyctx->debug: error recovery discarding state %d\n", *yyctx->stack.s_mark); +#endif + if (yyctx->stack.s_mark <= yyctx->stack.s_base) + goto yyabort; + --yyctx->stack.s_mark; + --yyctx->stack.l_mark; + } + } + } + else { + if (yyctx->chr == pcb_ordc_EOF) + goto yyabort; +#if pcb_ordc_DEBUG + if (yyctx->debug) { + if ((yys = pcb_ordc_name[pcb_ordc_TRANSLATE(yyctx->chr)]) == NULL) + yys = pcb_ordc_name[pcb_ordc_UNDFTOKEN]; + printf("yyctx->debug: state %d, error recovery discards token %d (%s)\n", yyctx->state, yyctx->chr, yys); + } +#endif + yyctx->chr = pcb_ordc_EMPTY; + goto yyloop; + } + +yyreduce: +#if pcb_ordc_DEBUG + if (yyctx->debug) + printf("yyctx->debug: state %d, reducing by rule %d (%s)\n", yyctx->state, yyctx->yyn, pcb_ordc_rule[yyctx->yyn]); +#endif + yyctx->yym = pcb_ordc_len[yyctx->yyn]; + if (yyctx->yym > 0) + yyctx->val = yyctx->stack.l_mark[1 - yyctx->yym]; + else + memset(&yyctx->val, 0, sizeof yyctx->val); + + switch (yyctx->yyn) { +case 6: +#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 96 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = yyctx->stack.l_mark[-1].un.tree; } +break; +case 8: +#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 98 "../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 10: +#line 100 "../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 11: +#line 101 "../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 12: +#line 103 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = NULL; } +break; +case 13: +#line 104 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = NULL; } +break; +case 14: +#line 105 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = NULL; } +break; +case 15: +#line 106 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = NULL; } +break; +case 16: +#line 111 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = yyctx->stack.l_mark[-1].un.tree; } +break; +case 17: +#line 114 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = NULL; } +break; +case 18: +#line 118 "../src_plugins/order/const_gram.y" + { yyctx->val.un.tree = NULL; } +break; +#line 412 "../src_plugins/order/const_gram.c" + } + yyctx->stack.s_mark -= yyctx->yym; + yyctx->state = *yyctx->stack.s_mark; + yyctx->stack.l_mark -= yyctx->yym; + yyctx->yym = pcb_ordc_lhs[yyctx->yyn]; + if (yyctx->state == 0 && yyctx->yym == 0) { +#if pcb_ordc_DEBUG + if (yyctx->debug) + printf("yyctx->debug: after reduction, shifting from state 0 to state %d\n", pcb_ordc_FINAL); +#endif + yyctx->state = pcb_ordc_FINAL; + *++yyctx->stack.s_mark = pcb_ordc_FINAL; + *++yyctx->stack.l_mark = yyctx->val; + if (yyctx->chr < 0) { + pcb_ordc_GETCHAR(2); + if (yyctx->chr < 0) + yyctx->chr = pcb_ordc_EOF; +#if pcb_ordc_DEBUG + if (yyctx->debug) { + if ((yys = pcb_ordc_name[pcb_ordc_TRANSLATE(yyctx->chr)]) == NULL) + yys = pcb_ordc_name[pcb_ordc_UNDFTOKEN]; + printf("yyctx->debug: state %d, reading %d (%s)\n", pcb_ordc_FINAL, yyctx->chr, yys); + } +#endif + } + if (yyctx->chr == pcb_ordc_EOF) + goto yyaccept; + goto yyloop; + } + if (((yyctx->yyn = pcb_ordc_gindex[yyctx->yym]) != 0) && (yyctx->yyn += yyctx->state) >= 0 && yyctx->yyn <= pcb_ordc_TABLESIZE && pcb_ordc_check[yyctx->yyn] == (pcb_ordc_int_t) yyctx->state) + yyctx->state = pcb_ordc_table[yyctx->yyn]; + else + yyctx->state = pcb_ordc_dgoto[yyctx->yym]; +#if pcb_ordc_DEBUG + if (yyctx->debug) + printf("yyctx->debug: after reduction, shifting from state %d to state %d\n", *yyctx->stack.s_mark, yyctx->state); +#endif + if (yyctx->stack.s_mark >= yyctx->stack.s_last && pcb_ordc_growstack(yyctx, &yyctx->stack) == pcb_ordc_ENOMEM) + goto yyoverflow; + *++yyctx->stack.s_mark = (pcb_ordc_int_t) yyctx->state; + *++yyctx->stack.l_mark = yyctx->val; + goto yyloop; + +yyoverflow: + pcb_ordc_error(ctx, yyctx->lval, "yacc stack overflow"); + +yyabort: + pcb_ordc_freestack(&yyctx->stack); + return pcb_ordc_RES_ABORT; + +yyaccept: + pcb_ordc_freestack(&yyctx->stack); + return pcb_ordc_RES_DONE; +} Index: const_gram.h =================================================================== --- const_gram.h (nonexistent) +++ const_gram.h (revision 36851) @@ -0,0 +1,116 @@ +#ifndef _pcb_ordc__defines_h_ +#define _pcb_ordc__defines_h_ + +typedef short pcb_ordc_int_t; +#define pcb_ordc_chr yyctx->chr +#define pcb_ordc_val yyctx->val +#define pcb_ordc_lval yyctx->lval +#define pcb_ordc_stack yyctx->stack +#define pcb_ordc_debug yyctx->debug +#define pcb_ordc_nerrs yyctx->nerrs +#define pcb_ordc_errflag yyctx->errflag +#define pcb_ordc_state yyctx->state +#define pcb_ordc_yyn yyctx->yyn +#define pcb_ordc_yym yyctx->yym +#define pcb_ordc_jump yyctx->jump +#line 18 "../src_plugins/order/const_gram.y" +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * order plugin - constraint language grammar + * pcb-rnd Copyright (C) 2020 Tibor 'Igor2' Palinkas + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * 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 +{ + double d; + int i; + char *s; + void *tree; +} pcb_ordc_tokunion_t; +#line 3 "../src_plugins/order/const_gram.y" +typedef struct pcb_ordc_tokstruct_s +{ + pcb_ordc_tokunion_t un; + long line, first_col, last_col; +} pcb_ordc_tokstruct_t; +typedef pcb_ordc_tokstruct_t pcb_ordc_STYPE; + + +#define T_ID 257 +#define T_INTEGER 258 +#define T_FLOAT 259 +#define T_QSTR 260 +#define T_IF 261 +#define T_ERROR 262 +#define T_INTVAL 263 +#define T_FLOATVAL 264 +#define pcb_ordc_ERRCODE 256 + +#ifndef pcb_ordc_INITSTACKSIZE +#define pcb_ordc_INITSTACKSIZE 200 +#endif + +typedef struct { + unsigned stacksize; + pcb_ordc_int_t *s_base; + pcb_ordc_int_t *s_mark; + pcb_ordc_int_t *s_last; + pcb_ordc_STYPE *l_base; + pcb_ordc_STYPE *l_mark; +#if pcb_ordc_DEBUG + int debug; +#endif +} pcb_ordc_STACKDATA; + +typedef struct { + int errflag; + int chr; + pcb_ordc_STYPE val; + pcb_ordc_STYPE lval; + int nerrs; + int yym, yyn, state; + int jump; + int stack_max_depth; + int debug; + + /* variables for the parser stack */ + pcb_ordc_STACKDATA stack; +} pcb_ordc_yyctx_t; + +typedef enum { pcb_ordc_RES_NEXT, pcb_ordc_RES_DONE, pcb_ordc_RES_ABORT } pcb_ordc_res_t; + +extern int pcb_ordc_parse_init(pcb_ordc_yyctx_t *yyctx); +extern pcb_ordc_res_t pcb_ordc_parse(pcb_ordc_yyctx_t *yyctx, pcb_ordc_ctx_t *ctx, int tok, pcb_ordc_STYPE *lval); +extern void pcb_ordc_error(pcb_ordc_ctx_t *ctx, pcb_ordc_STYPE tok, const char *msg); + + +#endif /* _pcb_ordc__defines_h_ */ Index: const_gram.y =================================================================== --- const_gram.y (nonexistent) +++ const_gram.y (revision 36851) @@ -0,0 +1,119 @@ +%prefix pcb_ordc_% + +%struct +{ + long line, first_col, last_col; +} + +%union +{ + double d; + int i; + char *s; + void *tree; +} + + +%{ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * order plugin - constraint language grammar + * pcb-rnd Copyright (C) 2020 Tibor 'Igor2' Palinkas + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * 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 + +/* Keywords for builtin functions */ +%token T_IF T_ERROR +%token T_INTVAL T_FLOATVAL + +%left "==" ">=" "<=" ">" "<" +%left "||" +%left "&&" +%left '+' '-' +%left '*' '/' '%' +%left '!' +%right '(' ')' + +%type T_QSTR +%type T_ID +%type T_INTEGER +%type T_FLOAT + +%type expr +%type stmt_if +%type stmt_error +%type stmt_block +%type statement + +%% + +file: + /* empty */ + |statement file + ; + +statement: + stmt_if + | stmt_error + | stmt_block + ; + +/*** expressions ***/ +expr: + '-' expr { $$ = unop(PCB_ORDC_NEG, $2); } + | '(' expr ')' { $$ = $2; } + | expr "==" expr { $$ = binop(PCB_ORDC_EQ, $1, $3); } + | expr ">=" expr { $$ = binop(PCB_ORDC_GE, $1, $3); } + + | expr '+' expr { $$ = binop(PCB_ORDC_ADD, $1, $3); } + | expr '-' expr { $$ = binop(PCB_ORDC_ADD, $1, $3); } + + | T_INTEGER { $$ = NULL; } + | T_FLOAT { $$ = NULL; } + | T_QSTR { $$ = NULL; } + | '$' T_ID { $$ = NULL; } + ; + +/*** statements ***/ +stmt_block: + '{' statement '}' { $$ = $2; } + +stmt_if: + T_IF '(' expr ')' statement { $$ = NULL; } + ; + +stmt_error: + T_ERROR '(' T_ID ',' T_QSTR ')' ';' { $$ = NULL; } + ; Index: const_lex.c =================================================================== --- const_lex.c (nonexistent) +++ const_lex.c (revision 36851) @@ -0,0 +1,281 @@ +static const unsigned char pcb_ordc_nfa_0[] = {4,3,0,0,0,0,0,32,255,131,0,0,0,40,0,0,0,0,11,3,0,0,0,0,0,32,255,131,0,0,0,40,0,0,0,0,0,0,0}; +static const unsigned char pcb_ordc_bittab_0[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +static const unsigned char pcb_ordc_chrtyp_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,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,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,0,0,0,0,1,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,0,0,0,0,0}; +static const unsigned char pcb_ordc_nfa_1[] = {4,11,3,0,0,0,0,0,32,255,131,0,0,0,40,0,0,0,0,0,3,0,0,0,0,0,64,0,0,0,0,0,0,0,0,0,0,11,3,0,0,0,0,0,40,255,3,32,0,0,0,32,0,0,0,0,0,0,0}; +static const unsigned char pcb_ordc_nfa_2[] = {4,3,0,0,0,0,0,0,0,0,254,255,255,7,254,255,255,7,11,3,0,0,0,0,0,32,255,3,254,255,255,135,254,255,255,7,0,0,0}; +static const unsigned char pcb_ordc_nfa_3[] = {4,1,34,6,1,11,3,255,255,255,255,251,255,255,255,255,255,255,255,255,255,255,255,0,7,1,1,34,0,0}; +static const unsigned char pcb_ordc_nfa_4[] = {4,3,0,0,0,0,98,191,0,112,0,0,0,0,0,0,0,16,0}; +static const unsigned char pcb_ordc_nfa_5[] = {4,3,0,38,0,0,1,0,0,0,0,0,0,0,0,0,0,0,11,3,0,38,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; +/* strtree.h BEGIN { */ +#ifndef UREGLEX_STRTREE_H +#define UREGLEX_STRTREE_H +typedef enum {ULX_REQ = 1, ULX_BRA, ULX_FIN, ULX_BAD} ureglex_stree_op_t; +typedef struct ureglex_strtree_s { int *code, *ip; } ureglex_strtree_t; +int ureglex_strtree_exec(ureglex_strtree_t *ctx, int chr); +#define UREGLEX_STRTREE_MORE -5 +#endif +/* strtree.h END } */ + +#include +#include "ureglex/exec.h" +int pcb_ordc_strings[] = {2,101,34,2,102,10,2,105,27,4,1,108,1,111,1,97,1,116,1,118,1,97,1,108,3,9,4,2,102,56,2,110,45,4,1,114,1,114,1,111,1,114,3,7,4,1,116,1,118,1,97,1,108,3,8,4,3,6,4}; +ureglex_precomp_t pcb_ordc_rules[] = { + {pcb_ordc_nfa_0, pcb_ordc_bittab_0, pcb_ordc_chrtyp_0, 1.000000}, + {pcb_ordc_nfa_1, pcb_ordc_bittab_0, pcb_ordc_chrtyp_0, 1.000000}, + {pcb_ordc_nfa_2, pcb_ordc_bittab_0, pcb_ordc_chrtyp_0, 1.000000}, + {pcb_ordc_nfa_3, pcb_ordc_bittab_0, pcb_ordc_chrtyp_0, 1.000000}, + {pcb_ordc_nfa_4, pcb_ordc_bittab_0, pcb_ordc_chrtyp_0, 1.000000}, + {pcb_ordc_nfa_5, pcb_ordc_bittab_0, pcb_ordc_chrtyp_0, 1.000000}, + {ureglex_nfa_str, NULL, NULL, 1.000000}, + {ureglex_nfa_str, NULL, NULL, 1.000000}, + {ureglex_nfa_str, NULL, NULL, 1.000000}, + {ureglex_nfa_str, NULL, NULL, 1.000000}, + {NULL, NULL, NULL, 0.0} +}; +#define pcb_ordc_num_rules 10 +typedef struct pcb_ordc_ureglex_s { + ureglex_precomp_t *rules; + char buff[256]; + int num_rules, buff_used, step_back_to, buff_save_term, by_len; + long loc_offs[2], loc_line[2], loc_col[2]; + ureglex_t state[pcb_ordc_num_rules]; + const char *sp; + int strtree_state, strtree_len, strtree_score; + ureglex_strtree_t strtree; + ureglex_t *pending_intcode; +} pcb_ordc_ureglex_t; + +/* TOP CODE BEGIN { */ +#line 5 "const_lex.ul" + /* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * order plugin - constraint language lexer + * pcb-rnd Copyright (C) 2022 Tibor 'Igor2' Palinkas + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + #include + #include + #include "../src_plugins/order/const_gram.h" + #define lval ((pcb_ordc_STYPE *)(user_ctx)) +/* TOP CODE END } */ + +/* exec_spec.h BEGIN { */ +void pcb_ordc_lex_reset(pcb_ordc_ureglex_t *ctx); +void pcb_ordc_lex_init(pcb_ordc_ureglex_t *ctx, ureglex_precomp_t *rules); +int pcb_ordc_lex_char(pcb_ordc_ureglex_t *ctx, void *user_ctx, int chr); +/* exec_spec.h END } */ + +static int pcb_ordc_user_code(pcb_ordc_ureglex_t *ctx, void * user_ctx, int ruleid) { + ureglex_t *rule = &ctx->state[ruleid]; + (void)rule; + switch(ruleid) { + case 0:{ +#line 40 "const_lex.ul" + lval->un.i = atoi(ULX_BUF); + return T_INTEGER; + + } + return UREGLEX_NOP; + case 1:{ +#line 46 "const_lex.ul" + lval->un.d = strtod(ULX_BUF, NULL); + return T_FLOAT; + + } + return UREGLEX_NOP; + case 2:{ +#line 52 "const_lex.ul" + lval->un.s = rnd_strdup(ULX_BUF); + return T_ID; + + } + return UREGLEX_NOP; + case 3:{ +#line 58 "const_lex.ul" + lval->un.s = rnd_strndup(ULX_TAGP(1), ULX_TAGL(1)); + return T_QSTR; + + } + return UREGLEX_NOP; + case 4:{ +#line 64 "const_lex.ul" + return *ULX_BUF; + + } + return UREGLEX_NOP; + case 5:{ +#line 69 "const_lex.ul" + ULX_IGNORE; + + } + return UREGLEX_NOP; + case 6:{ + return T_IF; + } + return UREGLEX_NOP; + case 7:{ + return T_ERROR; + } + return UREGLEX_NOP; + case 8:{ + return T_INTVAL; + } + return UREGLEX_NOP; + case 9:{ + return T_FLOATVAL; + } + return UREGLEX_NOP; + } + return UREGLEX_NO_MATCH; + goto ureglex_ignore; + ureglex_ignore:; + pcb_ordc_lex_reset(ctx); + return UREGLEX_MORE; +} + +/* exec_spec.c BEGIN { */ +void pcb_ordc_lex_reset(pcb_ordc_ureglex_t *ctx) +{ + int n = 0; + if ((ctx->step_back_to >= 0) && (ctx->step_back_to < ctx->buff_used)) { + if (ctx->buff_save_term > 0) + ctx->buff[ctx->step_back_to] = ctx->buff_save_term; + n = ctx->buff_used - ctx->step_back_to; + memmove(ctx->buff, ctx->buff + ctx->step_back_to, n+1); + } + ctx->buff_used = n; + for(n = 0; n < ctx->num_rules; n++) + ureglex_exec_init(&ctx->state[n], ctx->buff, ctx->buff_used); + ctx->buff_save_term = ctx->step_back_to = -1; + ctx->loc_offs[0] = ctx->loc_offs[1]; + ctx->loc_line[0] = ctx->loc_line[1]; + ctx->loc_col[0] = ctx->loc_col[1]; +#if 1 + ctx->strtree_state = UREGLEX_STRTREE_MORE; + ctx->strtree_len = ctx->strtree_score = 0; + ctx->strtree.ip = ctx->strtree.code = pcb_ordc_strings; + ctx->sp = ctx->buff; +#endif +} +void pcb_ordc_lex_init(pcb_ordc_ureglex_t *ctx, ureglex_precomp_t *rules) +{ + ureglex_precomp_t *p; + ctx->rules = rules; + ctx->num_rules = 0; + ctx->buff_save_term = ctx->step_back_to = -1; + for(p = pcb_ordc_rules; p->nfa != NULL; p++) + ctx->state[ctx->num_rules++].pc = p; + ctx->by_len = (p->weight > 0.0); + ctx->loc_offs[1] = ctx->loc_line[1] = ctx->loc_col[1] = 1; + pcb_ordc_lex_reset(ctx); + ctx->loc_offs[1] = ctx->loc_col[1] = 0; + ctx->pending_intcode = NULL; +} +int pcb_ordc_lex_char(pcb_ordc_ureglex_t *ctx, void *user_ctx, int chr) +{ + ureglex_t *best = NULL; + int n, working = 0; + if (ctx->buff_used >= (sizeof(ctx->buff)-1)) + return UREGLEX_TOO_LONG; + ctx->buff[ctx->buff_used++] = chr; + ctx->buff[ctx->buff_used] = '\0'; + ctx->loc_offs[1]++; + if (chr == '\n') { + ctx->loc_line[1]++; + ctx->loc_col[1] = 0; + } + else + ctx->loc_col[1]++; +#if 0 + if (ctx->pending_intcode != NULL) { + best = ctx->pending_intcode; + best->eopat[0] = ctx->buff + ctx->buff_used-1; + ctx->pending_intcode = NULL; + goto skip; + } +#endif +#if 1 + while((ctx->strtree_state == UREGLEX_STRTREE_MORE) && (ctx->sp < (&ctx->buff[ctx->buff_used]))) { + ctx->strtree_state = ureglex_strtree_exec(&ctx->strtree, *ctx->sp++); + if (ctx->strtree_state == UREGLEX_STRTREE_MORE) + working++; + if (ctx->strtree_state > 0) { + ureglex_t *s = &ctx->state[ctx->strtree_state]; + ctx->strtree_len = ctx->buff_used; + s->exec_state = s->score = ctx->strtree_score = (int)((double)(ctx->strtree_len-1) * s->pc->weight * 100); + s->bopat[0] = ctx->buff; + s->eopat[0] = ctx->buff + ctx->strtree_len - 1; + } + } +#endif + for(n = 0; n < ctx->num_rules; n++) { + ureglex_t *s = &ctx->state[n]; + if ((s->pc->bittab != NULL) && (s->exec_state < 0)) { + s->exec_state = ureglex_exec(s); + if (s->exec_state < 0) + working++; + else if ((s->exec_state > 0) && (s->pc->weight != 1.0)) + s->exec_state = s->score = (int)((double)s->exec_state * s->pc->weight); + } + } + if (working != 0) + return UREGLEX_MORE; + for(n = 0; n < ctx->num_rules; n++) { + ureglex_t *s = &ctx->state[n]; + if ((s->pc->bittab != NULL) && (s->exec_state > 0)) { + if (best == NULL) + best = s; + else if ((!ctx->by_len) && (s->score > best->score)) + best = s; + else if ((ctx->by_len) && (s->eopat[0] - s->eopat[1] > best->eopat[0] - best->eopat[1])) + best = s; + } + } +#if 1 + if (ctx->strtree_state > 0) { + if (best == NULL) + best = &ctx->state[ctx->strtree_state]; + else if ((!ctx->by_len) && (ctx->strtree_score > best->score)) + best = &ctx->state[ctx->strtree_state]; + else if ((ctx->by_len) && (ctx->strtree_len > best->eopat[0] - best->eopat[1])) + best = &ctx->state[ctx->strtree_state]; + } +#endif +#if 0 + ctx->pending_intcode = pcb_ordc_intcode_lookup(ctx, chr); +#endif + if (best == NULL) { + ctx->step_back_to = ctx->buff_used-1; + return UREGLEX_NO_MATCH; + } +#if 0 + skip:; +#endif + ctx->step_back_to = best->eopat[0] - ctx->buff; + ctx->buff_save_term = ctx->buff[ctx->step_back_to]; + ctx->buff[ctx->step_back_to] = '\0'; + return pcb_ordc_user_code(ctx, user_ctx, best - ctx->state); +} +/* exec_spec.c END } */ + Index: const_lex.h =================================================================== --- const_lex.h (nonexistent) +++ const_lex.h (revision 36851) @@ -0,0 +1,80 @@ +/* strtree.h BEGIN { */ +#ifndef UREGLEX_STRTREE_H +#define UREGLEX_STRTREE_H +typedef enum {ULX_REQ = 1, ULX_BRA, ULX_FIN, ULX_BAD} ureglex_stree_op_t; +typedef struct ureglex_strtree_s { int *code, *ip; } ureglex_strtree_t; +int ureglex_strtree_exec(ureglex_strtree_t *ctx, int chr); +#define UREGLEX_STRTREE_MORE -5 +#endif +/* strtree.h END } */ + +/* exec.h BEGIN { */ +#ifndef UREGLEX_EXEC_COMMON_H +#define UREGLEX_EXEC_COMMON_H +#define MAXTAG 10 +typedef struct ureglex_precomp_s { + const unsigned char *nfa; + const unsigned char *bittab; + const unsigned char *chrtyp; + double weight; +} ureglex_precomp_t; +typedef struct ureglex_s { + ureglex_precomp_t *pc; + const char *bol; + const char *bopat[MAXTAG]; + const char *eopat[MAXTAG]; + int score; + const char *endp; + union { const void *ptr; int i; } pmstk[30]; + int pmsp; + const unsigned char *pm_ap; + const char *pm_lp; + int pm_c; + const char *pm_bp; + const char *pm_ep; + const char *pm_are; + const char *ex_lp; + unsigned char ex_c; + int ex_loop, pm_loop, pm_loop2, pm_loop2_later; + int exec_state; +} ureglex_t; +typedef enum { + UREGLEX_MORE = -1, + UREGLEX_TOO_LONG = -2, + UREGLEX_NO_MATCH = -3, + UREGLEX_NOP = -4 +} ureglex_error_t; +extern const unsigned char ureglex_nfa_str[]; +#define ULX_BUF ctx->buff +#define ULX_TAGP(n) (ctx->state[ruleid].bopat[(n)]) +#define ULX_TAGL(n) (ctx->state[ruleid].eopat[(n)] - ctx->state[ruleid].bopat[(n)]) +#define ULX_IGNORE goto ureglex_ignore; +void ureglex_exec_init(ureglex_t *r, const char *lp, int buff_used); +int ureglex_exec(ureglex_t *r); +#endif +/* exec.h END } */ + +#define pcb_ordc_num_rules 10 +typedef struct pcb_ordc_ureglex_s { + ureglex_precomp_t *rules; + char buff[256]; + int num_rules, buff_used, step_back_to, buff_save_term, by_len; + long loc_offs[2], loc_line[2], loc_col[2]; + ureglex_t state[pcb_ordc_num_rules]; + const char *sp; + int strtree_state, strtree_len, strtree_score; + ureglex_strtree_t strtree; + ureglex_t *pending_intcode; +} pcb_ordc_ureglex_t; + +/* exec_spec.h BEGIN { */ +void pcb_ordc_lex_reset(pcb_ordc_ureglex_t *ctx); +void pcb_ordc_lex_init(pcb_ordc_ureglex_t *ctx, ureglex_precomp_t *rules); +int pcb_ordc_lex_char(pcb_ordc_ureglex_t *ctx, void *user_ctx, int chr); +/* exec_spec.h END } */ + +#ifndef URELGLEX_EXEC_pcb_ordc_H +#define URELGLEX_EXEC_pcb_ordc_H +extern ureglex_precomp_t pcb_ordc_rules[]; +#define URELGLEX_EXEC_pcb_ordc_HAS_COMMON 0 +#endif Index: const_lex.ul =================================================================== --- const_lex.ul (nonexistent) +++ const_lex.ul (revision 36851) @@ -0,0 +1,74 @@ +prefix pcb_ordc +by_score + +top_code + /* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * order plugin - constraint language lexer + * pcb-rnd Copyright (C) 2022 Tibor 'Igor2' Palinkas + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + #include + #include + #include "../src_plugins/order/const_gram.h" + #define lval ((pcb_ordc_STYPE *)(user_ctx)) + +rule integer +regex [-]?[0-9]+ +code + lval->un.i = atoi(ULX_BUF); + return T_INTEGER; + +rule real +regex [-]?[0-9]*[.][0-9Ee+-]* +code + lval->un.d = strtod(ULX_BUF, NULL); + return T_FLOAT; + +rule id +regex [a-zA-Z][a-zA-Z0-9_-]* +code + lval->un.s = rnd_strdup(ULX_BUF); + return T_ID; + +rule quoted string +regex "\([^"]*\)" +code + lval->un.s = rnd_strndup(ULX_TAGP(1), ULX_TAGL(1)); + return T_QSTR; + +rule chars +regex [()|&<>=!,*/+%-] +code + return *ULX_BUF; + +rule blank +regex [ \t\n\r]+ +code + ULX_IGNORE; + +rulestring if return T_IF; +rulestring error return T_ERROR; +rulestring intval return T_INTVAL; +rulestring floatval return T_FLOATVAL; Index: constraint.c =================================================================== --- constraint.c (nonexistent) +++ constraint.c (revision 36851) @@ -0,0 +1,5 @@ +#include "const_gram.h" +#include "constraint.h" + +/* Error is handled on the push side */ +void pcb_ordc_error(pcb_ordc_ctx_t *ctx, pcb_ordc_STYPE tok, const char *s) { } Index: constraint.h =================================================================== --- constraint.h (nonexistent) +++ constraint.h (revision 36851) @@ -0,0 +1,8 @@ +#ifndef PCB_ORDER_CONSTRAINT +#define PCB_ORDER_CONSTRAINT + +typedef struct pcb_ordc_ctx_s { + int dummy; +} pcb_ordc_ctx_t; + +#endif