2017-12-20 7 views
-1

の致命的なエラー予期せぬ終了と型なしであるので、私は、このコード私はYaccの中MOYの計算をコーディングしたいファイル

%{ 
#include <ctype.h> 
#include <stdlib.h> 
#include <stdio.h> 
#include <math.h> 
// Fonction qui permet de claculer la moyenne 
double moy(int*ls,int size) 
{ 
int som=0; 
for(int j=0; j<size;j++) 
     som+=ls[j]; 
    return (som/size); 
} 

/* La structure de la table*/ 
%} 

%union { 
    int value; 
    struct s{int *ls; int size;} str; 
} 
%token nb 
%type <value> E 
%type <str> L 
%left '+','-' 
%left '*','/' 
//%right '^' 
//%right moins_unaire 
%% 
Ligne : E '\n'  {printf("%d \n",$1);} 
; 

E : E '-' T {$$=$1-$3;} 
    | E '+' T {$$=$1+$3;} 
    | T   {$$=$1;} 
    ; 
T : T '*' F 
    | T '/' F 
    | F 
    ; 
F : '(' E ')' {$$=$2;} 
    | nb {$$=$1;} 
    | fct {$$=$1;} 
    ; 
fct: nf '('L ')' {if ($1==1) { 
     $$= moy($3.ls,$3.size); 
    } 
    ; 
nf : 'moy' {$$=1;} 
    ; 
L : L ',' E {$$.ls=$1; $$.ls[$$.size++]=$3;} 
    | E {$$.size=1; $$.ls=malloc(50); $$.ls[0]=$1;} 
    ; 
%% 
main() 
{ 
    yyparse(); 
} 

が、私はこれらの警告を得ている私はそれをコンパイルし、一度の操作を行い

:私はこの2行を削除した後

コンパイル... mo.y

C:\Users\LE\Desktop\exos\moy\mo.y(35) : warning Y4003: '$3' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(36) : warning Y4003: '$3' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(37) : warning Y4003: '$1' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(43) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(44) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(44) : warning Y4003: '$1' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(45) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(45) : warning Y4003: '$1' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(47) : warning Y4003: '$1' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(48) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(51) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(53) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(53) : warning Y4003: '$1' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(53) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(53) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(54) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(54) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(54) : warning Y4003: '$$' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(54) : warning Y4003: '$1' : attribute is untyped 
C:\Users\LE\Desktop\exos\moy\mo.y(62) : fatal error Y1015: unexpected end of file found in action 

g - 1 error(s), 19 warning(s) 

は私がいることに気づきました

型指定エラーが消えます。私は多くを検索しましたが、私は問題を解決するためには到達しませんでした。

どうすればよいですか?

+1

この行には問題があります: 'fct:nf '(' L ')' {if($ 1 == 1){'中括弧は一致しません。 –

答えて

1

あなたは型エラーを修正する

%type <value> E T F 

を必要としています。

@JeffMercadoで述べたように、時期尚早EOFがこれは適切ではない

fct: nf '('L ')' {if ($1==1) { 

そして

%left '+','-' 
%left '*','/' 

上の余分な最初のブレースによって引き起こされます。コンマはスペースでなければなりません。

+0

これを行うと、警告数が減少しました。コンパイル... mo.y C:\ Users \ LE \ Desktop \ exos \ moy \ mo.y(42):警告Y4003: '$ 1':属性はタイプされていません C:\ Users \ LE \ Desktop \ exos \ moy \ mo.y(43):警告Y4003: '$ 1':属性はタイプされていません C:\ Users \ LE \ Desktop \ exos \ moy \ mo.y(45 (Y):Y4003: '$ 1':属性が型なし C:\ Users \ LE \ Desktop \ exos \ moy \ mo.y(警告)あなたが真剣にそれが読みやすいと思えば、私は申し訳ありませんが、あなたの頭の中に岩があります。LE \ Desktop \ exos \ moy \ mo.y(50):警告Y4003: '$$':属性はタイプなし –

+0

あなたの質問にそれを編集してください。そして、関係する行番号がどれであるか教えてください。しかし、一般に、 '$$:属性は型なし 'とは正確に何を意味するのかを解決するのは、*型指定されていることを確認することです。 – EJP

+0

正直言っても、私の最初の経験では、エラーとは、すべてのトークンをトークンの下で宣言しなければならないということを意味し、ルールのためにタイプしなければならないということを理解できませんでした。だからこそ、私はいつも新しいエラーであると思っています。何か私はそんなに馬鹿だと思っていますが、それは私から誤解されていて、このエラーに私を導いてくれる混乱していました –

関連する問題