0

我正在尝试构建一个简单的词法分析器,以及一个用于(科学)C 程序的简单输入输出库。使用自动工具(包括 automake、libtool 和 autoconf)进行编译时,出现以下错误:

simpleio_lex.l:41: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘of’

这通常意味着我忘记了函数原型末尾的分号,但我检查了我的标题并且没有这样的遗漏。

这是 simpleio_lex.l:

%{
int yylex(void);
#define yylex sio_lex
#include "simpleio.h"
%}

NUM [0-9]           /* a number */
FLOAT {NUM}+"."{NUM}*           /* a floating point number */
FLOATSEQ {FLOAT[[:space:]]?}+
FLOATLN ^FLOATSEQ$
SYMBOL [a-z]+           /* a symbol always comes at the
                   beginning of a line */
SYMDEF ^SYMBOL[[:space:]]*FLOAT /* define a single value for a symbol */
RANGE FLOAT":"FLOAT":"FLOAT /* a range of numbers */
SYMRANGE ^SYMBOL[[:space:]]+RANGE$ /* assign a range of values to a symbol */

%%
                /* a set of lines with just numbers
                   indicates we should parse it as data */
{FLOATLN}+ sio_read_stk_inits (yytext);
SYMDEF sio_read_parse_symdef (yytext);
SYMRANGE sio_read_parse_symrange (yytext);
%%

/* might as well define these here */
sio_symdef_t *
sio_read_parse_symdef (char * symdef)
{
  sio_symdef_t * def = malloc (sizeof (sio_symdef_t));
  /* split the string into tokens on the LHS and RHS */
  char * delim = " ";
  char * lvalue = strtok (symdef, delim);
  size_t lsize = sizeof (lvalue);

  char * rest = strtok (NULL, delim);
  double plval;         /* place holder */
  int s_ck = sscanf (rest, "%lg", &plval);
  if (s_ck == EOF)
    return NULL;
  else
    {
    def->value = plval;
    def->name = malloc (lsize);
    memcpy(def->name, lvalue, lsize);
    }
  return def;
}

Emacs 中的*compilation*缓冲区超链接将我指向%}%序言末尾的 。为什么我会收到此错误?我也没有称为“的”的符号。

谢谢,

乔尔

4

1 回答 1

2

问题是我自己折叠到一条线上的悬空评论,如下所示:

/* this is a comment that's going to run into a 
     new line */

第二行直接复制到源代码中,没有注释分隔符。似乎 flex 对评论和格式相当挑剔。错误信息中提到的“of”是注释第二行的第一个单词。

问题是我必须查看派生的 .c 文件,而不是超链接指向我的 .l 文件。这是转换后的源:

#line 38 "simpleio_lex.l"
int yylex(void);
#define yylex sio_lex
#include <simpleio.h>
beginning of a line */
#line 505 "simpleio_lex.c"

从此在 flex 处理的文件中:

%{
int yylex(void);
#define yylex sio_lex
#include <simpleio.h>
%}


NUM [0-9]           /* a number */
FLOAT {NUM}+"."{NUM}*           /* a floating point number */
FLOATSEQ {FLOAT[[:space:]]?}+
FLOATLN ^FLOATSEQ$
SYMBOL [a-z]+           /* a symbol always comes at the
                   beginning of a line */

谢谢!乔尔

于 2010-07-20T20:30:07.497 回答