CnUnix

[알림판목록 I] [알림판목록 II] [글목록][이 전][다 음]
[ CnUnix ] in KIDS
글 쓴 이(By): terzeron (microkid)
날 짜 (Date): 2003년 4월 17일 목요일 오전 11시 03분 19초
제 목(Title): Re: 메모리네의 데이타를 yacc로 파싱하는 


O'Reilly 책에 lex 입력을 바꾸는 방법이 나와 있습니다. 
(2nd ed.에는 확실히 나와 있어요.) yacc쪽은 따로 특별한
설정이 필요한지 모르겠군요.

AT&T 버전에서는 
%{
extern char &mystring;
#undef input
#undef unput
#define input() (*mystring++)
#define unput() (*--mystring = c)
%}

Flex에서는
%{
#undef YY_INPUT
#define YY_INPUT(b, r, ms) (r = my_yyinput(b, ms))
%}

...

extern char myinput[];
extern char *myinputptr;
extern int *myinputlim;
int my_yyinput(char *buf, int max_size)
{
    int n = min(max_size, myinputlim - myinputptr);
    if (n > 0) {
        memcpy(buf, myinputptr, n);
        myinputptr += n;
    }
    return n;
}

---
어떤 성취가, 어떤 조롱이, 또는 어떤 고뇌가 나를 기다리고 있을지 나는 모른다. 
나는 아무 것도 모른다. 그러나 나는 아직 과거의 경이로운 기적의 시대가 영원히 
과거의 것이 되어 버리지는 않았다는 사실을 굳게 믿고 있다.  - Stanislaw Lem -
[알림판목록 I] [알림판목록 II] [글 목록][이 전][다 음]
키 즈 는 열 린 사 람 들 의 모 임 입 니 다.