[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3656
  • Last Modified:

warning: passing argument .. makes integer from pointer without a cast

Hello,

Can someone explain me why do i get the following warnings ?


Thanks in advnace for any help !
0
unknown_
Asked:
unknown_
  • 2
2 Solutions
 
unknown_Author Commented:
mygrammar.y: In function make_variable:
mygrammar.y:54: warning: assignment makes pointer from integer without a cast
mygrammar.y: In function yyparse:
mygrammar.y:136: warning: passing argument 1 of make_operator makes pointer from integer without a cast
mygrammar.y:136: warning: passing argument 3 of make_operator makes pointer from integer without a cast
mygrammar.y:136: warning: assignment makes integer from pointer without a cast
mygrammar.y:137: warning: passing argument 1 of make_operator makes pointer from integer without a cast
mygrammar.y:137: warning: passing argument 3 of make_operator makes pointer from integer without a cast
mygrammar.y:137: warning: assignment makes integer from pointer without a cast
mygrammar.y:143: warning: passing argument 1 of make_operator makes pointer from integer without a cast
mygrammar.y:143: warning: passing argument 3 of make_operator makes pointer from integer without a cast
mygrammar.y:143: warning: assignment makes integer from pointer without a cast
mygrammar.y:144: warning: passing argument 1 of make_operator makes pointer from integer without a cast
mygrammar.y:144: warning: passing argument 3 of make_operator makes pointer from integer without a cast
mygrammar.y:144: warning: assignment makes integer from pointer without a cast
mygrammar.y:149: warning: assignment makes integer from pointer without a cast
mygrammar.y:150: warning: passing argument 1 of make_number makes integer from pointer without a cast
mygrammar.y:150: warning: assignment makes integer from pointer without a cast
mygrammar.y:151: warning: passing argument 1 of make_variable makes integer from pointer without a cast
mygrammar.y:151: warning: assignment makes integer from pointer without a cast
mygrammar.y:167: warning: passing argument 1 of make_variable makes integer from pointer without a cast
mygrammar.y:167: warning: assignment from incompatible pointer type
mygrammar.y:170: warning: passing argument 1 of make_variable makes integer from pointer without a cast
mygrammar.y:170: warning: assignment from incompatible pointer type
mygrammar.y:171: warning: passing argument 1 of make_variable makes integer from pointer without a cast
mygrammar.y:171: warning: assignment from incompatible pointer type

%{
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
	
#define YYDEBUG 1
 
extern int  yyparse();
 extern int yylex();
 extern int line  ;
 
 
extern FILE *yyin;	
 
int yywrap()
 {
    return 1;
 }
   
void yyerror( const char *msg )
{
  printf("Line %d: %s\n",line, msg); 
}
 
enum treetype {operator_node, number_node, variable_node};
 typedef struct tree {
   enum treetype nodetype;
   union {
     struct {struct tree *left, *right; char operator;} an_operator;
     int ival;
     char * sval;
   } body;
 } tree;
 
 static tree *make_operator (tree *l, char o, tree *r) {
   tree *result= (tree*) malloc (sizeof(tree));
   result->nodetype= operator_node;
   result->body.an_operator.left= l;
   result->body.an_operator.operator= o;
   result->body.an_operator.right= r;
   return result;
 }
 
 static tree *make_number (int n) {
   tree *result= (tree*) malloc (sizeof(tree));
   result->nodetype= number_node;
   result->body.ival= n;
   return result;
 }
 
 static tree *make_variable (char v) {
   tree *result= (tree*) malloc (sizeof(tree));
   result->nodetype= variable_node;
   result->body.sval= v;
   return result;
 }
 
 
%}
 
%start goal
 
%union {
	int ival;
	char * sval;
        tree * t;
}
 
%token <sval> IDENTIFIER
%token <sval> VARIABLE
%token <ival> INTEGER
 /*%token <ival> FLOAT*/
%token <sval> STRING
%token <sval> LITERAL
%token <sval> UNKNOWN 
%token <sval> PLUS
%token <sval> MINUS
%token <sval> TIMES
%token <sval> SLASH
%token <sval> LPAREN
%token <sval> RPAREN
%token <sval> SEMICOLON
%token <sval> COMMA
%token <sval> EQL
%token <sval> OR 
%token <sval> ORR
%token <sval> AND
%token <sval> ANDD
 
 
/* keywords */
%token <sval> IF
%token <sval> ELSE
%token <sval> DO
%token <sval> INT
%token <sval> RETURN
%token <sval> VOID
%token <sval> FLOAT
%token <sval> WHILE
 
%type <t> goal
%type <ival> expression
%type <ival> term 
%type <ival> factor 
%type <sval> ifstatement
%type <sval> whilestatement
%type <sval> dostatement
%type <sval> variable_list
%type <sval> variable 
 
 
 
%%
 
goal	: statement_list;
        ;
 
statement_list: { /*empty*/ }
                | statement_list statement   
		;
 
statement : declaration_statement
          | ifstatement 
          | whilestatement
          | variable '=' expression SEMICOLON 
          | dostatement 
          |returnstatement 
          ;
 
declaration_statement : INT variable_list SEMICOLON {printf("INT_VARIABLE\n");}
                      | FLOAT variable_list SEMICOLON {printf("FLOAT_VARIABLE\n");}
                      ;
 
 
 
expression		:	term '+' term {printf("ADDITION\n");} {$$ = make_operator($1, '+', $3);}
|	term '-' term {printf("SUBTRACTION\n");} {$$ = make_operator ($1, '-' ,$3);}
|	term {printf("\n");}  {$$ = $1;}   ;
 
 
 
 
term			:	factor '*' factor  {printf("MULTIPLICATION\n");} {$$ = make_operator($1,'*', $3);}
|	factor '/' factor  {printf("DIVISION\n");} {$$ = make_operator($1, '/', $3);} 
|	factor {printf("\n");}  {$$ = $1;}  ;
 
 
factor			:	variable {printf("rule 7\n");} 
|	INTEGER {printf("integer\n");} {$$ = make_number($1);} 
|	FLOAT {printf("float\n");}  {$$ = make_number($1);}
|	STRING {printf("string\n");}  {$$ = make_variable($1);}
|	'(' expression ')' {$$ = $2;} ;
 
ifstatement		:	IF '(' expression ')' goal ELSE goal SEMICOLON {printf("rule: IF_ELSE_STATEMENT\n");}
|	IF '(' expression ')' goal {printf("rule: IF_STATEMENT\n");};
 
whilestatement	:	WHILE '(' expression ')' goal {printf("rule: WHILE_STATEMENT\n");};
	
		
dostatement : DO '(' expression ')' WHILE '(' expression ')' SEMICOLON   {printf("rule DO_STATEMENT\n");} ;
 
returnstatement : RETURN { } SEMICOLON   {printf("rule RETURN_STATEMENT\n");} ;
| RETURN factor SEMICOLON {printf("rule : RETURN 2\n");} 
;
 
 
variable : VARIABLE {printf("rule: variable2\n");} {$$= make_variable($1); };
 
	
variable_list : variable {printf("rule : variable1\n");}  {$$= make_variable($1); }
|  variable_list ',' variable {printf("rule: multvar\n");} {$$ = make_variable($1);} //	variable ',' variable_list {printf("rule: var,var\n");}  ;
;
 
%%
 
#include "lex.yy.c"
 
main(int argc,char *argv[])
{
 if(argc<1)
   {
    printf("Please specify the input file\n");
    exit(0);
   }
 FILE *fp=fopen(argv[1],"r");
 if(!fp)
   {
     printf("couldn't open file for reading\n");
     exit(0);
   }
 yyin=fp;
 
 do {
   yyparse();
 }while (!feof(yyin));
 
 fclose(fp);
}
 
 
 
 
 static void printtree (tree *t, int level) {
 #define step 4
   if (t)
     switch (t->nodetype)
     {
       case operator_node:
        printtree (t->body.an_operator.right, level+step);
        printf ("%*c%c\n", level, ' ', t->body.an_operator.operator);
        printtree (t->body.an_operator.left, level+step);
        break;
       case number_node:
        printf ("%*c%d\n", level, ' ', t->body.ival);
        break;
       case variable_node:
        printf ("%*c%c\n", level, ' ', t->body.sval);
     }
 }
 
 

Open in new window

0
 
Kent OlsenData Warehouse Architect / DBACommented:
Hi unknown,

Take a look at lines 31 and 54.

At line 31 you declare sval to be a pointer to a character.

At line 54 you use sval as if it were a character.

If you want to save the character, line 31 needs to change.  If you want to save the pointer to a character, all of the lines that threw the "assignment makes pointer from integer without a cast" error will need to change.


Good Luck,
Kent
0
 
ozoCommented:
make_operator takes pointer arguments, but you are passing it integers
 make_number takes an integer argument, but you are passing it a pointer
0
 
unknown_Author Commented:
.
0

Featured Post

Will You Be GDPR Compliant by 5/28/2018?

GDPR? That's a regulation for the European Union. But, if you collect data from customers or employees within the EU, then you need to know about GDPR and make sure your organization is compliant by May 2018. Check out our preparation checklist to make sure you're on track today!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now