flex 文件编译错误
我正在尝试构建一个简单的词法分析器,以及一个用于(科学)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*
缓冲区超链接将我引向序言末尾的 %}%
。为什么我会收到此错误?我也没有名为“of”的符号。
谢谢,
乔尔
I'm trying to build a simple lexical analyzer to go along with a simple input output library for (scientific) C programs. When compiling with autotools, including automake, libtool, and autoconf, I get the following error:
simpleio_lex.l:41: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘of’
This usually means that I've forgotten a semicolon at the end of a function prototype, but I've checked my header and there's no such omission.
Here's 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;
}
The *compilation*
buffer hyperlink in Emacs refers me to the %}%
at the end of the preamble. Why am I getting this error? I have no symbol called "of," either.
Thanks,
Joel
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是一个悬空注释,我将其折叠成一行,如下所示:
第二行被直接复制到源代码中,没有注释分隔符。看来flex对注释和格式相当挑剔。错误消息中提到的“of”是注释第二行的第一个单词。
问题是我必须查看派生的 .c 文件,而不是超链接指向我的 .l 文件。这是转换后的源:
来自flex处理的文件中的这个:
谢谢!
乔尔
The problem was a dangling comment that I folded onto a line by itself, like this:
The second line was copied directly into the source, without its comment delimiter. It seems flex is rather picky about comments and formatting. The "of" mentioned in the error message is the first word of the second line of the comment.
The problem is that I had to look in the derived .c file, not in the .l file where the hyperlink was directing me. This is the transformed source:
From this in the file processed by flex:
Thanks!
Joel