컴파일러 입문 (정익사) 4장 전체 연습 문제 입니다.
본 자료는 3페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
해당 자료는 3페이지 까지만 미리보기를 제공합니다.
3페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

컴파일러 입문 (정익사) 4장 전체 연습 문제 입니다.에 대한 보고서 자료입니다.

본문내용

용하여 실습하시오.
렉스 입력 :
%{
#include
#include
#include
#include
%}
L[a-zA-Z]
D[0-9]
%%
{L}({L}|{D})*printf(\"id: %s\\n\", yytext);
[a-zA-Z_][a-zA-Z0-9_]*printf(\"C id: %s \\n\", yytext);
(\"+\"|\"-\")?[0-9]+printf(\"integer: %s\\n\", yytext);
[0-9]+\".\"[0-9]+(e[+-]?[0-9]+)?printf(\"real: %s\\n\", yytext);
\\\"([^\\042\\134]|\"\\.\"|\"\\n\")*\\\"printf(\"string: %s\\n\", yytext);
\"/*\"([^*]|\"*\"+[^*])*\"*\"+\"/\"printf(\"text comment: %s\\n\", yytext);
\"//\".*printf(\"line comment: %s\\n\", yytext);
\"\\n\";
.;
%%
int yywrap()
{ return 1; }
void main()
{ yylex(); }
데이터 파일 :
/****************************************************
* This is a test data for Lex. 2006. 11. 7 *
****************************************************/
// identifier
good, n12, sum_product, __yylex, 526
// integer, real
526, +526, -526
5.26 0.24
0.526e10 0.1e-10 12.34e+10
// string constant
\"string\" \"double quote is \\\"(asci:042).\"
/* the end of input */
<<실행결과는 아래와 같습니다.>>
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.
C:\\Documents and Settings\\최정천>cd c:\\2007_2학기\\강의자료_컴파일러\\LEX
C:\\2007_2학기\\강의자료_컴파일러\\LEX>flex -oex0412.c ex0412.l
\"ex0412.l\", line 14: unrecognized rule
\"ex0412.l\", line 24: EOF encountered inside an action
<<여기서 에러를 수정하고, 다른 이름(ex04120.l)으로 저장함>>
C:\\2007_2학기\\강의자료_컴파일러\\LEX>type ex04120.l
%{
#include
#include
#include
#include
%}
L [a-zA-Z]
D [0-9]
%%
{L}({L}|{D})* printf(\" id : %s\\n\", yytext);
[a-zA-Z_][a-zA-Z0-9_]* printf(\" C id : %s \\n\", yytext);
(\"+\"|\"-\")?[0-9]+ printf(\" integer : %s\\n\", yytext);
[0-9]+\".\"[0-9]+(e[+-]?[0-9]+)? printf(\" real : %s\\n\", yytext);
\\\"([^\\042\\134]|\"\\.\"|\"\\n\")*\\\" printf(\" string : %s\\n\", yytext);
\"/*\"([^*]|\"*\"+[^*])*\"*\"+\"/\" printf(\" text comment : %s\\n\", yytext)
;
\"//\".* printf(\" line comment : %s\\n\", yytext);
\"\\n\" ;
. ;
%%
int yywrap()
{ return 1; }
void main()
{ yylex(); }
C:\\2007_2학기\\강의자료_컴파일러\\LEX>flex -oex0412.c ex04120.l
<<여기서 스캐너(ex0412.c)를 컴파일 함>>
<<다음 실행에서 입력 데이터로 ex04120.l을 사용했음>>
C:\\2007_2학기\\강의자료_컴파일러\\LEX>type ex04120.l | ex0412
id : include
id : stdio
id : h
id : include
id : string
id : h
id : include
id : stdlib
id : h
id : include
id : ctype
id : h
id : L
id : a
id : zA
id : Z
id : D
integer : 0
integer : -9
id : L
id : L
id : D
id : printf
id : id
id : s
id : n
string : \", yytext);
[a-zA-Z_][a-zA-Z0-9_]* printf(\"
id : C
id : id
id : s
id : n
string : \", yytext);
(\"
string : \"|\"
string : \")?[0-9]+ printf(\"
id : integer
id : s
id : n
string : \", yytext);
[0-9]+\"
string : \"[0-9]+(e[+-]?[0-9]+)? printf(\"
id : real
id : s
id : n
id : yytext
integer : 042
integer : 134
string : \"|\"
id : n
string : \" printf(\"
id : string
id : s
id : n
string : \", yytext);
\"
string : \"([^*]|\"
string : \"+[^*])*\"
string : \"+\"
string : \" printf(\"
id : text
id : comment
id : s
id : n
string : \", yytext);
\"
line comment : //\".* printf(\" line comment : %s\\n\", yytext)
;
id : n
id : int
id : yywrap
id : return
integer : 1
id : void
id : main
id : yylex
C:\\2007_2학기\\강의자료_컴파일러\\LEX>exit
  • 가격1,000
  • 페이지수11페이지
  • 등록일2009.10.25
  • 저작시기2009.1
  • 파일형식한글(hwp)
  • 자료번호#558013
본 자료는 최근 2주간 다운받은 회원이 없습니다.
  • 편집
  • 내용
  • 가격
청소해
다운로드 장바구니