Lex
Lex는 컴퓨터 과학 분야에서 구문 분석기인 Yacc와 같이 널리 쓰이는 어휘 분석기이다. Lex는 에릭 슈미트와 마이크 레스크�…
| 원저자 | 마이크 레스크, 에릭 슈미트 |
|---|---|
| 발표일 | 1975년 |
| 저장소 | |
| 운영 체제 | 유닉스, 유닉스 계열 |
| 종류 | 명령어 |
Lex는 컴퓨터 과학 분야에서 구문 분석기인 Yacc와 같이 널리 쓰이는 어휘 분석기이다. Lex는 에릭 슈미트와 마이크 레스크가 만든 것으로, 대부분의 유닉스 시스템의 구문 분석 표준으로 사용되고 있고, 그 정의는 POSIX 표준에 명시되어 있다.
Lex는 어휘 분석기를 읽어와서, Lexer를 만든 뒤 이를 C 언어로 만들어진 소스 코드의 형태로 출력한다.
Lex는 저작권이 있는 소프트웨어로 시작했지만, AT&T의 소스 코드에 기반하는 버전은 오픈 소스 정책을 따라 오픈 솔라리스 등에서 사용된다. 이외에도 유명한 오픈 소스 버전의 Lex로는 빠른 Lex(Fast Lex)라는 의미의 flex가 존재한다.
Lex 파일의 예
/*** Definition section ***/
%{
/* C code to be copied verbatim */
#include <stdio.h>
%}
/* This tells flex to read only one input file */
%option noyywrap
%%
/*** Rules section ***/
/* [0-9]+ matches a string of one or more digits */
[0-9]+ {
/* yytext is a string containing the matched text. */
printf("Saw an integer: %s\n", yytext);
}
.|\n { /* Ignore all other characters. */ }
%%
/*** C Code section ***/
int main(void)
{
/* Call the lexer, then quit. */
yylex();
return 0;
}
입력이 flex에 제공되면 C 파일 lex.yy.c로 변환된다. 정수의 문자열과 일치하여 출력하는 실행 파일로 컴파일된다. 예를 들어 아래와 같이 입력하면:
abc123z.!&*2gj6
프로그램은 다음과 같이 출력한다:
Saw an integer: 123 Saw an integer: 2 Saw an integer: 6
같이 보기
| 이 글은 소프트웨어에 관한 토막글입니다. 여러분의 지식으로 알차게 문서를 완성해 갑시다. |
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.