gpt4 book ai didi

java - 符号表实现

转载 作者:行者123 更新时间:2023-12-01 13:35:02 27 4
gpt4 key购买 nike

我想为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 error

程序1.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() 进行字符串比较。

关于java - 符号表实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21350768/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com