how to avoid execution in a block in bison

so i am facing a problem where it executes the PRINT command though return value is false
eg:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>func main(){
a -> 9;
print ( a );
if (a > 10){
print ( 99 );
}
}
</code>
<code>func main(){ a -> 9; print ( a ); if (a > 10){ print ( 99 ); } } </code>
func main(){
    a -> 9;
    print ( a );
    if (a > 10){
        print ( 99 );
    }   
}

so 99 shouldn’t be printed as expected but it prints , how can i avoid it?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Result: 9
Result: 99
statements : empty
statements : statement statements
Condition false, skipping if block
statements : empty
statements : statement statements
statements : statement statements
statements : statement statements
function : FUNC IDENT LPAR RPAR LCURL statements RCURL
functions : empty
functions : function functions
program : functions
</code>
<code>Result: 9 Result: 99 statements : empty statements : statement statements Condition false, skipping if block statements : empty statements : statement statements statements : statement statements statements : statement statements function : FUNC IDENT LPAR RPAR LCURL statements RCURL functions : empty functions : function functions program : functions </code>
Result: 9
Result: 99
statements : empty
statements : statement statements
Condition false, skipping if block
statements : empty
statements : statement statements
statements : statement statements
statements : statement statements
function : FUNC IDENT LPAR RPAR LCURL statements RCURL
functions : empty
functions : function functions
program : functions
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code> %{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "variables.h"
#define MAX_VARS 100
typedef struct {
char *name;
int value;
} Var;
Var vars[MAX_VARS];
int var_count = 0;
int yylex();
void yyerror(const char *s);
int get_var_value(const char *name);
void set_var_value(const char *name, int value);
%}
%union {
int ival;
char *sval;
}
%token <sval> IDENTIFIER
%token <ival> INTEGER
%token FUNC
%token LPAR
%token RPAR
%token LCURL
%token RCURL
%token PRINT
%token SEMICOLON
%token PLUS
%token IS
%token MINUS
%token MULTIPLY
%token DIVIDE
%token GREATER
%token LESS
%token EQUAL
%token DOUBLE_EQUAL
%token IF
%left PLUS MINUS
%left MULTIPLY DIVIDE
%type <ival> expression
%type <ival> statement
%type <ival> statements
%type <ival> function
%type <ival> functions
%type <ival> program
%type <ival> var_decl
%type <ival> condition
%start program
%%
program : functions { printf("program : functionsn"); }
;
functions : function functions { printf("functions : function functionsn"); }
| /* empty */ { printf("functions : emptyn"); }
;
function : FUNC IDENTIFIER LPAR RPAR LCURL statements RCURL { printf("function : FUNC IDENT LPAR RPAR LBIG statements RBIGn"); }
;
statements : statement statements { printf("statements : statement statementsn"); }
| /* empty */ { printf("statements : emptyn"); }
;
statement : PRINT LPAR expression RPAR SEMICOLON { printf("Result: %dn", $3); }
| var_decl SEMICOLON {}
| IF LPAR condition RPAR LCURL statements RCURL {
if ($3 == 1) {
printf("Condition truen");
} else if ( $3 == 0) {
printf("Condition false,skipping if blockn");
//skip the {} block of the if condition
}
}
;
condition : expression GREATER expression { $$ = $1 > $3; }
| expression LESS expression { $$ = $1 < $3; }
| expression DOUBLE_EQUAL expression { $$ = $1 == $3; }
;
/* toke $1 ** toke $3 */
var_decl : IDENTIFIER IS INTEGER { set_var_value($1, $3); $$ = $3; }
;
expression : expression PLUS expression { $$ = $1 + $3; }
| expression MINUS expression { $$ = $1 - $3; }
| expression MULTIPLY expression { $$ = $1 * $3; }
| expression DIVIDE expression { $$ = $1 / $3; }
| INTEGER { $$ = $1; }
| IDENTIFIER { $$ = get_var_value($1); }
;
%%
int main(void) {
return yyparse();
}
void yyerror(const char *s) {
printf("ERROR: %sn", s);
}
</code>
<code> %{ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "variables.h" #define MAX_VARS 100 typedef struct { char *name; int value; } Var; Var vars[MAX_VARS]; int var_count = 0; int yylex(); void yyerror(const char *s); int get_var_value(const char *name); void set_var_value(const char *name, int value); %} %union { int ival; char *sval; } %token <sval> IDENTIFIER %token <ival> INTEGER %token FUNC %token LPAR %token RPAR %token LCURL %token RCURL %token PRINT %token SEMICOLON %token PLUS %token IS %token MINUS %token MULTIPLY %token DIVIDE %token GREATER %token LESS %token EQUAL %token DOUBLE_EQUAL %token IF %left PLUS MINUS %left MULTIPLY DIVIDE %type <ival> expression %type <ival> statement %type <ival> statements %type <ival> function %type <ival> functions %type <ival> program %type <ival> var_decl %type <ival> condition %start program %% program : functions { printf("program : functionsn"); } ; functions : function functions { printf("functions : function functionsn"); } | /* empty */ { printf("functions : emptyn"); } ; function : FUNC IDENTIFIER LPAR RPAR LCURL statements RCURL { printf("function : FUNC IDENT LPAR RPAR LBIG statements RBIGn"); } ; statements : statement statements { printf("statements : statement statementsn"); } | /* empty */ { printf("statements : emptyn"); } ; statement : PRINT LPAR expression RPAR SEMICOLON { printf("Result: %dn", $3); } | var_decl SEMICOLON {} | IF LPAR condition RPAR LCURL statements RCURL { if ($3 == 1) { printf("Condition truen"); } else if ( $3 == 0) { printf("Condition false,skipping if blockn"); //skip the {} block of the if condition } } ; condition : expression GREATER expression { $$ = $1 > $3; } | expression LESS expression { $$ = $1 < $3; } | expression DOUBLE_EQUAL expression { $$ = $1 == $3; } ; /* toke $1 ** toke $3 */ var_decl : IDENTIFIER IS INTEGER { set_var_value($1, $3); $$ = $3; } ; expression : expression PLUS expression { $$ = $1 + $3; } | expression MINUS expression { $$ = $1 - $3; } | expression MULTIPLY expression { $$ = $1 * $3; } | expression DIVIDE expression { $$ = $1 / $3; } | INTEGER { $$ = $1; } | IDENTIFIER { $$ = get_var_value($1); } ; %% int main(void) { return yyparse(); } void yyerror(const char *s) { printf("ERROR: %sn", s); } </code>
    %{
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "variables.h"

    #define MAX_VARS 100

    typedef struct {
        char *name;
        int value;
    } Var;

    Var vars[MAX_VARS];
    int var_count = 0;

    int yylex();
    void yyerror(const char *s);

    int get_var_value(const char *name);
    void set_var_value(const char *name, int value);
    %}

    %union {
        int ival;
        char *sval;
    }

    %token <sval> IDENTIFIER
    %token <ival> INTEGER
    %token FUNC
    %token LPAR
    %token RPAR
    %token LCURL
    %token RCURL
    %token PRINT
    %token SEMICOLON
    %token PLUS
    %token IS
    %token MINUS
    %token MULTIPLY
    %token DIVIDE
    %token GREATER
    %token LESS
    %token EQUAL
    %token DOUBLE_EQUAL
    %token IF

    %left PLUS MINUS
    %left MULTIPLY DIVIDE

    %type <ival> expression
    %type <ival> statement
    %type <ival> statements
    %type <ival> function
    %type <ival> functions
    %type <ival> program
    %type <ival> var_decl
    %type <ival> condition 
    %start program

    %%

    program : functions { printf("program : functionsn"); }
            ;

    functions : function functions { printf("functions : function functionsn"); }
            | /* empty */ { printf("functions : emptyn"); }
            ;

    function : FUNC IDENTIFIER LPAR RPAR LCURL statements RCURL { printf("function : FUNC IDENT LPAR RPAR LBIG statements RBIGn"); }
            ;

    statements : statement statements { printf("statements : statement statementsn"); }
            | /* empty */ { printf("statements : emptyn"); }
            ;

    statement : PRINT LPAR expression RPAR SEMICOLON { printf("Result: %dn", $3); }
            | var_decl SEMICOLON {}
            | IF LPAR condition RPAR LCURL statements RCURL {
                if ($3 == 1) {
                    printf("Condition truen");
                } else if ( $3 == 0) {
                    printf("Condition false,skipping if blockn");                
                    //skip the {} block of the if condition 
                }
            }
            ;

    condition : expression GREATER expression { $$ = $1 > $3; }
            | expression LESS expression { $$ = $1 < $3; }
            | expression DOUBLE_EQUAL expression { $$ = $1 == $3; }
            ;
                /* toke $1      **   toke $3 */
    var_decl : IDENTIFIER IS INTEGER { set_var_value($1, $3); $$ = $3; }
            ;

    expression : expression PLUS expression { $$ = $1 + $3; }
            | expression MINUS expression { $$ = $1 - $3; }
            | expression MULTIPLY expression { $$ = $1 * $3; }
            | expression DIVIDE expression { $$ = $1 / $3; }
            | INTEGER { $$ = $1; }
            | IDENTIFIER { $$ = get_var_value($1); }
            ;

    %%

    int main(void) {
        return yyparse();
    }

    void yyerror(const char *s) {
        printf("ERROR: %sn", s);
    }

I am noob at coding and i am just trying to learn bison and flex , if the condition is false not to execute the statements inside the if block
and got to next block
eg:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>func main(){
a -> 9;
print ( a );
if (a > 10){
print ( 99 );
}
b -> 10;
print( b );
}
</code>
<code>func main(){ a -> 9; print ( a ); if (a > 10){ print ( 99 ); } b -> 10; print( b ); } </code>
func main(){
    a -> 9;
    print ( a );
    if (a > 10){
        print ( 99 );
    }   
b -> 10;
print( b );
}

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật