Jump to content

yacc errors

- - - - -

  • Please log in to reply
No replies to this topic

#1
ahmed

ahmed

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 304 posts
Well i have been working from past 5-6hrs and i can't get these errors from the grammar
it has errors
yacc: 1 rule never reduced
yacc: 5 shift/reduce conflicts, 6 reduce/reduce conflicts.

program:
        declaration_list        
        ;

declaration_list:
        declaration_list declaration
        | declaration
        ;

declaration:
        var_declaration
        | fun_declaration
        ;

var_declaration:
        type_specifier ID SEMICOLON
        | type_specifier ID OPENAB NUM CLOSEAB SEMICOLON
        ;        
        
type_specifier:
        INTEGER
        | VOID
        ;
        
fun_declaration:
        type_specifier ID OPENB params CLOSEB compound_stmt
        ;

params:
        param_list
        | VOID    
        ;
        
param_list:
        param_list COMMA param
        | param
        ;

param:
        type_specifier ID
        | type_specifier ID OPENAB CLOSEAB
        ;

compound_stmt:
        OPENSB local_declarations statement_list CLOSESB
        ;
        
local_declarations:
        local_declarations var_declaration
        | 
        ;
        
statement_list:
        statement_list statement
        |
        ;
        
statement:
        expression_stmt
        | compound_stmt
        | selection_stmt
        | iteration_stmt
        | return_stmt
        ;
        
expression_stmt:
        expression SEMICOLON
        | SEMICOLON
        ;
        
selection_stmt:
        IF OPENB expression CLOSEB statement
        | IF OPENB expression CLOSEB statement ELSE statement
        ;
        
iteration_stmt:
            WHILE OPENB expression CLOSEB statement
            ;        
        
return_stmt:
            RETURN SEMICOLON
            | RETURN SEMICOLON expression
            ;    

expression:
            var EQUAL expression
            | simple_expression
            ;    

var:
            ID
            |ID OPENAB expression CLOSEAB
            ;    

simple_expression:
            additive_expression relop additive_expression
            | additive_expression
            ;    

relop:
            LESSE
            |LESS
            |GREATER
            |GREATERE
            |DEQUAL
            |NOTE
            ;        

additive_expression:
            additive_expression addop term
            |term
            ;        

addop :
            |PLUS
            |MINUS
            ;        

term:
            term mulop factor
            | factor
            ;

mulop:
            MUL
            | DIV
            ;
            
factor:
            OPENB expression CLOSEB
            |var
            |call
            |NUM
            ;
    
call:
            ID OPENB args CLOSEB
            ;    
            
args:
            arg_list
            |
            ;
            
arg_list:
            arg_list COMMA expression
            | expression
            ;
        
%%

I don't know where the problem is can anyone please please help me out :cursing:




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users