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

reduce/reduce conflicts and precedence fixes #64

Merged
merged 8 commits into from
Nov 7, 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
47 changes: 19 additions & 28 deletions thecl/ecsparse.y
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ static void directive_eclmap(parser_state_t* state, char* name);
%token B_OR "|"
%token B_AND "&"
%token DEC "--"
%token NEG "-"
%token NEG
%token NEGI
%token NEGF
%token SIN "sin"
Expand Down Expand Up @@ -326,19 +326,23 @@ static void directive_eclmap(parser_state_t* state, char* name);
%type <integer> VarDeclaration

%left QUESTION
%left OR AND
%left XOR B_OR B_AND
%left OR
%left AND
%left B_OR
%left XOR
%left B_AND
%left EQUAL INEQUAL
%left LT LTEQ GT GTEQ
%left ADD SUBTRACT
%left MULTIPLY DIVIDE MODULO
%right NOT NEG
%left SIN COS SQRT
%right DEC
%precedence NOT NEG
%precedence SIN COS SQRT
%precedence DEC

%%

Statements:
%empty
| Statements Statement
;

Expand Down Expand Up @@ -534,7 +538,7 @@ VarDeclaration:
;

ArgumentDeclaration:
/* The | at the beginning is obviously intentional and needed to allow creating subs with no arguments. */
%empty
| DeclareKeyword IDENTIFIER {
var_create(state, state->current_sub, $2, $1);
free($2);
Expand All @@ -546,6 +550,7 @@ ArgumentDeclaration:
;

Instructions:
%empty
| Instructions INTEGER ":" { set_time(state, $2); }
| Instructions PLUS_INTEGER ":" { set_time(state, state->instr_time + $2); }
| Instructions IDENTIFIER ":" { label_create(state, $2); free($2); }
Expand Down Expand Up @@ -647,6 +652,7 @@ IfBlock:
;

ElseBlock:
%empty
| "else" {
char labelstr[256];
snprintf(labelstr, 256, "if_%i_%i", yylloc.first_line, yylloc.first_column);
Expand Down Expand Up @@ -860,9 +866,7 @@ SwitchBlock:
;

CaseList:
Case
| Case Instructions
| CaseList Case
Case Instructions
| CaseList Case Instructions
;

Expand Down Expand Up @@ -1097,7 +1101,7 @@ Assignment:
;

Instruction_Parameters:
{ $$ = NULL; }
%empty { $$ = NULL; }
| Instruction_Parameters_List
;

Expand Down Expand Up @@ -1143,9 +1147,7 @@ Cast_Type:
;

Instruction_Parameter:
Address
| Integer
| Floating
Load_Type
| Text
| Cast_Target2 Cast_Type {
$$ = param_new('D');
Expand All @@ -1163,18 +1165,6 @@ Instruction_Parameter:
}
param_free($2);
}
| Cast_Target "(" Expression ")" {
list_prepend_new(&state->expressions, $3);

$$ = param_new($1);
$$->stack = 1;
$$->is_expression_param = $1;
if ($1 == 'S') {
$$->value.val.S = -1;
} else {
$$->value.val.f = -1.0f;
}
}
| Expression {
list_prepend_new(&state->expressions, $1);

Expand Down Expand Up @@ -1237,7 +1227,7 @@ Expression:
if ($1->value.val.S >= 0) /* Stack variables only. This is also verrfied to be int by expression creation. */
state->current_sub->vars[$1->value.val.S / 4]->is_written = true;
}
| "-" Expression {
| "-" Expression %prec NEG {
if (is_post_th13(state->version)) {
$$ = EXPR_21(NEGI, NEGF, $2);
} else {
Expand All @@ -1253,7 +1243,8 @@ Expression:
/* Custom expressions. */
| IDENTIFIER "(" Instruction_Parameters ")" { $$ = expression_call_new(state, $3, $1); }
| Rank_Switch_List { $$ = expression_rank_switch_new(state, $1); }
| Expression "?" Expression_Safe ":" Expression_Safe { $$ = expression_ternary_new(state, $1, $3, $5); }
| Expression "?" Expression_Safe ":" Expression_Safe %prec QUESTION
{ $$ = expression_ternary_new(state, $1, $3, $5); }
;

/*
Expand Down
1 change: 0 additions & 1 deletion thecl/ecsscan.l
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@
"|" return B_OR;
"&" return B_AND;
"--" return DEC;
"-" return NEG;
"sin" return SIN;
"cos" return COS;
"sqrt" return SQRT;
Expand Down
21 changes: 0 additions & 21 deletions thecl/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,6 @@
#include "ecsparse.h"
#include "expr.h"

typedef struct {
int symbol;
int symbols[2];
} alternative_t;

static const alternative_t
th10_alternatives[] = {
{ 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 } },
{ NEG, { NEGI, NEGF } },
{ 0, { 0, 0 } }
};

static const expr_t
th10_expressions[] = {
/* The program checks against the number of params, as well as the
Expand Down