1. 27 (token descriptions) (regular expressions), grep egrep.. C. 1),., C (expressions), (statements), (declarations), (blocks) (procedures). (parsing



Similar documents
商用

lex-yacc-tutorial.hwp

K&R2 Reference Manual 번역본

컴파일러

프로그램을 학교 등지에서 조금이라도 배운 사람들을 위한 프로그래밍 노트 입니다. 저 역시 그 사람들 중 하나 입니다. 중고등학교 시절 학교 도서관, 새로 생긴 시립 도서관 등을 다니며 책을 보 고 정리하며 어느정도 독학으르 공부하긴 했지만, 자주 안하다 보면 금방 잊어

EA0015: 컴파일러

Page 2 of 5 아니다 means to not be, and is therefore the opposite of 이다. While English simply turns words like to be or to exist negative by adding not,

chap7.key


step 1-1

untitled


DIY 챗봇 - LangCon

PowerPoint 프레젠테이션

강의10

C++-¿Ïº®Çؼ³10Àå

BMP 파일 처리

휠세미나3 ver0.4

<30352DC0CCC7F6C8F B1B3292DBFACB1B8BCD2B1B3C1A42E687770>

(Asynchronous Mode) ( 1, 5~8, 1~2) & (Parity) 1 ; * S erial Port (BIOS INT 14H) - 1 -

6주차.key

歯9장.PDF

5.스택(강의자료).key

chap10.PDF

본 강의에 들어가기 전

03장.스택.key

/chroot/lib/ /chroot/etc/

, ( ),, ( ), 3, int kor[5]; int eng[5]; int Microsoft Windows 4 (ANSI C2 ) int kor[5] 20 # define #define SIZE 20 int a[10]; char c[10]; float

슬라이드 1

슬라이드 1

Columns 8 through while expression {commands} 예제 1.2 (While 반복문의이용 ) >> num=0


Page 2 of 6 Here are the rules for conjugating Whether (or not) and If when using a Descriptive Verb. The only difference here from Action Verbs is wh

MPLAB C18 C

<4D F736F F D20C3A520BCD2B0B32DC0CCB7B2B0C5B8E9B3AAB6FBBFD6B0E1C8A5C7DFBEEE322E646F63>

Microsoft PowerPoint - semantics

untitled

13주-14주proc.PDF

퇴좈저널36호-4차-T.ps, page Preflight (2)

PowerPoint 프레젠테이션

PowerPoint 프레젠테이션

4.18.국가직 9급_전산직_컴퓨터일반_손경희_ver.1.hwp

- 2 -

À©µµ³×Æ®¿÷ÇÁ·Î±×·¡¹Ö4Àå_ÃÖÁ¾

Orcad Capture 9.x

PowerPoint 프레젠테이션

Chapter 4. LISTS

가정법( 假 定 法 )이란, 실제로 일어나지 않았거나 앞으로도 일어나지 않을 것 같은 일에 대해 자신의 의견을 밝히거나 소망을 표현하는 어법이다. 가정법은 화자의 심적 태도나 확신의 정도를 나타내는 어법이기 때문 에 조동사가 아주 요긴하게 쓰인다. 조동사가 동사 앞에

untitled

OCaml

C프로-3장c03逞풚

Microsoft PowerPoint - PL_03-04.pptx

C# Programming Guide - Types

07 자바의 다양한 클래스.key

0. 표지에이름과학번을적으시오. (6) 1. 변수 x, y 가 integer type 이라가정하고다음빈칸에 x 와 y 의계산결과값을적으시오. (5) x = (3 + 7) * 6; x = 60 x = (12 + 6) / 2 * 3; x = 27 x = 3 * (8 / 4

호랑이 턱걸이 바위

Chapter_06

Microsoft PowerPoint - chap13-입출력라이브러리.pptx

Microsoft PowerPoint - PLT_ch04_KOR

歯7장.PDF

PowerPoint 프레젠테이션


chap7.PDF

May 2014 BROWN Education Webzine vol.3 감사합니다. 그리고 고맙습니다. 목차 From Editor 당신에게 소중한 사람은 누구인가요? Guidance 우리 아이 좋은 점 칭찬하기 고맙다고 말해주세요 Homeschool [TIP] Famil

4. #include <stdio.h> #include <stdlib.h> int main() { functiona(); } void functiona() { printf("hihi\n"); } warning: conflicting types for functiona

Semantic Consistency in Information Exchange

How to use this book Preparation My family I have a big family. I have grandparents, parents. I m the oldest in my family. My father is strict. 다양한 생활

PowerPoint 프레젠테이션

3장 어휘분석

PowerPoint 프레젠테이션

112초등정답3-수학(01~16)ok

Microsoft PowerPoint - a10.ppt [호환 모드]

untitled

Something that can be seen, touched or otherwise sensed

chap01_time_complexity.key

02 C h a p t e r Java

Stage 2 First Phonics

2002년 2학기 자료구조

untitled

초보자를 위한 C++

< E20C6DFBFFEBEEE20C0DBBCBAC0BB20C0A7C7D12043BEF0BEEE20492E707074>

Sena Technologies, Inc. HelloDevice Super 1.1.0

Microsoft PowerPoint - 3ÀÏ°_º¯¼ö¿Í »ó¼ö.ppt

시편강설-경건회(2011년)-68편.hwp

<C1D6BFE4BDC7C7D0C0DA5FC6EDC1FDBFCF28B4DCB5B5292E687770>

untitled

정 관

하나님의 선한 손의 도우심 이세상에서 가장 큰 축복은 하나님이 나와 함께 하시는 것입니다. 그 이 유는 하나님이 모든 축복의 근원이시기 때문입니다. 에스라서에 보면 하나님의 선한 손의 도우심이 함께 했던 사람의 이야기 가 나와 있는데 에스라 7장은 거듭해서 그 비결을

vi 사용법

PDF

PRO1_09E [읽기 전용]

10주차.key

Blackjack Game [Project #1] Multiplayer Blackjack Game 블랙잭은 21을넘지않는한도내에서딜러와겨루어숫자가높으면이기는게임 1 딜러 (House) 가자신을포함한참가자전원에게카드두장을나누어주는데, 딜러의카드한장은참가자들에게보이지않는다

01-OOPConcepts(2).PDF

1장. 유닉스 시스템 프로그래밍 개요

삼성955_965_09

I&IRC5 TG_08권

SRC PLUS 제어기 MANUAL

제1장 Unix란 무엇인가?

PowerPoint 프레젠테이션

Transcription:

(lex) (yacc). (object code) C. (unit).. C,,,,. ( ) (lexical analysis) (lexing). C (routine). (lexical analyzer) (lexer) (scanner). (lex specification).

1. 27 (token descriptions) (regular expressions), grep egrep.. C. 1),., C (expressions), (statements), (declarations), (blocks) (procedures). (parsing), (grammar)., C, (parser). (match), (syntax error).,.., (.. 2 )..,. 1) :. (lex) (lexer)..

28 lex yacc (standard input) : (standard output). \n ECHO; cat (arguments). C,.,,. (code base),.. (, ),.

1. 29. is am are were was be being been do does did will would should can could has have had go [ 1-1]. %{ /* * ( ). * / */ % [\t ]+ /*. */ ; is am are were was be being been do does did will would

30 lex yacc should can could has have had go { printf("%s: is a verb\n", yytext); [a-za-z]+ { printf("%s: is not a verb\n", yytext);. \n { ECHO; /* */ main() { yylex();. (bold). % example1 did I have fun? did: is a verb I: is not a verb have: is a verb fun: is not a verb? ^D %. %{ /* * ( ).

1. 31 * / */ % (definition section) C.. C "%{" "%" (delimiter). C, C. C,. (whitespace)... (rules section)., (pattern) (action).. (regular expressions), grep, sed, ed. 6.. [\t ]+ /*. */ ; "[ ]". ( ) "\t" ( ) " ". "+". ( ). (action), C.

32 lex yacc. " "( ).,. 2). is am are were was be being been do does did should can could has have had go { printf("%s: is a verb\n", yytext);. C printf. yytext. ": is a verb\n".. 2)., foo bar "foo" "bar"..

1. 33 [a-za-z]+ { printf("%s: is not a verb \n", yytext);. \n { ECHO; /* */ "[a-za-z]+",. "-", "-"., ": is not a verb\n". ([a-za-z]).. "island" "is" "island".,.. 1.. 2. (longest possible match). "island" "is", "island" "is".,.. "."( ), "\n". ECHO (punctuation). ECHO,. (,

34 lex yacc ).. (user subroutine section), C. C. main( ). main() { yylex(); yylex( ) C, (main). 3) return, yylex( ). ch1-02.l.. % lex ch1-02.l % cc lex.yy.c -o first -ll lex.yy.c C, C -ll.,.. 3).

1. 35, ' '. [ 1-2]. %{ /* *. */ % [\t ]+ /*. */ ; is am are were was be being been do does did will would should can could has have had go { printf("%s: is a verb\n", yytext); very simply gently quietly calmly

36 lex yacc angrily { printf("%s: is an adverb\n", yytext); to from behind above below between below { printf("%s: is a preposition\n", yytext); if then and but or { printf("%s: is a conjunction\n", yytext); their my your his her its { printf("%s: is an adjective\n", yytext); I you he she we they { printf("%s: is a pronoun\n", yytext); [a-za-z]+ { printf("%s: don't recognize, might be a noun\n", yytext);. \n { ECHO; /* */ main() { yylex();

1. 37.,.,..,,.,.,. noun dog cat horse cow verb chew eat lick (symbol table),., C,,, (enumeration tag).. C,,...,,. (, ) ' (reserved words)'.., add_word( ), lookup_word( ). state, LOOKUP,

38 lex yacc. state, \n state. [ 1-3]. %{ /* * */ enum { LOOKUP = 0, /* -. */ VERB, ADJ, ADV, NOUN, PREP, PRON, CONJ ; int state; int add_word(int type, char *word); int lookup_word(char *word); %, state enum. (enumerated type) state,..

1. 39 [ 1-4]. \n { state = LOOKUP; /*,. */ /* */ /*. */ ^verb { state = VERB; ^adj { state = ADJ; ^adv { state = ADV; ^noun { state = NOUN; ^prep { state = PREP; ^pron { state = PRON; ^conj { state = CONJ; [a-za-z]+ { /*,. */ if(state!= LOOKUP) { /*. */ add_word(state, yytext); else { switch(lookup_word(yytext)) { case VERB: printf("%s: verb\n", yytext); break; case ADJ: printf("%s: adjective\n", yytext); break; case ADV: printf("%s: adverb\n", yytext); break; case NOUN: printf("%s: noun\n", yytext); break; case PREP: printf("%s: preposition\n", yytext); break; case PRON: printf("%s: pronoun\n", yytext); break; case CONJ: printf("%s: conjunction\n", yytext); break; default: printf("%s: don't recognize\n", yytext); break;

40 lex yacc. /*. */ ;, ( "^" ). state LOOKUP. "[a-za-z]+" state LOOKUP lookup_word( ),. state add_word( ). [ 1-5] main( ). main() { yylex(); /*. */ struct word { char *word_name; int word_type; struct word *next; ; struct word *word_list; /* */ extern void *malloc(); int add_word(int type, char *word) { struct word *wp; if(lookup_word(word)!= LOOKUP) {

1. 41 printf("!!! warning: word %s already defined \n", word); return 0; /*,. */ wp = (struct word *) malloc(sizeof(struct word)); wp->next = word_list; /*. */ wp->word_name = (char *) malloc(strlen(word)+1); strcpy(wp->word_name, word); wp->word_type = type; word_list = wp; return 1; /*. */ int lookup_word(char *word) { struct word *wp = word_list; /*. */ for(; wp; wp = wp->next) { if(strcmp(wp->word_name, word) == 0) return wp->word_type; return LOOKUP; /*. */ (linked list).. (hash table)..

42 lex yacc (session). verb is am are was were be being been do is is: verb noun dog cat horse cow verb chew eat lick verb run stand sleep dog run dog: noun run: verb chew eat sleep cow horse chew: verb eat: verb sleep: verb cow: noun horse: noun verb talk talk talk: verb......

1. 43. noun verb noun verb noun. " ". 4),. subject noun pronoun "subject( )" (noun) (pronoun).., (object). object noun,. sentence subject verb object..,. 4) " ",,.,.

44 lex yacc. yylex( ).., yylex( )..,.... (NOUN), (PRONOUN), (VERB), (ADVERB), (ADJECTIVE), (PREPOSITION) (CONJUNCTION). #define.. # define NOUN 257 # define PRONOUN 258 # define VERB 259 # define ADVERB 260 # define ADJECTIVE 261 # define PREPOSITION 262 # define CONJUNCTION 263 0. 0,. C. y.tab.h, MS-DOS ytab.h yytab.h,.

1. 45 [ 1-6]. %{ /* *. */ #include "y.tab.h" /* */ #define LOOKUP 0 /* -. */ int state; % \n { state = LOOKUP; \.\n { state = LOOKUP; return 0; /* */ ^verb { state = VERB; ^adj { state = ADJECTIVE; ^adv { state = ADVERB; ^noun { state = NOUN; ^prep { state = PREPOSITION; ^pron { state = PRONOUN; ^conj { state = CONJUNCTION; [a-za-z]+ { if(state!= LOOKUP) { add_word(state, yytext); else { switch(lookup_word(yytext)) { case VERB: return(verb); case ADJECTIVE: return(adjective);

46 lex yacc case ADVERB: return(adverb); case NOUN: return(noun); case PREPOSITION: return(preposition); case PRONOUN: return(pronoun); case CONJUNCTION: return(conjunction); default: printf("%s: don't recognize\n", yytext); /*. */ \. ;... add_word() lookup_word()..... return., return. yylex( ). yylex( ),..,.

1. 47. \.\n { state = LOOKUP; return 0; /* */.. main( ). [ 1-7]. %{ /* * */ #include <stdio.h> % %token NOUN PRONOUN VERB ADVERB ADJECTIVE PREPOSITION CONJUNCTION sentence: subject VERB object { printf("sentence is valid.\n"); ; subject: NOUN PRONOUN ; object: NOUN ;

48 lex yacc extern FILE *yyin; main() { do { yyparse(); while(!feof(yyin)); yyerror(s) char *s; { fprintf(stderr, "%s\n", s);. "%{" "%" (literal code block). C (, C C ) ( stdio.h).,..,. C (identifier),... yyparse( ) main( ). yyparse( ), ( 0. ).

1. 49 (production rules) ( ). ":",..,. 0. NOUN object..,. " ",. " " "or( )", (subject) NOUN PRONOUN. "{" "" C.,. sentence. sentence sentence. ( main ). yyparse( ). "subject VERB object". "subject subject"? yyerror( ), error.., yyparse( ).

50 lex yacc. C,. main( ) yyerror( ). yyin. yylex( ). [ 1-8],... %{ #include <stdio.h> % %token NOUN PRONOUN VERB ADVERB ADJECTIVE PREPOSITION CONJUNCTION sentence: simple_sentence { printf("parsed a simple sentence.\n"); compound_sentence { printf("parsed a compound sentence.\n"); ; simple_sentence: subject verb object subject verb object prep_phrase ; compound_sentence: simple_sentence CONJUNCTION simple_sentence compound_sentence CONJUNCTION simple_sentence ; subject: NOUN PRONOUN ADJECTIVE subject ; verb: VERB

1. 51 ADVERB VERB verb VERB ; object: NOUN ADJECTIVE object ; prep_phrase: PREPOSITION NOUN ; extern FILE *yyin; main() { do { yyparse(); while(!feof(yyin)); yyerror(s) char *s; { fprintf(stderr, "%s\n", s); sentence. (simple sentence) (clauses). "and" "but" "if".

52 lex yacc (recursion).,. compound_sentence, verb. compound_sentence.. simple_sentence CONJUNCTION simple_sentence " (clauses)", " ". compound_sentence CONJUNCTION simple_sentence.,,., C. if( a == b ) break; else func(&a);v if, (, a, ==, "a == b" if (expression part), break " " " ".

1. 53. ch1-n.l, N. ch1-m.y, M.,. % lex ch1-n.l % yacc -d ch1-m.y % cc -c lex.yy.c y.tab.c % cc -o example-m.n lex.yy.o y.tab.o -ll, C lex.yy.c. y.tab.c y.tab.h (y.tab.h -d, ). C., /usr/lib/libl.a libl.a -ll. AT&T, ( lex yacc byacc flex -ll ).., (GNU bison), C ch1-m.tab.c ch1-m.tab.h. MS-DOS ( ytab.c ytab.b ). ' A'.

54 lex yacc C.. [ 1-9],,, C. [ 1-10]. C 3., C. #include <stdio.h> #include <ctype.h> char *progname; #define NUMBER 400 #define COMMENT 401 #define TEXT 402 #define COMMAND 403 main(argc,argv) int argc; char *argv[]; { int val; while(val = lexer()) printf("value is %d\n",val); lexer() { int c; while ((c=getchar()) == ' ' c == '\t') ; if (c == EOF)

1. 55 return 0; if (c == '.' isdigit(c)) { /* */ while ((c = getchar())!= EOF && isdigit(c)); if (c == '.') while ((c = getchar())!= EOF && isdigit(c)); ungetc(c, stdin); return NUMBER; if ( c == '#' ) { /* */ int index = 1; while ((c = getchar())!= EOF && c!= '\n'); ungetc(c,stdin); return COMMENT; if ( c == '"' ) { /* */ int index = 1; while ((c = getchar())!= EOF && c!= '"' && c!= '\n'); if(c == '\n') ungetc(c,stdin); return TEXT; if ( isalpha(c)) { /*. */ int index = 1; while ((c = getchar())!= EOF && isalnum(c)); ungetc(c, stdin); return COMMAND; return c; %{ #define NUMBER 400 #define COMMENT 401 #define TEXT 402

56 lex yacc #define COMMAND 403 % [ \t]+ ; [0-9]+ [0-9]+.[0-9]+ \.[0-9]+ { return NUMBER; #* { return COMMENT; \"[^\"\n]*\" { return TEXT; [a-za-z][a-za-z0-9]+ { return COMMAND; \n { return '\n'; return yytext[0]; #include <stdio.h> main(argc,argv) int argc; char *argv[]; { int val; while(val = yylex()) printf("value is %d\n",val);., C. "*", "/". "*" "/",. C "*" "*",. ( ). /** **/

1. 57,,. 2. 3.,. 1.,. 2. "has been". AUXVERB. 3. "watch", "fly", "time" "bear".? NOUN_OR_VERB, subject, verb object.? 4.,.? "ing", "a" "the". 5.??