English 中文(简体)
1. 修改acc酸acc类型
原标题:Who modify the type of $$ in a yacc grammar

我想修改以下图表中的元件定义,即宣布乙醇为胎体,但是,在编造带有胶卷的立体时有错误。

gcc *.c -ly 
tp.l: In function ‘yylex’:
tp.l:12: error: request for member ‘sum’ in something not a structure or union
y.tab.c:1035: error: conflicting types for ‘yylval’
tp.y:11: note: previous declaration of ‘yylval’ was here

the yacc file:

 %{
        #include <ctype.h>
        #include <stdio.h>
        #include <stdlib.h>

        typedef struct {
            int val;
            int cpt;
        } str;

        str yylval;

%}
        %start  start 
        %token  number

%%
    start : number + number 
 
    ;

%%

int main(void)
{
        yyparse();
        return 0;
}

弹性文件:

%option noyywrap

%{
    #include<stdio.h>
    #include<stdlib.h>
    #include<ctype.h>
    #include"y.tab.h"
%}

%%
[0-9]+  {
            yylval = atoi(yytext); 
            return number;
        }

"+"     return  + ;

      return  
 ;
" " ;

%%
最佳回答

您不能界定自己的<代码>yylval。 所产生的法典已经界定了这一点。 使用<代码>%union指令间接界定该类型。 如果这不合适,那么你可以做的是重新界定宏观标码,将其扩大到任意型谱。 例如:

struct my_semantic_attributes {
  int foo;
  /* ... */
};

#define YYSTYPE struct my_semantic_attributes
问题回答

暂无回答




相关问题
Parse players currently in lobby

I m attempting to write a bash script to parse out the following log file and give me a list of CURRENT players in the room (so ignoring players that left, but including players that may have rejoined)...

How to get instance from string in C#?

Is it possible to get the property of a class from string and then set a value? Example: string s = "label1.text"; string value = "new value"; label1.text = value; <--and some code that makes ...

XML DOM parsing br tag

I need to parse a xml string to obtain the xml DOM, the problem I m facing is with the self closing html tag like <br /> giving me the error of Tag mismatch expected </br>. I m aware this ...

Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

Locating specific string and capturing data following it

I built a site a long time ago and now I want to place the data into a database without copying and pasting the 400+ pages that it has grown to so that I can make the site database driven. My site ...

热门标签