Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

& and | operators, escaping quotes/backslashes, other small things #56

Merged
merged 4 commits into from
May 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion thecl/ecsparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$-"
Expand Down Expand Up @@ -255,7 +257,7 @@ void set_time(parser_state_t* state, int new_time);
%type <integer> Cast_Target
%type <integer> 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

Expand Down Expand Up @@ -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); }
Expand Down
21 changes: 19 additions & 2 deletions thecl/ecsscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
result = 1; \
} \
}
%x COMMENT CSTRING STRING
%x COMMENT CSTRING STRING ESCAPE_CHAR
%%
"," return COMMA;
":" return COLON;
Expand Down Expand Up @@ -105,6 +105,8 @@
"||" return OR;
"&&" return AND;
"^" return XOR;
"|" return B_OR;
"&" return B_AND;
"--" return DEC;
"-" return NEG;
"sin" return SIN;
Expand Down Expand Up @@ -150,10 +152,13 @@ ins_[0-9]+ {
BEGIN(STRING);
yylval.string = strdup("");
}
<STRING>[^\"\n]+ {
<STRING>[^\"\n\\]+ {
yylval.string = realloc(yylval.string, strlen(yylval.string) + yyleng + 1);
strcat(yylval.string, yytext);
}
<STRING>\\ {
BEGIN(ESCAPE_CHAR);
}
<STRING>\n {
free(yylval.string);
yyerror(NULL, "unterminated string");
Expand All @@ -164,6 +169,18 @@ ins_[0-9]+ {
BEGIN(INITIAL);
return TEXT;
}
<ESCAPE_CHAR>[\"\\] {
yylval.string = realloc(yylval.string, strlen(yylval.string) + yyleng + 1);
strcat(yylval.string, yytext);
BEGIN(STRING);
}
<ESCAPE_CHAR>[^\"\\] {
char buf[256];
snprintf(buf, 256, "invalid character escape: %s", yytext);
yyerror(NULL, buf);
BEGIN(INITIAL);
yyterminate();
}

"/*" BEGIN(COMMENT);
<COMMENT>[^*]* |
Expand Down
2 changes: 2 additions & 0 deletions thecl/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)" },
Expand Down
2 changes: 1 addition & 1 deletion thecl/thecl06.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down
8 changes: 4 additions & 4 deletions thecl/thecl10.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
Expand Down Expand Up @@ -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" },
Expand All @@ -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" },
Expand Down