2010-07-20 3 views
0

(과학적인) C 프로그램을위한 간단한 입력 출력 라이브러리와 함께 사용하기 위해 간단한 어휘 분석기를 작성하려고합니다. automake에, libtool이, 그리고 autoconf를 포함 autotools를, 컴파일 할 때, 나는 다음과 같은 오류가 발생합니다 :flex 파일의 컴파일 오류

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; 
} 

이멕스의 *compilation* 버퍼 하이퍼 링크 프리앰블 끝에 %}% 날을 말한다. 이 오류가 발생하는 이유는 무엇입니까? 나는 "of"이라는 상징이 없다. , 두 번째 줄은 직접 소스로 복사 한

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

:

감사합니다,

조엘

+0

이것을 Adobe Flex에 표시 하시겠습니까? – JeffryHouser

+0

아니요. 그는 실제 flex를 의미하지 않았지만 일반적으로 gnu-flex로 태그하므로 'flex'태그가 제거됩니다. –

+0

감사합니다. Simeon - Adobe Flex와 같은 것이 있는지 몰랐습니다. –

답변

2

이 문제는 다음과 같이 내가 그 자체로 한 줄에 접어 매달려 코멘트를했다 주석 구분 기호없이. flex는 코멘트와 포맷에 대해 다소 까다 롭습니다. 오류 메시지에 언급 된 "of"는 주석의 두 번째 줄의 첫 번째 단어입니다.

문제는 하이퍼 링크가 나를 안내하는 .l 파일이 아니라 파생 된 .c 파일을 조사해야한다는 것입니다. 플렉스에 의해 처리되는 파일에이에서

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

:

%{ 
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 */ 

덕분에이 변환 된 소스입니다! Joel