1 / 14

형식언어와 오토마타

형식언어와 오토마타. 컴퓨터 공학부 4 학년 서정태 squallsjt@empal.com. Contents. Subject. 1. Grammar. 2. Diagram. 3. Automata. 4. 5. Programming. S ubject. Pascal 의 식별자를 인식하는 오토마타 작성하 기 ( 인식기 ) 입력 : 식별자 처리 : 인식 가능한 식별자와 불가능한 식 별자 구분하는 오토마타 출력 : Accept OR Reject. Grammar. 식별자를 위한 문법

freira
Download Presentation

형식언어와 오토마타

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 형식언어와 오토마타 컴퓨터 공학부 4학년 서정태 squallsjt@empal.com

  2. Contents Subject 1 Grammar 2 Diagram 3 Automata 4 5 Programming

  3. Subject • Pascal의 식별자를 인식하는 오토마타 작성하기(인식기) • 입력 : 식별자 • 처리 : 인식 가능한 식별자와 불가능한 식별자 구분하는 오토마타 • 출력 : Accept OR Reject

  4. Grammar • 식별자를 위한 문법 • 다음 문법을 기반으로 프로그램 작성 < id > -> <letter><rest> • <rest> -> <letter><rest>|<digit><rest>| λ <letter> -> a|b|…|z <digit> -> 0|1|…|9

  5. Diagram Java Language Type 1. 일반적으로 생각해 낸 기법을 이용해서 작성한 순차적으로 검사하는 방식 Type2. 각각의 상태를 메소드로 구현해 표현한 방식으로 상태의 값을 전달 해 검사하는 방식

  6. Automata letter Q1 letter identifier fail identifier Q0 Satrt fail digit Q2 Text digit

  7. Type 1. public static void main(String[] args)throws IOException { BufferedReader in = newBufferedReader(newInputStreamReader(System.in)); String term = ""; System.out.print(" Input Data : "); term = in.readLine(); chekVariable(term); } Text

  8. public static void chekVariable(String var){ char[] L = null; L = var.toCharArray(); if(((int)L[0] >=65 & (int)L[0] <= 90) | ((int)L[0] >=97 & (int)L[0] <=122)){ for(int i=1; i<L.length; i++){ if(((int)L[i] >=65 & (int)L[i] <= 90) | ((int)L[i] >=97 & (int)L[i] <=122) | ((int)L[i] >= 48 &(int)L[i] <=57) ){} else{ System.out.println("Reject a variable"); System.exit(0); } } System.out.println("Accect a variable"); } else{ System.out.println("Reject a variable"); } }

  9. Type 2. public static void main(String[] args) throws IOException{ BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String term = ""; char [] arr = null; int len = 0; System.out.print( " Input Data : "); term = in.readLine(); arr = term.toCharArray(); Q0(arr, len); } Text

  10. public static void Q0(char [] arr, int len){ if(arr.length == 1 |(int)arr[0] >= 48 & (int)arr[0] <= 57){ if(((int)arr[len] >= 65 & (int)arr[len] <= 90) | ((int)arr[len] >=97 & (int)arr[len] <= 122)){ Q1(arr, len); } else{ System.out.println("Reject a variable."); } } else{ if(((int)arr[len] >= 65 & (int)arr[len] <= 90) | ((int)arr[len] >=97 & (int)arr[len] <= 122)){ Q1(arr, len); } else if((int)arr[len] >= 48 & (int)arr[len] <= 57){ Q2(arr, len); } else{ System. out.println("Reject a variable."); } } } Text

  11. Type 2. public static void Q1(char [] arr, int len){ if(((int)arr[len] >= 65 & (int)arr[len] <= 90) | ((int)arr[len] >=97 & (int)arr[len] <= 122)){ len ++; if(arr.length == len){ System.out.println("Accect a variable."); } else{ Q1(arr, len); } } else{ Q0(arr, len); } }

  12. Type 2. public static void Q2(char [] arr, int len){ if((int)arr[len] >= 48 & (int)arr[len] <= 57){ len ++; if(arr.length == len){ System.out.println("Accect a variable."); } else{ Q2(arr, len); } } else{ Q0(arr, len); } }

  13. Result Text Text Text Text

  14. Thank You ! 컴퓨터공학부 발표자 서정태

More Related