feat: Add negation to grammar

This commit is contained in:
overflowerror 2024-03-02 19:53:47 +01:00
parent 237d9f584c
commit 7de4815ab8
3 changed files with 7 additions and 0 deletions

View file

@ -60,6 +60,7 @@ enum calc_operator {
NOT_EQUALS,
CONJUNCTION,
DISJUNCTION,
NEGATION,
};
struct calc_expression {

View file

@ -83,6 +83,7 @@ strbuf_t strbuf = NULL;
<INITIAL>"!=" { return NOT_EQUAL; }
<INITIAL>"&&" { return AND; }
<INITIAL>"||" { return OR; }
<INITIAL>"!" { return NOT; }
<INITIAL>"(" { return OPENING_BRACKETS; }
<INITIAL>")" { return CLOSING_BRACKETS; }

View file

@ -54,6 +54,7 @@ extern struct block* program;
%token NOT_EQUAL
%token AND
%token OR
%token NOT
%token OPENING_BRACKETS
%token CLOSING_BRACKETS
@ -162,6 +163,10 @@ calcexpr: OPENING_BRACKETS expr op expr CLOSING_BRACKETS
{
$$ = calc_expression_new($2, $4, $3);
}
| NOT expr
{
$$ = calc_expression_new($2, NULL, NEGATION);
}
;
op: PLUS