tags:

views:

21

answers:

1

Hello,

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

A: 

The problem was a dangling comment that I folded onto a line by itself, like this:

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

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:

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

From this in the file processed by 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 */

Thanks! Joel

Joel J. Adamson