Download presentation
Presentation is loading. Please wait.
1
LOGO 형식언어와 오토마타 컴퓨터 공학부 4 학년 서정태 squallsjt@empal.com
2
Contents Subject 1 Grammar 2 Diagram 3 Automata 4 Programming 5
3
Subject Pascal Pascal 의 식별자를 인식하는 오토 마타 작성하기 ( 인식기 ) 입력 : 식별자 처리 : 인식 가능한 식별자와 불가능한 식 별자 구분하는 오토마타 출력 : Accept OR Reject
4
Grammar 식별자를 위한 문법 다음 문법을 기반으로 프로그램 작성 -> -> | | λ -> a|b|…|z -> 0|1|…|9
5
Diagram Type 1. 일반적으로 생각해 낸 기법을 이용해서 작성한 순차적으로 검사하는 방식 Java Language Type2. 각각의 상태를 메소드로 구현해 표현한 방식으로 상태의 값을 전달 해 검사하는 방식
6
Automata Q0 Text Satrt Q1 Q2 letter digit letter digit identifier fail identifier
7
Type 1. Text public static void main(String[] args)throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String term = ""; System.out.print(" Input Data : "); term = in.readLine(); chekVariable(term); }
8
public static void chekVariable(String var){ char [] L = null; L = var.toCharArray(); if(((int)L[0] >=65 & (int)L[0] =97 & (int)L[0] <=122)){ for(int i=1; i<L.length; i++){ if(((int)L[i] >=65 & (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. Text 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); }
10
Text 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] =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."); }
11
public static void Q1(char [] arr, int len){ if(((int)arr[len] >= 65 & (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); } Type 2.
12
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); } Type 2.
13
Result Text
14
LOGO 컴퓨터공학부 발표자 서정태
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.