を構築しながら:私は判断私.LファイルでフレックスYACC(バイソン)セグメンテーションフォールト私は私の.Yファイルでは、私は論理演算子で</p> <p>で問題を抱えている構文解析ツリー
expr: expr oper1 expr { $$=insert_expression($2, $1, $3); }
| expr oper2 expr { $$=insert_expression($2, $1, $3); }
;
そのOPER1とoper2は、次のとおりです。
"<" | ">" | "=" | "<>" | "<=" | ">=" { return oper1; }
"AND" | "OR" { return oper2; }
その後、私は内の値を配置する構造を持っている:
typedef struct _Expression
{
char *oper;
struct _Expression *ex1;
struct _Expression *ex2;
} is_expression;
とに値を入れる:
void show_expression(is_expression *e)
{
show_expression(e->ex1);
printf("%s", e->oper);
show_expression(e->ex2);
}
が、その後、私は式exprにはoper exprを使用してセグメンテーションフォールトを毎回取得:
is_expression* insert_expression(char* oper, is_expression *expr1, is_expression *expr2)
{
is_expression* e = (is_expression*)malloc(sizeof(is_expression));
e->ex1 = expr1;
e->ex2 = expr2;
e->oper = oper;
return e;
}
、最終的にはそれらを表示
Program received signal SIGSEGV, Segmentation Fault
を
私が間違っていることについてのアイデアはありますか?すべてのトークンの
おかげ
最初のスニペットに波括弧がありません。 –
をクリアすると、 '| expr oper2 expr $$ = insert_expression($ 2、$ 1、$ 3); } 'は' 'でなければなりません。 expr oper2 expr {$$ = insert_expression($ 2、$ 1、$ 3); } ' – gbulmer
申し訳ありません、コピー&ペーストエラー:-(元のコードには中かっこはありません(少なくともyファイル:-)) – Nitrate