小编Jay*_*Jay的帖子

$ 1,$ 2 ..变量值始终为NULL

我想在我的Ubuntu操作系统上用Bison(GNU bison 2.4.1)和flex(2.5.35)创建一个解析器.我有这样的事情:

sql.h:

typedef struct word
{
  char *val;
  int  length;
} WORD;

struct yword
{
  struct word  v;
  int          o;
...
};
Run Code Online (Sandbox Code Playgroud)

sql1.y

%{
..
#include "sql.h"
..
%}

%union yystype
{
  struct tree *t;
  struct yword b;
...
}

%token <b> NAME

%%

...

table:
        NAME           { add_table(root, $1.v); }
    ;

...
Run Code Online (Sandbox Code Playgroud)

麻烦的是,无论我给它什么字符串,当解决这个问题时,即使输入字符串应该有一些表名,v总是有值(NULL,0).(我选择跳过不必要的其他细节/片段,但如果它有助于解决此问题,可以提供更多.)

我编写了完整而正确的语法,但由于这个问题我无法建立解析树.

任何输入都将非常感激.

tree parsing types bison flex-lexer

4
推荐指数
1
解决办法
1317
查看次数

标签 统计

bison ×1

flex-lexer ×1

parsing ×1

tree ×1

types ×1