⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cw3c.java

📁 a Java program that reads a file containing instructions written in self-defined file (TPL in this c
💻 JAVA
字号:
import java.io.*;
import java.util.*;


class cw3c
{	
	static Vector text;
	static Vector data;
	static int pNo=0;
	
	public static void main(String args[])
	{	
		
		text=new Vector();
		boolean x=false;
		boolean y;
		String line;
		
		if(args.length>=1)
		
		{	
			try{
					BufferedReader inFile=new BufferedReader(new FileReader(args[0]));
					
						
					while((line=inFile.readLine())!=null)	
					{
					 	
					 	text.addElement(line);			 	
					 	
					 }
			
				}catch(IOException e){
					System.out.println("an error ["+e+"]");
				}
		}
		else
		{
			System.out.println("no command line args");
		}
		for(int i=0;i<text.size();i++)
		{
			String temp=(String)text.elementAt(i);
			y=temp.equalsIgnoreCase("end");
			x=y;
		}
		if(x==false)
		 exit();
		else
		 dostuff();
		 
	}//main
	
	public static void exit()
	{
		System.out.println("unexpected statement");
		System.exit(0);
	}//exit
	
	public static void dostuff()
	{
		String fStr=" ";
		String sStr=" ";
	
		for(int i=0;i<text.size();i++)
		{
			String temp=(String)text.elementAt(i);
			StringTokenizer file=new StringTokenizer(temp);
			if(file.countTokens()>1)
			{
				int dx=temp.indexOf(" ");
				fStr=temp.substring(0,dx);			//fstr contain reserved words
				sStr=temp.substring((dx+1),temp.length());	//sStr has content of command
				if((fStr.equals("#"))==true)
				{	
					System.out.println(sStr);
					pNo++;
				}//end of #
				
			 	else if((fStr.equalsIgnoreCase("println"))==true)
				{
					if(sStr.indexOf("\"")>=0)
					{ 
						
			 			String t=sStr.substring(1,(sStr.length()-1));
						System.out.println(t);
						pNo++;
					}
					else
						System.out.println(sStr);
						pNo++;
				}
				else if((fStr.equalsIgnoreCase("print"))==true)
				{
					if(sStr.indexOf("\"")>=0)
					{ 
						
			 			String t=sStr.substring(1,(sStr.length()-1));
						System.out.print(t);
					}
					else
						System.out.print(sStr);
				}
				
			 }

			else
			{
				if((temp.equalsIgnoreCase("println"))==true)
				{
					System.out.println(" ");
				
				}
				else
				{
					System.out.println("TPL finished ok. [ "+(pNo+1)+" ] lines processed");
				}
						
			}//end of else
		}//end of for
	}//end of dostuff

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -