| 头文件/模块例句 |
#include <stdio.h> |
#include <iostream> |
using System; |
import math |
import java.util.*; |
import "module" |
Import ModuleName |
source file.sh |
Import-Module Module |
require 'module' |
import "fmt" |
mod module; |
import Module |
include 'file.php' |
import package.Class |
| 命名空间例句 |
无 |
namespace MyNS {} |
namespace MyNS {} |
无 |
package com.example; |
无 |
无 |
无 |
无 |
module MyModule |
无 |
mod my_module |
无 |
namespace MyNS; |
package com.example |
| 定义变量例句 |
int x = 10; |
int x = 10; |
int x = 10; |
x = 10 |
int x = 10; |
let x = 10; |
Dim x As Integer = 10 |
x=10 |
$x = 10 |
x = 10 |
var x int = 10 |
let x: i32 = 10; |
var x = 10 |
$x = 10; |
val x = 10 |
| 语句结束符号 |
; |
; |
; |
换行 |
; |
;(可选) |
:(语句块) |
换行 |
换行 |
换行 |
; |
; |
; |
; |
; |
| 定义函数例句 |
int add(int a, int b) { return a+b; } |
int add(int a, int b) { return a+b; } |
int Add(int a, int b) { return a+b; } |
def add(a, b): return a+b |
int add(int a, int b) { return a+b; } |
function add(a, b) { return a+b; } |
Function Add(a As Integer, b As Integer) As Integer\n Add = a + b\nEnd Function |
add() { echo $(($1 + $2)); } |
function Add($a, $b) { $a + $b } |
def add(a, b) a + b end |
func add(a int, b int) int { return a + b } |
fn add(a: i32, b: i32) -> i32 { a + b } |
func add(a: Int, b: Int) -> Int { return a + b } |
function add($a, $b) { return $a + $b; } |
fun add(a: Int, b: Int): Int = a + b |
| 定义类例句 |
无 |
class MyClass {}; |
class MyClass {} |
class MyClass: |
class MyClass {} |
class MyClass {} |
Class MyClass\nEnd Class |
无 |
无 |
class MyClass; end |
type MyStruct struct {} |
struct MyStruct {} |
class MyClass {} |
class MyClass {} |
class MyClass {} |
| 构造函数例句 |
无 |
MyClass() {} |
MyClass() {} |
def __init__(self): |
MyClass() {} |
constructor() {} |
Private Sub Class_Initialize() |
无 |
无 |
def initialize; end |
无 |
impl MyStruct { fn new() -> Self { MyStruct{} } } |
init() {} |
function __construct() {} |
constructor() {} |
| 调用函数例句 |
add(1, 2); |
add(1, 2); |
Add(1, 2); |
add(1, 2) |
add(1, 2); |
add(1, 2); |
Add(1, 2) |
add 1 2 |
Add 1 2 |
add(1, 2) |
add(1, 2) |
add(1, 2); |
add(1, 2) |
add(1, 2); |
add(1, 2) |
| 调用子函数例句 |
无 |
obj.method(); |
obj.Method(); |
obj.method() |
obj.method(); |
obj.method(); |
obj.Method |
无 |
无 |
obj.method |
obj.Method() |
obj.method(); |
obj.method() |
obj->method(); |
obj.method() |
| 继承例句 |
无 |
class Derived : public Base {}; |
class Derived : Base {} |
class Derived(Base): |
class Derived extends Base {} |
class Derived extends Base {} |
Class Derived\n Inherits Base\nEnd Class |
无 |
无 |
class Derived < Base; end |
无(通过组合) |
struct Derived; impl Base for Derived {} |
class Derived: Base {} |
class Derived extends Base {} |
class Derived : Base() |
| 多态例句 |
无 |
virtual void func(); |
virtual void Method(); |
无 |
void method() {}(默认虚) |
无 |
无 |
无 |
无 |
无 |
interface { method() } |
trait Trait { fn method(&self); } |
func method()(默认虚) |
无 |
open fun method() {} |
| 公开/私有声明修饰符 |
无 |
public: private: |
public private |
_开头表示私有 |
public private |
无 |
Public Private |
无 |
无 |
public private |
大写公开,小写私有 |
pub |
public private |
public private |
public private |
| 静态/动态声明修饰符 |
static |
static |
static |
@staticmethod |
static |
static |
Static |
无 |
无 |
self. |
无 |
无 |
static |
static |
companion object |
| 接口/抽象类修饰符 |
无 |
=0(纯虚) |
abstract |
from abc import ABC |
interface abstract |
无 |
无 |
无 |
无 |
module |
interface |
trait |
protocol |
interface |
interface abstract |
| 单行注释例句 |
// comment |
// comment |
// comment |
# comment |
// comment |
// comment |
' comment |
# comment |
# comment |
# comment |
// comment |
// comment |
// comment |
// comment |
// comment |
| 多行注释例句 |
/* comment */ |
/* comment */ |
/* comment */ |
''' comment ''' |
/* comment */ |
/* comment */ |
' comment ' |
:<<'END'\ncomment\nEND |
<# comment #> |
=begin\ncomment\n=end |
/* comment */ |
/* comment */ |
/* comment */ |
/* comment */ |
/* comment */ |
| 基本数据类型 |
int, float, char |
int, float, char |
int, float, char |
int, float, str |
int, float, char |
number, string |
Integer, String |
int, string |
int, string |
Integer, String |
int, float |
i32, f64 |
Int, Double |
int, string |
Int, Double |
| 变量声明例句 |
int x = 10; |
int x = 10; |
int x = 10; |
x = 10 |
int x = 10; |
let x = 10; |
Dim x As Integer = 10 |
x=10 |
$x = 10 |
x = 10 |
var x int = 10 |
let x: i32 = 10; |
var x = 10 |
$x = 10; |
val x = 10 |
| 变量作用域例句 |
{}块级 |
{}块级 |
{}块级 |
函数级 |
{}块级 |
{}块级 |
过程级 |
函数级 |
函数级 |
块级 |
{}块级 |
{}块级 |
{}块级 |
{}块级 |
{}块级 |
| 访问修饰符 |
无 |
public private |
public private |
_开头 |
public private |
无 |
Public Private |
无 |
无 |
public private |
大写公开 |
pub |
public private |
public private |
public private |
| 存储类修饰符 |
static extern |
static extern |
static |
无 |
static final |
const let |
Static |
readonly |
ReadOnly |
无 |
const |
const |
let |
const |
const val |
| 运算符类型算术运算符 |
+ - * / % |
+ - * / % |
+ - * / % |
+ - * / % ** |
+ - * / % |
+ - * / % ** |
+ - * / Mod |
+ - * / % |
+ - * / % |
+ - * / % ** |
+ - * / % |
+ - * / % |
+ - * / % |
+ - * / % ** |
+ - * / % |
| 运算符类型比较运算符 |
== != < > <= >= |
== != < > <= >= |
== != < > <= >= |
== != < > <= >= is is not |
== != < > <= >= |
== != < > <= >= === !== |
= <> < > <= >= |
-eq -ne -lt -gt -le -ge |
-eq -ne -lt -gt -le -ge |
== != < > <= >= |
== != < > <= >= |
== != < > <= >= |
== != < > <= >= |
== != < > <= >= === !== |
== != < > <= >= |
| 运算符类型逻辑运算符 |
`&& |
|
!` |
`&& |
|
!` |
`&& |
|
!` |
and or not |
`&& |
|
!` |
`&& |
|
| 运算符类型位运算运算符 |
`& |
^ ~ << >>` |
`& |
^ ~ << >>` |
`& |
^ ~ << >>` |
`& |
^ ~ << >>` |
`& |
^ ~ << >>` |
`& |
^ ~ << >>` |
And Or Xor Not |
`& |
^` |
| 运算符类型赋值运算符 |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
= += -= |
| 循环类型for例句 |
for(int i=0;i<10;i++){} |
for(int i=0;i<10;i++){} |
for(int i=0;i<10;i++){} |
for i in range(10): |
for(int i=0;i<10;i++){} |
for(let i=0;i<10;i++){} |
For i=1 To 10\nNext |
for i in {1..10}; do done |
for($i=0;$i -lt 10;$i++){} |
for i in 1..10 do end |
for i:=0;i<10;i++{} |
for i in 0..10 {} |
for i in 0..<10 {} |
for($i=0;$i<10;$i++){} |
for(i in 0..9){} |
| 判断类型if例句 |
if(x>0){} |
if(x>0){} |
if(x>0){} |
if x>0: |
if(x>0){} |
if(x>0){} |
If x>0 Then\nEnd If |
if [ $x -gt 0 ]; then fi |
if($x -gt 0){} |
if x>0; end |
if x>0 {} |
if x>0 {} |
if x>0 {} |
if($x>0){} |
if(x>0){} |
| 判断类型if-else例句 |
if(x>0){}else{} |
if(x>0){}else{} |
if(x>0){}else{} |
if x>0:\n else: |
if(x>0){}else{} |
if(x>0){}else{} |
If x>0 Then\nElse\nEnd If |
if [ $x -gt 0 ]; then else fi |
if($x -gt 0){}else{} |
if x>0; else; end |
if x>0 {} else {} |
if x>0 {} else {} |
if x>0 {} else {} |
if($x>0){}else{} |
if(x>0){}else{} |
| 判断类型switch例句 |
switch(x){case 1:} |
switch(x){case 1:} |
switch(x){case 1:} |
无 |
switch(x){case 1:} |
switch(x){case 1:} |
Select Case x\n Case 1\nEnd Select |
case $x in 1) ;; esac |
switch($x){1{}} |
case x; when 1; end |
switch x{case 1:} |
match x{1=>} |
switch x{case 1:} |
switch($x){case 1:} |
when(x){1->} |
| 定义数组例句 |
int arr[10]; |
int arr[10]; |
int[] arr = new int[10]; |
arr = [1,2,3] |
int[] arr = new int[10]; |
let arr = [1,2,3]; |
Dim arr(9) As Integer |
arr=(1 2 3) |
$arr = @(1,2,3) |
arr = [1,2,3] |
var arr [10]int |
let arr = [1,2,3]; |
var arr = [1,2,3] |
$arr = array(1,2,3); |
val arr = arrayOf(1,2,3) |
| 调用数组元素例句 |
arr[0]; |
arr[0]; |
arr[0]; |
arr[0] |
arr[0]; |
arr[0]; |
arr(0) |
${arr[0]} |
$arr[0] |
arr[0] |
arr[0] |
arr[0]; |
arr[0] |
$arr[0]; |
arr[0] |
| 定义指针例句 |
int *p; |
int *p; |
unsafe int* p; |
无 |
无 |
无 |
无 |
无 |
无 |
无 |
var p *int |
let p: *i32; |
无 |
无 |
无 |
| 调用指针例句 |
*p = 10; |
*p = 10; |
*p = 10; |
无 |
无 |
无 |
无 |
无 |
无 |
无 |
*p = 10 |
*p = 10; |
无 |
无 |
无 |
| 抛出异常例句 |
无 |
throw exception(); |
throw new Exception(); |
raise Exception() |
throw new Exception(); |
throw new Error(); |
Err.Raise |
exit 1 |
throw "error" |
raise "error" |
panic("error") |
panic!("error") |
fatalError() |
throw new Exception(); |
throw Exception() |
| 捕获异常例句 |
无 |
try{}catch{} |
try{}catch{} |
try:\n except: |
try{}catch{} |
try{}catch{} |
On Error GoTo |
trap |
try{}catch{} |
begin rescue end |
defer |
match result{Ok(_)=>} |
do{}catch{} |
try{}catch{} |
try{}catch{} |
| finally块例句 |
无 |
try{}catch{}finally{} |
try{}catch{}finally{} |
try:\n finally: |
try{}catch{}finally{} |
try{}catch{}finally{} |
无 |
无 |
try{}catch{}finally{} |
begin ensure end |
defer |
无 |
defer{} |
try{}catch{}finally{} |
try{}finally{} |
| 定义容器(数组/列表)例句 |
int arr[10]; |
vector<int> v; |
List<int> list; |
lst = [1,2,3] |
ArrayList<Integer> list; |
let arr = [1,2,3]; |
Collection |
arr=(1 2 3) |
$list = @(1,2,3) |
arr = [1,2,3] |
slice := []int{1,2,3} |
let v = vec![1,2,3]; |
var arr = [1,2,3] |
$arr = [1,2,3]; |
val list = listOf(1,2,3) |
| 调用容器元素例句 |
arr[0]; |
v[0]; |
list[0]; |
lst[0] |
list.get(0); |
arr[0]; |
coll(0) |
${arr[0]} |
$list[0] |
arr[0] |
slice[0] |
v[0]; |
arr[0] |
$arr[0]; |
list[0] |
| 定义字典/哈希表例句 |
无 |
map<string,int> m; |
Dictionary<string,int> d; |
d = {'a':1} |
HashMap<String,Integer> map; |
let obj = {a:1}; |
Dictionary |
declare -A arr |
$hash = @{a=1} |
h = {a:1} |
m := map[string]int{"a":1} |
let m = HashMap::new(); |
var d = ["a":1] |
$arr = ["a"=>1]; |
val map = mapOf("a" to 1) |
| 调用字典元素例句 |
无 |
m["a"]; |
d["a"]; |
d['a'] |
map.get("a"); |
obj.a; |
dict("a") |
${arr[a]} |
$hash["a"] |
h[:a] |
m["a"] |
m["a"]; |
d["a"] |
$arr["a"]; |
map["a"] |
| 运算符重载例句 |
无 |
T operator+(T a,T b){} |
public static T operator+(T a,T b){} |
def __add__(self,other): |
无 |
无 |
无 |
无 |
无 |
def +(other) end |
无 |
impl Add for T{} |
func +(l:T,r:T)->T{} |
无 |
operator fun plus(other:T):T{} |
| 函数重载例句 |
无 |
void f(int); void f(double); |
void F(int); void F(double); |
无 |
void f(int){} void f(double){} |
无 |
无 |
无 |
无 |
def f(a) end; def f(a,b) end |
无 |
无 |
func f(_ i:Int){} func f(_ d:Double){} |
无 |
fun f(i:Int){} fun f(d:Double){} |
| 多态(虚函数/方法重写)例句 |
无 |
virtual void f(); |
virtual void F(); |
无 |
@Override void f(){} |
无 |
无 |
无 |
无 |
无 |
interface I{f()} |
trait T{fn f(&self);} |
func f(){}(协议) |
无 |
open fun f(){} |
| 定义接口例句 |
无 |
class I{virtual void f()=0;} |
interface I{void F();} |
class I(ABC): |
interface I{void f();} |
无 |
无 |
无 |
无 |
module I; end |
type I interface{f()} |
trait T{fn f(&self);} |
protocol P{func f()} |
interface I{function f();} |
interface I{fun f()} |
| 调试输出日志例句 |
printf("msg"); |
cout << "msg"; |
Console.WriteLine("msg"); |
print("msg") |
System.out.println("msg"); |
console.log("msg"); |
Debug.Print "msg" |
echo "msg" |
Write-Output "msg" |
puts "msg" |
fmt.Println("msg") |
println!("msg"); |
print("msg") |
echo "msg"; |
println("msg") |
| 继承语法例句 |
无 |
class D:public B{}; |
class D:B{} |
class D(B): |
class D extends B{} |
class D extends B{} |
Class D: Inherits B |
无 |
无 |
class D < B; end |
无 |
struct D; impl B for D{} |
class D:B{} |
class D extends B{} |
class D:B() |
| 多态支持例句 |
无 |
virtual+指针 |
virtual+引用 |
鸭子类型 |
接口 |
原型链 |
无 |
无 |
无 |
鸭子类型 |
接口 |
trait对象 |
协议 |
接口 |
接口 |
| 公开声明例句 |
无 |
public: |
public |
无 |
public |
无 |
Public |
无 |
无 |
public |
大写 |
pub |
public |
public |
public |
| 私有声明例句 |
static |
private: |
private |
_开头 |
private |
无 |
Private |
无 |
无 |
private |
小写 |
无 |
private |
private |
private |
| 静态成员声明例句 |
static int x; |
static int x; |
static int x; |
@staticmethod |
static int x; |
static x=1; |
Static x As Integer |
无 |
static $x=1 |
@@x=1 |
无 |
static x:i32=1; |
static var x=1 |
static $x=1; |
companion object{val x=1} |
| 动态成员声明例句 |
无 |
无 |
dynamic |
动态添加 |
无 |
动态添加 |
无 |
无 |
无 |
动态添加 |
无 |
无 |
无 |
动态添加 |
无 |
| 接口定义例句 |
无 |
class I{virtual void f()=0;} |
interface I{void F();} |
class I(ABC): |
interface I{void f();} |
无 |
无 |
无 |
无 |
module I; end |
type I interface{f()} |
trait T{fn f(&self);} |
protocol P{func f()} |
interface I{function f();} |
interface I{fun f()} |
| 抽象类定义例句 |
无 |
class A{virtual void f()=0;} |
abstract class A{abstract void F();} |
class A(ABC): |
abstract class A{abstract void f();} |
无 |
无 |
无 |
无 |
class A; end |
无 |
trait T{fn f(&self);} |
class A{func f()} |
abstract class A{abstract function f();} |
abstract class A{abstract fun f()} |
| 函数传递参数语法例句 |
f(1,2); |
f(1,2); |
F(1,2); |
f(1,2) |
f(1,2); |
f(1,2); |
f 1,2 |
f 1 2 |
f 1 2 |
f(1,2) |
f(1,2) |
f(1,2); |
f(1,2) |
f(1,2); |
f(1,2) |