سؤال

This is my code in yacc:

%{
#include <stdio.h>
#include <stdbool.h>

%}
%code requires{
struct Node {
char* nodeValue;         
 struct Node* leftOperand;
 struct Node* rightOperand;    
 char* nodeType;
  };
}
%union {

char *string;
Node *node;  <---  error here
}

1. I dont know why it showed an error: unknown type name ‘Node’ even I declared Node above. If I put struct before it, it's fine. And I have to put struct before every Node.

2.If I change char into string in the struct it shows unknown type name ‘string’ too. it seems I cannot use any type of data other than char, int.

Edit: if I write 2 function returning the Node type, it means that I have to put struct before them, and it shows conflicting types error.

Update: I actually compiled my code with C, that's why it showed these errors. Thank you guys for these responses below.

هل كانت مفيدة؟

المحلول

For C it needs to be

struct Node *node;
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top