Hi, I want to ask you something related to the behaviour i found in C, actually compiled thru GCC 3.2.2 The problem is or could be in the semantic behaviour. ~~ ~~~~~~~~ Please note the following excerpt from the attached file program symdef.c ~~~~~~~~~~~~~~~~~~~ ~~~~~~~~ void printSymtab(void) { Symtab *tptr; Symtab t; puts("**************\n\t\tSymTable**************"); puts(" Name PIB PIH BlkNo "); printf("%u", t); if (t) ; if (tptr); if (*tptr); return; } `````````````````````````````````````````````` Compilation ~~~~~~~~~~~ [u02139@cs123]$ gcc -Wall symdef.c symdef.c: In function `printSymtab': symdef.c:84: invalid operands to binary != symdef.c:88: invalid operands to binary != [u02139@cs123]$ `````````````````````````````````````````````` The error/semantic behaviour to be pointed out is, when we print the variable "t" it is allowed, but when comparison is done implicit or explicit it gives an error. void printSymtab(void) { Symtab *tptr; Symtab t; puts("**************\n\t\tSymTable**************"); puts(" Name PIB PIH BlkNo "); printf("%u", t); <-------------ALLOWED if (t) ; <-------------NOT ALLOWED (line 84) if (tptr); <-------------This is OKAY if (*tptr); <---------NOT ALLOWED/possibly it is error (line 88) return; } Why so ? could please explain me this semantic behaviour. When allowed in one case can also be implemented/used in other case. Actually it shd be allowed in either cases. I'm doing CC(compiler construction) course in our department and was working out for Tiger language. I just started writing code for the semantic analysis phase, and during compilation such error was encountered. Actually, line 88 was done by mistake, but helped get into these other things. The files used for compilation are attached. Pleaze help me, Waiting for your response. Bye & take care. -- -SilverZ. -- Always forgive your enemies - Nothing annoys them so much. -------------------------------------- Silver Chandrakant L MCA (Batch 2002) IInd year University of Pune. India. chandrakant_silver@xxxxxxxxxxx
#ifndef __SYMDEF_H__ #define __SYMDEF_H__ #define HASHTAB_SIZE 50 /*********SYMTAB*****************************/ typedef struct symtab_tag /* Symbol Table */ { char *symname; /* symbol name */ unsigned pib; /* previous in block */ unsigned pih; /* previous in hash */ unsigned blkno; /* block no */ struct symtab_tag *next; }Symtab; /*********BLKTAB*****************************/ typedef struct blktab_tag /* Block Table */ { char *blkname; /* block name */ unsigned lastentry; /* last entry */ struct blktab_tag *next; }Blktab; /*********STACK*****************************/ typedef struct stack_node_tag /* Stack */ { int data; struct stack_node_tag *next; }Stack; /*********FUNCTIONs*****************************/ void initStack(void); int isEmpty(void); int push(int data); int pop(void); #endif
#include <stdlib.h> #include <stdio.h> #include <string.h> #include "symdef.h" #define NEWNODE (Stack *)malloc(sizeof(Stack)) int hashtab[HASHTAB_SIZE]; Stack *top=NULL; Symtab *head; void initStack(void) { top=NULL; return; } int isEmpty(void) { return(top == NULL ? 1 : 0); } int push(int data) { Stack *t; t=NEWNODE; t->data=data; t->next=top; top=t; return 0; } int pop(void) { Stack *t; int data; if (isEmpty()) return -1; data=top->data; t=top; top=top->next; return data; } void initHash(void) { bzero(&hashtab, sizeof(hashtab)); return; } /* * str : hash string * Returns : hashed value */ unsigned hash(char *str) { return(str ? (str[0] * ( str[0] && str[1] ? str[1] : str[0]) % HASHTAB_SIZE) : 0); } Symtab *addSym(char *sym) { return NULL; } void printSymtab(void) { Symtab *tptr; Symtab t; puts("**************\n\t\tSymTable**************"); puts(" Name PIB PIH BlkNo "); printf("%u", t); if (t) ; if (tptr); if (*tptr); return; } int main(void) { return 0; }