From 71f9b6896b722b4a60f871d57fd07aaf42e8c519 Mon Sep 17 00:00:00 2001 From: Priw8 Date: Mon, 8 Apr 2019 14:03:19 +0200 Subject: [PATCH 1/4] thecl: Add bitwise operators --- thecl/ecsparse.y | 6 +++++- thecl/ecsscan.l | 2 ++ thecl/expr.c | 2 ++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/thecl/ecsparse.y b/thecl/ecsparse.y index 8babcc1a..0e53a6d5 100644 --- a/thecl/ecsparse.y +++ b/thecl/ecsparse.y @@ -222,6 +222,8 @@ void set_time(parser_state_t* state, int new_time); %token AND "&&" %token OR "||" %token XOR "^" +%token B_OR "|" +%token B_AND "&" %token DEC "--" %token NEG "-" %token NEGI "$-" @@ -255,7 +257,7 @@ void set_time(parser_state_t* state, int new_time); %type Cast_Target %type Cast_Target2 -%nonassoc ADD ADDI ADDF SUBTRACT SUBTRACTI SUBTRACTF MULTIPLY MULTIPLYI MULTIPLYF DIVIDE DIVIDEI DIVIDEF EQUAL EQUALI EQUALF INEQUAL INEQUALI INEQUALF LT LTI LTF LTEQ LTEQI LTEQF GT GTI GTF GTEQ GTEQI GTEQF MODULO OR AND XOR +%nonassoc ADD ADDI ADDF SUBTRACT SUBTRACTI SUBTRACTF MULTIPLY MULTIPLYI MULTIPLYF DIVIDE DIVIDEI DIVIDEF EQUAL EQUALI EQUALF INEQUAL INEQUALI INEQUALF LT LTI LTF LTEQ LTEQI LTEQF GT GTI GTF GTEQ GTEQI GTEQF MODULO OR AND XOR B_OR B_AND %left NOT NEG NEGI NEGF SIN COS SQRT %right DEC @@ -806,6 +808,8 @@ Expression: | Expression "||" Expression { $$ = EXPR_12(OR, $1, $3); } | Expression "&&" Expression { $$ = EXPR_12(AND, $1, $3); } | Expression "^" Expression { $$ = EXPR_12(XOR, $1, $3); } + | Expression "|" Expression { $$ = EXPR_12(B_OR, $1, $3); } + | Expression "&" Expression { $$ = EXPR_12(B_AND, $1, $3); } | Address "--" { $$ = EXPR_1A(DEC, $1); } | "-" Expression { $$ = EXPR_1B(NEGI, NEGF, $2); } | "sin" Expression { $$ = EXPR_11(SIN, $2); } diff --git a/thecl/ecsscan.l b/thecl/ecsscan.l index 7edc2638..217b4642 100644 --- a/thecl/ecsscan.l +++ b/thecl/ecsscan.l @@ -105,6 +105,8 @@ "||" return OR; "&&" return AND; "^" return XOR; +"|" return B_OR; +"&" return B_AND; "--" return DEC; "-" return NEG; "sin" return SIN; diff --git a/thecl/expr.c b/thecl/expr.c index 5eda8909..63bccad1 100644 --- a/thecl/expr.c +++ b/thecl/expr.c @@ -101,6 +101,8 @@ th10_expressions[] = { { OR, 73, 'S', NULL, 2, "SS", "s1 || s0" }, { AND, 74, 'S', NULL, 2, "SS", "s1 && s0" }, { XOR, 75, 'S', NULL, 2, "SS", "s1 ^ s0" }, + { B_OR, 76, 'S', NULL, 2, "SS", "s1 | s0" }, + { B_AND, 77, 'S', NULL, 2, "SS", "s1 & s0" }, { DEC, 78, 'S', "S", 0, NULL, "p0--" }, { SIN, 79, 'f', NULL, 1, "f", "sin(s0)" }, { COS, 80, 'f', NULL, 1, "f", "cos(s0)" }, From 471df60c1d0d389e8fe688c1c4484c35426d90cd Mon Sep 17 00:00:00 2001 From: Priw8 Date: Tue, 9 Apr 2019 13:08:31 +0200 Subject: [PATCH 2/4] thecl: Fix argument types for ins 408 and 410 in th13_fmts --- thecl/thecl10.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/thecl/thecl10.c b/thecl/thecl10.c index df7755d0..7d75e12d 100644 --- a/thecl/thecl10.c +++ b/thecl/thecl10.c @@ -761,9 +761,9 @@ static const id_format_pair_t th13_fmts[] = { { 405, "SSff" }, { 406, "ff" }, { 407, "SSff" }, - { 408, "ffSS" }, + { 408, "ffff" }, { 409, "SSfff" }, - { 410, "ffSS" }, + { 410, "ffff" }, { 411, "SSfff" }, { 412, "SSf" }, { 413, "SSf" }, From 09632bb0fd7278045d25de5d921bd5ab969b8b5b Mon Sep 17 00:00:00 2001 From: Priw8 Date: Tue, 9 Apr 2019 13:56:02 +0200 Subject: [PATCH 3/4] thecl: Fix argument type for ins430 in th13_fmts --- thecl/thecl10.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/thecl/thecl10.c b/thecl/thecl10.c index 7d75e12d..011a0089 100644 --- a/thecl/thecl10.c +++ b/thecl/thecl10.c @@ -783,7 +783,7 @@ static const id_format_pair_t th13_fmts[] = { { 427, "" }, { 428, "ff" }, { 429, "SSff" }, - { 430, "SS" }, + { 430, "ff" }, { 431, "SSff" }, { 432, "S" }, { 433, "S" }, From 0784031380394981337cbacac1daa8ad0d240c91 Mon Sep 17 00:00:00 2001 From: Priw8 Date: Wed, 22 May 2019 13:51:56 +0200 Subject: [PATCH 4/4] thecl: Add escaping quotes and backslashes in strings --- thecl/ecsscan.l | 19 +++++++++++++++++-- thecl/thecl06.c | 2 +- thecl/thecl10.c | 2 +- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/thecl/ecsscan.l b/thecl/ecsscan.l index 217b4642..5cfa7117 100644 --- a/thecl/ecsscan.l +++ b/thecl/ecsscan.l @@ -60,7 +60,7 @@ result = 1; \ } \ } -%x COMMENT CSTRING STRING +%x COMMENT CSTRING STRING ESCAPE_CHAR %% "," return COMMA; ":" return COLON; @@ -152,10 +152,13 @@ ins_[0-9]+ { BEGIN(STRING); yylval.string = strdup(""); } -[^\"\n]+ { +[^\"\n\\]+ { yylval.string = realloc(yylval.string, strlen(yylval.string) + yyleng + 1); strcat(yylval.string, yytext); } +\\ { + BEGIN(ESCAPE_CHAR); +} \n { free(yylval.string); yyerror(NULL, "unterminated string"); @@ -166,6 +169,18 @@ ins_[0-9]+ { BEGIN(INITIAL); return TEXT; } +[\"\\] { + yylval.string = realloc(yylval.string, strlen(yylval.string) + yyleng + 1); + strcat(yylval.string, yytext); + BEGIN(STRING); +} +[^\"\\] { + char buf[256]; + snprintf(buf, 256, "invalid character escape: %s", yytext); + yyerror(NULL, buf); + BEGIN(INITIAL); + yyterminate(); +} "/*" BEGIN(COMMENT); [^*]* | diff --git a/thecl/thecl06.c b/thecl/thecl06.c index b1bd4c0b..152c7368 100644 --- a/thecl/thecl06.c +++ b/thecl/thecl06.c @@ -124,7 +124,7 @@ th06_param_to_text( for (size_t z = 0; z < zlen; ++z) { if (!param->value.val.z[z]) break; - if (param->value.val.z[z] == '"') + if (param->value.val.z[z] == '"' || param->value.val.z[z] == '\\') *temp++ = '\\'; *temp++ = param->value.val.z[z]; } diff --git a/thecl/thecl10.c b/thecl/thecl10.c index 011a0089..bd07a3de 100644 --- a/thecl/thecl10.c +++ b/thecl/thecl10.c @@ -137,7 +137,7 @@ th10_param_to_text( for (size_t z = 0; z < zlen; ++z) { if (!param->value.val.z[z]) break; - if (param->value.val.z[z] == '"') + if (param->value.val.z[z] == '"' || param->value.val.z[z] == '\\') *temp++ = '\\'; *temp++ = param->value.val.z[z]; }