~lbnz/xr0

d3c9271ac1f744e8aa086c3d2ee360d529125125 — Xr0 Team 7 months ago babd049
checkpoint
5 files changed, 28 insertions(+), 51 deletions(-)

M include/ast.h
M src/ast/expr/expr.c
M src/ast/expr/expr.h
M src/ast/gram.y
M src/ast/lex.l
M include/ast.h => include/ast.h +15 -26
@@ 2,32 2,6 @@
#define XR0_AST_H
#include <stdbool.h>

enum ast_unary_operator {
	UNARY_OP_ADDRESS		= 1 << 0,
	UNARY_OP_DEREFERENCE		= 1 << 1,
	UNARY_OP_POSITIVE		= 1 << 2,
	UNARY_OP_NEGATIVE		= 1 << 3,
	UNARY_OP_ONES_COMPLEMENT	= 1 << 4,
	UNARY_OP_BANG			= 1 << 5
};

enum ast_binary_operator {
	BINARY_OP_EQV	= 1 << 0,
	BINARY_OP_IMPL	= 1 << 1,
	BINARY_OP_FLLW	= 1 << 2,

	BINARY_OP_EQ	= 1 << 3,
	BINARY_OP_NE	= 1 << 4,

	BINARY_OP_LT	= 1 << 5,
	BINARY_OP_GT	= 1 << 6,
	BINARY_OP_LE	= 1 << 7,
	BINARY_OP_GE	= 1 << 8,				

	BINARY_OP_ADDITION	= 1 << 9,
	BINARY_OP_SUBTRACTION	= 1 << 10
};

struct ast_expr;

struct ast_expr *


@@ 87,6 61,8 @@ ast_expr_member_root(struct ast_expr *);
char *
ast_expr_member_field(struct ast_expr *);

enum ast_unary_operator;

struct ast_expr *
ast_expr_unary_create(struct ast_expr *, enum ast_unary_operator);



@@ 99,6 75,19 @@ ast_expr_unary_isdereference(struct ast_expr *);
struct ast_expr *
ast_expr_unary_operand(struct ast_expr *);

enum ast_binary_operator {
	BINARY_OP_EQ	= 1 << 0,
	BINARY_OP_NE	= 1 << 1,

	BINARY_OP_LT	= 1 << 2,
	BINARY_OP_GT	= 1 << 3,
	BINARY_OP_LE	= 1 << 4,
	BINARY_OP_GE	= 1 << 5,

	BINARY_OP_ADDITION	= 1 << 6,
	BINARY_OP_SUBTRACTION	= 1 << 7,
};

struct ast_expr *
ast_expr_binary_create(struct ast_expr *e1, enum ast_binary_operator,
		struct ast_expr *e2);

M src/ast/expr/expr.c => src/ast/expr/expr.c +0 -4
@@ 406,10 406,6 @@ static void
ast_expr_binary_str_build(struct ast_expr *expr, struct strbuilder *b)
{
	const char *opstr[] = {
		[BINARY_OP_EQV]		= "===",
		[BINARY_OP_IMPL]	= "==>",
		[BINARY_OP_FLLW]	= "<==",

		[BINARY_OP_EQ]		= "==",
		[BINARY_OP_NE]		= "!=",


M src/ast/expr/expr.h => src/ast/expr/expr.h +8 -1
@@ 33,7 33,14 @@ struct ast_expr {
		struct {
			int inc, pre;
		} incdec;
		enum ast_unary_operator unary_op;
		enum ast_unary_operator {
			UNARY_OP_ADDRESS		= 1 << 0,
			UNARY_OP_DEREFERENCE		= 1 << 1,
			UNARY_OP_POSITIVE		= 1 << 2,
			UNARY_OP_NEGATIVE		= 1 << 3,
			UNARY_OP_ONES_COMPLEMENT	= 1 << 4,
			UNARY_OP_BANG			= 1 << 5,
		} unary_op;
		struct {
			enum ast_binary_operator op;
			struct ast_expr *e1, *e2;

M src/ast/gram.y => src/ast/gram.y +5 -17
@@ 5,6 5,7 @@
#include <string.h>
#include <assert.h>
#include "ast.h"
#include "expr/expr.h"
#include "gram_util.h"
#include "lex.h"
#include "util.h"


@@ 103,7 104,6 @@ variable_array_create(struct ast_variable *v)

%token IDENTIFIER CONSTANT CHAR_LITERAL STRING_LITERAL SIZEOF
%token PTR_OP INC_OP DEC_OP LEFT_OP RIGHT_OP LE_OP GE_OP EQ_OP NE_OP
%token EQV_OP IMPL_OP FLLW_OP
%token ISDEALLOCAND_OP
%token AND_OP OR_OP MUL_ASSIGN DIV_ASSIGN MOD_ASSIGN ADD_ASSIGN
%token SUB_ASSIGN LEFT_ASSIGN RIGHT_ASSIGN AND_ASSIGN


@@ 168,13 168,13 @@ variable_array_create(struct ast_variable *v)
%type <block> block compound_statement compound_verification_statement
%type <block> optional_compound_verification
%type <block_statement> block_statement
%type <binary_operator> connective equality_operator relational_operator
%type <binary_operator> equality_operator relational_operator
%type <boolean> struct_or_union
%type <declarator> declarator init_declarator init_declarator_list
%type <direct_function_declarator> direct_function_declarator

%type <expr> expression assignment_expression conditional_expression unary_expression
%type <expr> justified_expression postfix_expression primary_expression
%type <expr> postfix_expression primary_expression
%type <expr> logical_or_expression logical_and_expression inclusive_or_expression
%type <expr> exclusive_or_expression and_expression equality_expression
%type <expr> relational_expression shift_expression additive_expression


@@ 362,21 362,9 @@ logical_or_expression
	/*| logical_or_expression OR_OP logical_and_expression*/
	;

connective
	: EQV_OP 	{ $$ = BINARY_OP_EQV; }
	| IMPL_OP	{ $$ = BINARY_OP_IMPL; }
	/*| FLLW_OP	{ $$ = BINARY_OP_FLLW; }*/
	;

justified_expression
	: logical_or_expression
	| justified_expression connective justification logical_or_expression
		{ $$ = ast_expr_binary_create($1, $2, $4); }
	;

conditional_expression
	: justified_expression
	/*| justified_expression '?' expression ':' conditional_expression*/
	: logical_or_expression
	/*| logical_or_expression '?' expression ':' conditional_expression*/
	;

assignment_expression

M src/ast/lex.l => src/ast/lex.l +0 -3
@@ 105,9 105,6 @@ L?\"(\\.|[^\\"])*\"	{ count(); return(STRING_LITERAL); }
">="			{ count(); return(GE_OP); }
"=="			{ count(); return(EQ_OP); }
"!="			{ count(); return(NE_OP); }
"==="			{ count(); return(EQV_OP); }
"==>"			{ count(); return(IMPL_OP); }
"<=="			{ count(); return(FLLW_OP); }
";"			{ count(); return(';'); }
("{"|"<%")		{ count(); return('{'); }
("}"|"%>")		{ count(); return('}'); }