
-
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


목차
Test.l
Lex 입력 파일
실행 후 LEXYY.C 생성
Lex 실행 화면
생성된 LEXYY.C 파일
입력 Data
한라인 입력 후 해당 결과 출력
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.
-------------------------------------------------------------------------------------
한라인 입력 후 해당 결과 출력
-------------------------------------------------------------------------------------
}
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의 정의 및 구성과특징
[우수과제] Lex와 Yacc를 이용한 사칙연산 계산기 제작 (함수, 상수, 변수 사용가능)
[컴파일러, Compiler] Lex & Yacc 를 이용한 계산기 Report
[컴파일러, Compiler] Lex & Yacc 를 이용한 계산기 Source code
[컴파일러, Compiler] Lex & Yacc 를 이용한 Intermediate code 생성 Report
[컴파일러, Compiler] Lex & Yacc 를 이용한 Parser Report
[컴파일러, Compiler] Lex & Yacc 를 이용한 Intermediate code 생성 Source code
[컴파일러, Compiler] Lex & Yacc 를 이용한 Parser Source code
(컴파일러) LEX를 이용한 ARROW Language Specification