for (alloclen = 8; alloclen < sizeof(long) + sizeof(*gstr) + len;
alloclen *= 2);
- gstr = malloc(alloclen);
+ gstr = zmalloc(alloclen);
+ if (!gstr) {
+ goto end;
+ }
cds_list_add(&gstr->gc, &parser_ctx->allocated_strings);
gstr->alloclen = alloclen;
+end:
return gstr;
}
struct filter_ast *ast = filter_parser_get_ast(scanner);
struct filter_node *node;
- node = malloc(sizeof(*node));
+ node = zmalloc(sizeof(*node));
if (!node)
return NULL;
memset(node, 0, sizeof(*node));
struct filter_ast *ast = filter_parser_get_ast(scanner);
struct filter_node *node;
- node = malloc(sizeof(*node));
+ node = zmalloc(sizeof(*node));
if (!node)
return NULL;
memset(node, 0, sizeof(*node));
{
struct filter_ast *ast;
- ast = malloc(sizeof(*ast));
+ ast = zmalloc(sizeof(*ast));
if (!ast)
return NULL;
memset(ast, 0, sizeof(*ast));
yydebug = filter_parser_debug;
- parser_ctx = malloc(sizeof(*parser_ctx));
+ parser_ctx = zmalloc(sizeof(*parser_ctx));
if (!parser_ctx)
return NULL;
memset(parser_ctx, 0, sizeof(*parser_ctx));
%type <gs> s_char s_char_sequence c_char c_char_sequence
%type <n> primary_expression
+%type <n> prefix_expression
+%type <n> prefix_expression_rec
%type <n> postfix_expression
%type <n> unary_expression
%type <n> unary_operator
%type <n> logical_and_expression
%type <n> logical_or_expression
%type <n> expression
+%type <n> identifiers
%%
}
;
-primary_expression
- : IDENTIFIER
- {
- $$ = make_node(parser_ctx, NODE_EXPRESSION);
- $$->u.expression.type = AST_EXP_IDENTIFIER;
- $$->u.expression.u.identifier = yylval.gs->s;
- }
- | GLOBAL_IDENTIFIER
- {
- $$ = make_node(parser_ctx, NODE_EXPRESSION);
- $$->u.expression.type = AST_EXP_GLOBAL_IDENTIFIER;
- $$->u.expression.u.identifier = yylval.gs->s;
- }
-
- | DECIMAL_CONSTANT
+primary_expression:
+ DECIMAL_CONSTANT
{
$$ = make_node(parser_ctx, NODE_EXPRESSION);
$$->u.expression.type = AST_EXP_CONSTANT;
}
;
-postfix_expression
- : primary_expression
- { $$ = $1; }
- | postfix_expression DOT IDENTIFIER
+identifiers
+ : IDENTIFIER
{
$$ = make_node(parser_ctx, NODE_EXPRESSION);
$$->u.expression.type = AST_EXP_IDENTIFIER;
+ $$->u.expression.u.identifier = yylval.gs->s;
+ }
+ | GLOBAL_IDENTIFIER
+ {
+ $$ = make_node(parser_ctx, NODE_EXPRESSION);
+ $$->u.expression.type = AST_EXP_GLOBAL_IDENTIFIER;
+ $$->u.expression.u.identifier = yylval.gs->s;
+ }
+ ;
+
+prefix_expression_rec
+ : LSBRAC unary_expression RSBRAC
+ {
+ $$ = $2;
+ }
+ | LSBRAC unary_expression RSBRAC prefix_expression_rec
+ {
+ $$ = $2;
+ $$->u.expression.pre_op = AST_LINK_BRACKET;
+ $$->u.expression.prev = $4;
+ }
+ ;
+
+prefix_expression
+ : identifiers
+ {
+ $$ = $1;
+ }
+ | identifiers prefix_expression_rec
+ {
+ $$ = $1;
+ $$->u.expression.pre_op = AST_LINK_BRACKET;
+ $$->u.expression.next_bracket = $2;
+ }
+ ;
+
+postfix_expression
+ : prefix_expression
+ {
+ $$ = $1;
+ }
+ | postfix_expression DOT prefix_expression
+ {
+ $$ = $3;
$$->u.expression.post_op = AST_LINK_DOT;
- $$->u.expression.u.identifier = $3->s;
$$->u.expression.prev = $1;
}
- | postfix_expression RARROW IDENTIFIER
+ | postfix_expression RARROW prefix_expression
{
- $$ = make_node(parser_ctx, NODE_EXPRESSION);
- $$->u.expression.type = AST_EXP_IDENTIFIER;
+ $$ = $3;
$$->u.expression.post_op = AST_LINK_RARROW;
- $$->u.expression.u.identifier = $3->s;
$$->u.expression.prev = $1;
}
;
unary_expression
: postfix_expression
{ $$ = $1; }
+ | primary_expression
+ { $$ = $1; }
| unary_operator unary_expression
{
$$ = $1;
| NOT_BIN
{
$$ = make_node(parser_ctx, NODE_UNARY_OP);
- $$->u.unary_op.type = AST_UNARY_BIN_NOT;
+ $$->u.unary_op.type = AST_UNARY_BIT_NOT;
}
;
{ $$ = $1; }
| shift_expression LEFT_OP additive_expression
{
- $$ = make_op_node(parser_ctx, AST_OP_LSHIFT, $1, $3);
+ $$ = make_op_node(parser_ctx, AST_OP_BIT_LSHIFT, $1, $3);
}
| shift_expression RIGHT_OP additive_expression
{
- $$ = make_op_node(parser_ctx, AST_OP_RSHIFT, $1, $3);
+ $$ = make_op_node(parser_ctx, AST_OP_BIT_RSHIFT, $1, $3);
}
;
{ $$ = $1; }
| and_expression AND_BIN equality_expression
{
- $$ = make_op_node(parser_ctx, AST_OP_BIN_AND, $1, $3);
+ $$ = make_op_node(parser_ctx, AST_OP_BIT_AND, $1, $3);
}
;
{ $$ = $1; }
| exclusive_or_expression XOR_BIN and_expression
{
- $$ = make_op_node(parser_ctx, AST_OP_BIN_XOR, $1, $3);
+ $$ = make_op_node(parser_ctx, AST_OP_BIT_XOR, $1, $3);
}
;
{ $$ = $1; }
| inclusive_or_expression OR_BIN exclusive_or_expression
{
- $$ = make_op_node(parser_ctx, AST_OP_BIN_OR, $1, $3);
+ $$ = make_op_node(parser_ctx, AST_OP_BIT_OR, $1, $3);
}
;