목차
1. 프로그램 구조
2. 실행예시
3. 코 드
2. 실행예시
3. 코 드
본문내용
ception {//숫자가 아닌 변수연산을 위한 함수
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();
}
}
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
+ \"\\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.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
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();
}
}
소개글