利用汉语拼音实现java编程

众所周知,编程离不开英语,英文是通用语言,只有26个字母,基本所有的机器和环境都支持。那么不用英语编程行不行?当然是可以的。高级编程语言基本上接近于自然语言。理论上来说,利用任何自然语言来进行编程都是可以的,只要定义好规则,利用编译器或者解释器,将其翻译成机器语言,只要能被计算机识别,就能正常运行了。除了英语,利用汉语拼音进行编程也是可以的。汉语拼音的字母和英语字母基本上也是一样的,除了读音和拼写规则、语法语义上不一样之外,其他基本没区别,不会造成乱码问题。其实不管使用什么编程语言,对于计算机来说都是无感知的,计算机无法直接识别高级语言,只能经过编译,将其转化为字节码,再转换为机器码来执行。操作系统一般是32位或者64位,也就是一条计算机指令的长度(字长)。对于编译器,就如同高级语言和低级语言之间的翻译官,可以利用汇编语言来实现,也可以利用现有的编译器来实现。下面我们利用汉语拼音来实现java编程。请看下面的编码表:

han语言编码对照表
序号所属类型han语言关键字java关键字中文名han语言缩写27修饰限定baohuprotected受保护的bh
1数据类型buer(基本类型)/BuEr(包装类)boolean/Boolean布尔b/B28jingstatic静态的jt
2zi/ZiJiebyte/Byte字节j/J29gufinal固定的gd
3zifu/ZiFuchar/Character字符f/F30chouabstract抽象的cx
4zheng/Zhengint/Integer整数z/Z31bennative本地的bd
5duan/Duanshort/Short短整型d/D32tongsynchronized同步tb
6chang/Changlong/Long长整型c/C33lintransient临时n
7dan/Danfloat/Float单精度浮点数a/A34bianvolatile易变的yb
8shuang/Shuangdouble/Double双精度浮点数s/S35questrictfp精确浮点数q
9对象xinnew新建x36流程控制ruif如果r
10kongvoid空对象k37huoelse或者h
11baopackagebo38tuibreak退出tc
12leiclassl39xucontinue继续xu
13yinruimport引入y40huanswitch转换ha
14jichengextends继承jc41licase实例li
15shixianimplements实现sx42modefault默认m
16jiekouinterface接口jk43lunfor循环(多轮)dl
17leixinginstanceof类型lx44zuodozo
18异常处理shitry尝试cs45dangwhileda
19buhuocatch捕获(异常)bh46fanreturn返回fh
20rengthrows扔出r47字面量wunull空无w
21paothrow抛出p48zhentruezn
22houfinally最后h49jiaflaseja
23修饰限定zhethis这个zg50保留字hengconst恒常he
24gongpublic公有g51tiaogoto跳转t
25siprivate私有i52其他juenum枚举j
26chaosuper超类cl53duanassert断言da

语法规则                                                                                       
1.区分大小写;                                                
2.命名规约:名称可以采用$、数字(0-9)、汉语拼音字母(a-z,A-Z)、下划线(_),不能使用其它符号,不能以数字开头;        
3.命名规范和Java一致,建议采用大驼峰(类)和小驼峰(方法名、属性名)的方式,包名全小写;                        
4.尽量使用汉语拼音全称,避免使用不规范的缩写或者不符合拼写习惯的拼写。命名不能和已有的关键字、保留字相同;正确示例:ping_an,xiAn,错误示例:ua,il;                                                
5.书写方式、换行、缩进和Java一致;关键字前后加空格;每条语句占一行,结尾用;。块级代码写在{}中。每行代码尽量不超过120字符,力求精简。                                          
6.主函数:zhu();相当于public static void main(String[] args);                                
7.打印函数:dayin();//不换行,相当于System.out.print();
                     dayinh();//换行,相当于System.out.println();
8.包的定义如下:bao  gongsi.ceshi.shili_1,类似于java的写法;    
                             包    公司名.应用名.包路径       

9.注释分三种:

          1./*

               代码块

              */ 

             2.// 行级注释

            3. /**

                * 文档注释

                */

10.han语言和java的区别:关键词一一对应,对类库进行替换和改写。利用转换器转换为java执行,和java可以等价互换,实现跨平台的特性。底层利用java来实现。

han语言包装类对照表
序号java基本类型java包装类型han基本类型han包装类型备注
1bytejava.lang.Bytezihan.lang.Zi字节(数组zi[])
2shortjava.lang.Short  duanhan.lang.Duan短整型
3intjava.lang.Integerzhenghan.lang.Zheng整形
4longjava.lang.Longchanghan.lang.Chang长整型(C)
5floatjava.lang.Floatdanhan.lang.Dan单精度(D)
6doublejava.lang.Doubleshuanghan.lang.Shuang双精度(S)
7booleanjava.lang.Booleanbuerhan.lang.BuEr布尔
8charjava.lang.Characterzifuhan.lang.ZiFu字符(a-z/A-Z)

han语言代码示例:

bao gongsi.ceshi.shili_1;
/**
 * 我的第一个han语言程序
 */
gong lei HanCeShi_1{
    // 这是主函数
    zhu(){
       dayinh("你好,欢迎来到han语言的世界!");
       dayin("这是第一个han语言程序。");
       ceShiFangFa();
    }
    
    // 这是示例函数
    gong jing kong ceShiFangFa(){
        /* 定义字节数组 */
        zi[] ziJieShuZu = xin zi[1024];
        Zheng  yi = 1;
        BuEr buEr = zhen;
        Zheng zongHe = 0;
        ru ( ! jia ){
           lun ( zheng i=1;i<=10;i++) {
               zongHe++;
            }
        }
        dayin(zongHe);
    }
}

han语言,顾名思义就是汉语拼音编程语言,这里简称为H++语言。作为英语编程的汉化替代者,目的是让编程者完全脱离对英语的依赖,全部利用汉语拼音就能轻松实现编程,不需要英语基础。执行时利用转码器进行转码,转码程序如下:

package com.han.language.trans;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * han语言转码器
 * @author 1814260016@qq.com
 * @version 1.0.0
 */
public class TransHan {
	
	private  static final String JAVA_KEY_WORDS = "Boolean,boolean,"
			+ "byte,Byte,char,character,Integer,int,short,Short,"
			+ "long,Long,float,Float,double,Double,new,void,instanceof,package,import,class,extends,implements,"
			+ "interface,try,catch,throws,throw,finally,this,super,public,protected,private,"
			+ "static,final,abstract,native,synchronized,transient,volatile,strictfp,if,else,"
			+ "break,continue,switch,case,default,for,do,while,return,null,true,false,const,goto,enum,assert,"
			+ "public static void main(String[] args){,System.out.println,System.out.print";
	
	private  static final String HAN_KEY_WORDS = "BuEr,buer,zi,ZiJie,zifu,ZiFu,Zheng,zheng,duan,Duan,"
			+"chang,Chang,dan,Dan,shuang,Shuang,xin,kong,leixing,bao,yinru,lei,"
			+"jicheng,shixian,jiekou,shi,buhuo,reng,pao,hou,zhe,chao,gong,baohu,si,jing,gu,"
			+"chou,ben,tong,lin,bian,que,ru,huo,tui,xu,huan,li,mo,lun,zuo,dang,fan,wu,zhen,jia,heng,tiao,ju,pan,zhu(){,dayinh,dayin";
	private static final String SHORT_KEY_WORDS = "B,b,j,J,"
			+ "f,F,z,Z,d,D,c,C,a,A,s,S,x,k,bo,l,y,jc,sx,jk,lx,cs,bh,r,p,h,zg,g,i,cl,zhu(){,dayinh,dayin";
	
	public static String replaceCode(String code,int ope) {
		String rs= "";
		code=code.trim();
		String[] javaKey = JAVA_KEY_WORDS.split(",");
		String[] hanKey = HAN_KEY_WORDS.split(",");
		String[] shortKey = SHORT_KEY_WORDS.split(",");
		String[] codes = code.split(" ");
		StringBuffer sb =new  StringBuffer();
		if(code.startsWith("//") || code.startsWith("/*") || code.startsWith("*")) {
			return code;
		}
		for(int j=0;j<codes.length;j++) {
			String c=codes[j].trim();
			boolean isTrue = false;
			int ind = 0;
			for(int i=0;i<hanKey.length;i++){
				String temp = hanKey[i];
				String tempCode = "";
				if(c.endsWith(";")) {
					tempCode=hanKey[i]+";";
					if (c.equals(tempCode)) {
						isTrue = true;
						ind = i;
						break;
					}
				}
				if(c.indexOf("[")>-1) {
					tempCode=c.split("\\[")[0].trim();
					if (tempCode.equals(temp)) {
						isTrue = true;
						ind = i;
						break;
					}
				}else if (c.equals(hanKey[i])) {
					isTrue = true;
					ind = i;
					break;
				}
			}
		
			if(!isTrue) {
				sb.append(c);
			}else {
				if(0==ope) {
					sb.append(c.replace(hanKey[ind],javaKey[ind]));
				}
				if(1==ope) {
					// 输出min
					sb.append(c.replace(hanKey[ind],shortKey[ind]));
				}
			}
			if(j<codes.length-1) {
				sb.append(" ");
			} 
		}
		if(code.contains("dayinh")) {
			rs = code.replace("dayinh", "System.out.println");
			return rs;
		}
		if(code.contains("dayin")) {
			rs = code.replace("dayin", "System.out.print");
			return rs;
		}
		
		return sb.toString();
	}
	 
	 

	public static void main(String[] args) throws IOException {
		// han源码txt文件
		String source = "D:\\han\\source\\test01.txt";
		// 转码文件
		String out = "D:/han/source/out_test01.txt";
		
		BufferedReader reader = null;
		BufferedWriter output = null;
		try {
			File sourceFile = new File(source);
			File outFile = new File(out);
			// true,则追加写入text文本
			output = new BufferedWriter(new FileWriter(outFile ,true));
			// 删除旧文件重新生成
			if (outFile.exists()) {
				outFile.delete();
			}
			outFile.createNewFile();
			
			String temp = null;
			int line = 1;

			reader = new BufferedReader(new FileReader(sourceFile));
			while ((temp = reader.readLine()) != null) {
				String code = replaceCode(temp,0);
				System.out.println(code);
				output.write(code);
				output.write("\r\n");//换行
				
				line++;
			}
			output.flush();
		} catch (Exception e) {
			e.printStackTrace();
			// System.out.println(e.printStackTrace());
		}finally {
			if(null!=output) {
				output.close();
			}
			if(null!=reader ) {
				reader .close();
			}
		}
	}

}

han语言符合汉语使用习惯,编程短小精悍,力求精简。简称是为了进行源码文件压缩,编码一一对应,压缩后的文件格式是.han.min或.h.min。可以直接利用java的编译器,在java环境下运行,或者用其他语言编写新的编译器。可以根据需要扩展新的类库。

声明:原创语言,免费开源。未经允许,请勿转载。
                                                 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值