컴파일러 Lex 사용법 및 소스
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
해당 자료는 10페이지 까지만 미리보기를 제공합니다.
10페이지 이후부터 다운로드 후 확인할 수 있습니다.

목차

Test.l
Lex 입력 파일
실행 후 LEXYY.C 생성
Lex 실행 화면

생성된 LEXYY.C 파일

입력 Data

한라인 입력 후 해당 결과 출력

본문내용

ndition stack" );
}
yy_start_stack[yy_start_stack_ptr++] = YY_START;
BEGIN(new_state);
}
#endif
#ifndef YY_NO_POP_STATE
static void yy_pop_state()
{
if ( --yy_start_stack_ptr < 0 )
YY_FATAL_ERROR( "start-condition stack underflow" );
BEGIN(yy_start_stack[yy_start_stack_ptr]);
}
#endif
#ifndef YY_NO_TOP_STATE
static int yy_top_state()
{
return yy_start_stack[yy_start_stack_ptr - 1];
}
#endif
#ifndef YY_EXIT_FAILURE
#define YY_EXIT_FAILURE 2
#endif
#ifdef YY_USE_PROTOS
static void yy_fatal_error( const char msg[] )
#else
static void yy_fatal_error( msg )
char msg[];
#endif
{
(void) fprintf( stderr, "%s\n", msg );
exit( YY_EXIT_FAILURE );
}
/* Redefine yyless() so it works in section 3 code. */
#undef yyless
#define yyless(n) \
do \
{ \
/* Undo effects of setting up yytext. */ \
yytext[yyleng] = yy_hold_char; \
yy_c_buf_p = yytext + n - YY_MORE_ADJ; \
yy_hold_char = *yy_c_buf_p; \
*yy_c_buf_p = '\0'; \
yyleng = n; \
} \
while ( 0 )
/* Internal utility routines. */
#ifndef yytext_ptr
#ifdef YY_USE_PROTOS
static void yy_flex_strncpy( char *s1, const char *s2, int n )
#else
static void yy_flex_strncpy( s1, s2, n )
char *s1;
const char *s2;
int n;
#endif
{
register int i;
for ( i = 0; i < n; ++i )
s1[i] = s2[i];
}
#endif
#ifdef YY_USE_PROTOS
static void *yy_flex_alloc( yy_size_t size )
#else
static void *yy_flex_alloc( size )
yy_size_t size;
#endif
{
return (void *) malloc( size );
}
#ifdef YY_USE_PROTOS
static void *yy_flex_realloc( void *ptr, yy_size_t size )
#else
static void *yy_flex_realloc( ptr, size )
void *ptr;
yy_size_t size;
#endif
{
return (void *) realloc( ptr, size );
}
#ifdef YY_USE_PROTOS
static void yy_flex_free( void *ptr )
#else
static void yy_flex_free( ptr )
void *ptr;
#endif
{
free( ptr );
}
#if YY_MAIN
int main()
{
yylex();
return 0;
}
#endif
#line 20 "test.l"
void main()
{
enum tnumber tn; /*token number*/
printf("Start of Lex\n");
while ((tn=yylex()) != TEOF) {
switch(tn) {
case TBEGIN : printf("Begin"); break;
case TEND : printf("End\n"); break;
case TIDEN : printf("Identifier : %s\n", yytext); break;
case TASSIGN : printf("Assignment_op\n"); break;
case TADD : printf("Add_op\n"); break;
case TNUM : printf("Number : %d\n", atoi(yytext)); break;
case TSEMI : printf("Semicolon"); break;
case TDOT : printf("Dot"); break;
case TERROR : printf("Error : %c\n", yytext[0]); break;
}
}
}
int yywrap() {
printf("End of Lex\n");
return 1;
}
-------------------------------------------------------------------------------------
LEXYY.C 컴파일(TC++ for windows)
-------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------
입력 Data
-------------------------------------------------------------------------------------
begin
num := 0;
num := num+526;
end.
-------------------------------------------------------------------------------------
한라인 입력 후 해당 결과 출력
-------------------------------------------------------------------------------------

키워드

컴파일러,   Lex,   Yacc,   컴파일
  • 가격3,000
  • 페이지수41페이지
  • 등록일2007.12.24
  • 저작시기2007.11
  • 파일형식한글(hwp)
  • 자료번호#443923
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니