자바를 이용한 Interpreter
본 자료는 3페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
해당 자료는 3페이지 까지만 미리보기를 제공합니다.
3페이지 이후부터 다운로드 후 확인할 수 있습니다.

목차

1. 프로그램 구조
2. 실행예시
3. 코 드

본문내용

ption {//숫자가 아닌 변수연산을 위한 함수
String t = fIn.sval;
while (true) {
fIn.nextToken();
switch (fIn.ttype) {
case '+' : plus(t, Object_term());break;
case '-' : minus(t, Object_term());break;
case '<' :
String temp = "temp";
fIn.nextToken();
int a = (int)fIn.nval;
add(temp,1);
add_value(temp,0,findObject(t).value[a]);
fIn.nextToken();
if(fIn.ttype != '>')
issueError("> is missing");
return temp;
case '/' : issueError("You can't use '/'operator");break;
case '*' : issueError("You can't use '*'operator");break;
default : fIn.pushBack(); return t;
}
}
}
public void run() {
try {
System.out.println(" The program processes statements in the "
+ "following format:\n"
+ "\t[If Id is vector]\n"
+ "\tDIM ID dimention\n\tID = [factor,factor,...,factor];\n"
+ "\tor Id = vector + vector - vector...+vector\n"
+ "\t[If Id is scalar]\n"
+ "\tID = expression;\n"
+ "\tID is ID.value[num] data\n"
+ "\tPrint ID;\n"
+ "\tEnd");
while (true) {
System.out.print(" Enter a statement: ");
fIn.nextToken();
String str = fIn.sval;
String str2, str3;
if (str.toUpperCase().equals("PRINT")) {
fIn.nextToken();
str = fIn.sval;
Id tmp = findObject(str);
if(tmp.size>1){
System.out.print(" "+str + " = " + "[ ");
for(int i =0;i System.out.print(tmp.value[i] + ", ");
System.out.println(tmp.value[tmp.size-1] + " ]");
}
else{
System.out.println(" "+str + " = " + tmp.value[0]);
}
fIn.nextToken();
if(fIn.ttype != ';')
issueError("; is missing");
}
else if (str.toUpperCase().equals("END"))
return;
//변수 선언 하는 부분
else if (str.toUpperCase().equals("DIM")){
fIn.nextToken();
str = fIn.sval;
if(idList.indexOf(new Id(str,0)) != -1)
issueError("This Variable was declared");
else{
fIn.nextToken();
int i = (int)fIn.nval;
fIn.nextToken();
if(fIn.ttype !=';')
issueError("; is missing");
else
add(str,i);
}
}
else{
//변수 = 식 처리 부분
int k = findObject(str).size;
fIn.nextToken();
if (fIn.ttype == '=') {
fIn.nextToken();
//[]연산을 통해 벡터에 값을 넣는 부분
if(fIn.ttype == '['){
double e;
for(int count =0;count e = expression();
add_value(str, count, e);
fIn.nextToken();
}
fIn.nextToken();
if(fIn.ttype != ';')
issueError("; is missing");
}
//벡터끼리 연산 처리부분
else if(fIn.ttype == fIn.TT_WORD){
if(findObject(str).size>1){
add("tmp",findObject(str).size);
str3 = findObject("tmp").toString();
str2 = fIn.sval;
copy(str3,str2);
str2 = Object_expression();
fIn.nextToken();
if(fIn.ttype != ';')
issueError("; is missing");
else{
copy(str, str2);
copy(str2, str3);
}
}//연산 변수가 스칼라일 경우
else{
fIn.pushBack();
double e = expression();
fIn.nextToken();
if (fIn.ttype != ';')
issueError("There are some extras in the statement.");
else add_value(str, 0, e);
}
}
//[]와 벡터연산 아닌 스칼라 연산부분
else {
fIn.pushBack();
double e = expression();
fIn.nextToken();
if (fIn.ttype != ';')
issueError("There are some extras in the statement.");
else add_value(str, 0, e);
}
}
else issueError("'=' s missing.");
}
}
}
catch (IOException e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
(new Interpreter()).run();
}
}

키워드

  • 가격2,000
  • 페이지수10페이지
  • 등록일2009.04.07
  • 저작시기2009.4
  • 파일형식한글(hwp)
  • 자료번호#528656
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니