Lex and Yacc declared type -- Getting an error

Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
anonim
Messages
39
Reaction score
2
in .y code:

Code:
%union{
    int ival;
    int *ivals;
    char id[20];
    char *str;
    bool *b;
}
%start START

%token COMMENT OP_PLUS OP_MINUS OP_DIV OP_MULT OP_OP OP_CP OP_DBLMULT OP_OC OP_CC OP_COMMA KW_AND KW_OR KW_NOT KW_EQUAL KW_LESS
KW_NIL KW_LIST KW_APPEND KW_CONCAT KW_SET KW_DEFFUN KW_FOR KW_IF KW_EXIT KW_DEFVAR KW_WHILE
KW_LOAD KW_DISP KW_TRUE KW_FALSE NEWLINE
FLOAT_NUMBER LISTOP%token <ival> LIMITED_VALUE
%token <id> IDENTIFIER
%token <str> FLE
%token <ival> NUMBER

%type <ival> START
%type <ival> EXPI
%type <ival> EXPB
%type <ivals> VALUES
%type <ivals> EXPLISTI
%type <ivals> LISTVALUE
%type <b> BinaryValue

in l code:

Code:
[[:alpha:]][[:alnum:]]*   {strcpy(yylval.id, yytext); return IDENTIFIER;}
[[1-9][:digit:]]+         {yylval.ival = atoi(yytext); return VALUE;}
{LIMITED_VALUE}                   {yylval.ival = atoi(yytext); return VALUE;}

I got an error:

error: $3 of ‘EXPI’ has no declared type $$=$3;

code blog with the line where I got the error:
Code:
| OP_OP KW_WHILE OP_OP EXPB OP_CP EXPLISTI OP_CP{
    $$=$3;
    if(!$3){
        listIndex=0;
        listValues[0]=NULL;
    }
    list_flag=1;
}
Why am I getting an error when I declare it? Can you help me solve this?
 
Physics news on Phys.org
As I recall in yacc, $3 refers to the value of OP_OP in the code fragment given. The %token expression given doesn't assign a type which is an error. Why EXPI is reported as the offending variable, I don't know.