Skip to content

Commit

Permalink
Merge pull request #61 from thpatch/thecl-typed-variables-betternum
Browse files Browse the repository at this point in the history
thecl: better number and rad handling
  • Loading branch information
ManDude authored Oct 12, 2019
2 parents c64ee0f + 4895c13 commit 5c4c430
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
7 changes: 6 additions & 1 deletion thecl/ecsparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static void directive_eclmap(parser_state_t* state, char* name);
%token <string> IDENTIFIER "identifier"
%token <string> TEXT "text"
%token <integer> INTEGER "integer"
%token <integer> PLUS_INTEGER "+integer"
%token <floating> FLOATING "floating"
%token <string> RANK "rank"
%token <string> DIRECTIVE "directive"
Expand Down Expand Up @@ -503,7 +504,7 @@ ArgumentDeclaration:

Instructions:
| Instructions INTEGER ":" { set_time(state, $2); }
| Instructions "+" INTEGER ":" { set_time(state, state->instr_time + $3) }
| Instructions PLUS_INTEGER ":" { set_time(state, state->instr_time + $2) }
| Instructions IDENTIFIER ":" { label_create(state, $2); free($2); }
| Instructions Instruction ";"
| Instructions Block
Expand Down Expand Up @@ -1201,6 +1202,10 @@ Integer:
$$ = param_new('S');
$$->value.val.S = $1;
}
| PLUS_INTEGER {
$$ = param_new('S');
$$->value.val.S = $1;
}
;

Floating:
Expand Down
12 changes: 8 additions & 4 deletions thecl/ecsscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ _Sf return CAST_IF;
_ff return CAST_FF;
_fS return CAST_FI;

-?[0-9]+(\.[0-9]*)?f {
(-|\+)?[0-9]+(\.([0-9]*f|[0-9]+)|f) {
yylval.floating = strtof(yytext, NULL);
return FLOATING;
}
rad\(-?[0-9]+(\.[0-9]*)?f\) {
rad\((-|\+)?[0-9]+(\.([0-9]*f|[0-9]+)|f)?\) {
yylval.floating = strtof(yytext+4, NULL) / 180.0f * 3.14159265359f;
return FLOATING;
}
Expand All @@ -150,11 +150,15 @@ ins_[0-9]+ {
yylval.integer = strtol(yytext, NULL, 10);
return INTEGER;
}
-?0x[0-9a-fA-F]+ {
\+[0-9]+ {
yylval.integer = strtol(yytext, NULL, 10);
return PLUS_INTEGER;
}
-|\+?0x[0-9a-fA-F]+ {
yylval.integer = strtol(yytext, NULL, 16);
return INTEGER;
}
-?0b[0-1]+ {
-|\+?0b[0-1]+ {
bool isNegative = yytext[0] == '-';
yylval.integer = strtol(yytext + (isNegative ? 3 : 2), NULL, 2);
if (isNegative) yylval.integer = -yylval.integer;
Expand Down

0 comments on commit 5c4c430

Please sign in to comment.