符号表实现(Symbol table implementation)
java
我想为IBM360语言设计一个汇编程序。这里我实现了pass1的符号表。 但是在编译期间遇到1错误。 我无法处理那个错误。任何人都可以指导我??? 我的节目在这里......
import java.io.*; import java.lang.*; import java.util.*; class Symbol { int s_no; String s_name; int s_addr; } class Literal { int literal_no; String literal_name[]; int literal_addr; } class Pass1 { static String POT[]={"START","END","EQU","DC","DS","USING"}; static String MOT[]={"L","SR","A","ST"}; static int POTGET(String instr) { int i,t; for(i=0;i<6;i++) { t=instr.compareTo(POT[i]); if(t==0) return(i+1); } return -1; } static int MOTGET(String instr) { int i,t; for(i=0;i<4;i++) { t=instr.compareTo(MOT[i]); if(t==0) return(i+1); } return -1; } public static void main(String args[]) throws Exception { FileReader fr = new FileReader("program1.asm"); BufferedReader br = new BufferedReader(fr); String str,l; String code[][]=new String[50][10]; int N=0,i,LOC=0,n=0,j; System.out.println("Assembly lang program :\n--------------------------"); while((str = br.readLine()) != null) { //System.out.println(s); String codearr[]=str.split(" "); for(i=0;i<codearr.length;i++) { code[N][i]=codearr[i]; System.out.println(codearr[i]); } N++; } fr.close();int k=0; Symbol s[]=new Symbol[10]; boolean flag; for(i=0;i<N;i++) { for(j=0;j<code[i].length;j++) { if(code[i][j]!=null && code[i][j]!="\t") { flag=false; int p=POTGET(code[i][j]); if(p!=-1) System.out.println( "found IN POT"); else { int m=MOTGET(code[i][j]); if(m!=-1) System.out.println( "found in MOT"); else {System.out.println(code[i][j]); flag=true;} } if(flag) { if((code[i][j]!="=") && (code[i][j]=",") && (code[i][j]!="F") && (code[i][j].startsWith("\'")!=true)) { s[k]= new Symbol(); s[k++].s_name=code[i][j]; } } } } } for(i=0;i<k;i++) System.out.println(s[i].s_name); } }错误:
G:\programs>javac Pass1.java Pass1.java:86: operator && cannot be applied to boolean,java.lang.String if((code[i][j]!="=") && (code[i][j]=",") && (cod e[i][j]!="F") && (code[i][j].startsWith("\'")!=true)) ^ 1 errorprogram1.asm
JOHN START USING * , 15 SR 1 , 1 L 1 , FIVE A 1 , = F '7' ST 1 , TEMP FIVE DC F '5' TEMP DS 1F ENDI want to design an assembler for IBM360 language.so here im implementing the symbol table of pass1. But m getting the 1 error during compilation. I'm not able to deal with that error.can anyone guide me??? my program is here...
import java.io.*; import java.lang.*; import java.util.*; class Symbol { int s_no; String s_name; int s_addr; } class Literal { int literal_no; String literal_name[]; int literal_addr; } class Pass1 { static String POT[]={"START","END","EQU","DC","DS","USING"}; static String MOT[]={"L","SR","A","ST"}; static int POTGET(String instr) { int i,t; for(i=0;i<6;i++) { t=instr.compareTo(POT[i]); if(t==0) return(i+1); } return -1; } static int MOTGET(String instr) { int i,t; for(i=0;i<4;i++) { t=instr.compareTo(MOT[i]); if(t==0) return(i+1); } return -1; } public static void main(String args[]) throws Exception { FileReader fr = new FileReader("program1.asm"); BufferedReader br = new BufferedReader(fr); String str,l; String code[][]=new String[50][10]; int N=0,i,LOC=0,n=0,j; System.out.println("Assembly lang program :\n--------------------------"); while((str = br.readLine()) != null) { //System.out.println(s); String codearr[]=str.split(" "); for(i=0;i<codearr.length;i++) { code[N][i]=codearr[i]; System.out.println(codearr[i]); } N++; } fr.close();int k=0; Symbol s[]=new Symbol[10]; boolean flag; for(i=0;i<N;i++) { for(j=0;j<code[i].length;j++) { if(code[i][j]!=null && code[i][j]!="\t") { flag=false; int p=POTGET(code[i][j]); if(p!=-1) System.out.println( "found IN POT"); else { int m=MOTGET(code[i][j]); if(m!=-1) System.out.println( "found in MOT"); else {System.out.println(code[i][j]); flag=true;} } if(flag) { if((code[i][j]!="=") && (code[i][j]=",") && (code[i][j]!="F") && (code[i][j].startsWith("\'")!=true)) { s[k]= new Symbol(); s[k++].s_name=code[i][j]; } } } } } for(i=0;i<k;i++) System.out.println(s[i].s_name); } }ERROR :
G:\programs>javac Pass1.java Pass1.java:86: operator && cannot be applied to boolean,java.lang.String if((code[i][j]!="=") && (code[i][j]=",") && (cod e[i][j]!="F") && (code[i][j].startsWith("\'")!=true)) ^ 1 errorprogram1.asm
JOHN START USING * , 15 SR 1 , 1 L 1 , FIVE A 1 , = F '7' ST 1 , TEMP FIVE DC F '5' TEMP DS 1F END最满意答案
(代码[i] [j] = “”)
这需要==或!=而不是=
编辑:并且正如BackSlash所说,你应该使用.equals()进行字符串比较。
(code[i][j]=",")
This needs to be == or != instead of =
Edit: and as BackSlash noted, you should use .equals() for string comparisons.
更多推荐
发布评论