头图

Write in front

This is Ozelot. A college student who is learning to program and hopes to communicate and learn with you guys. design plan about the programming language Cesno. Welcome to comment and exchange!

Tip: The final design has not been decided yet, there may be many design deficiencies that need to be optimized, so the content may be changed. Because I couldn't leave it unlabeled, I had to label it as "programmer". Hope it doesn't cause trouble to everyone.

Note: Because Cesno has not been produced yet, only the grammar specifications of Cesno are recorded here. Because of this, the highlighting of the code part may not be guaranteed to be displayed correctly every time. If it affects reading, I am very sorry!


Basic grammatical structure

This part contains the basic grammatical structure of Cesno. It is designed to allow developers to better understand Cesno and quickly master the grammar.

Statement

A Cesno sentence is composed of sentence body and a semicolon appended to the end. like this:

int a = 10;

This sentence is a variable statement . Among them, the content in the sentence body represents "declare a as an integer variable and receive 10 as the value", and the semicolon marks the end of the sentence. More about "declaration" will appear in "Cesno Variables".

Cesno uses a semicolon instead of a newline to end a statement. Therefore, programmers can appropriately add blank lines to make the code more readable. For example, write like this

var x = 1 + 2 + 3;

Equivalent to

var x = 1 + 2
          + 3;

Or insert a newline version in other blank spaces. Line breaks can be treated as spaces by Cesno (in fact, indentation is also made up of spaces in most cases). You should not break in a word, number, operator of more than one word, or other "things" that don't contain spaces, although this may sound obvious.

definition

A Cesno definition consists of the definition starting keyword (these special keywords are usually abbreviated as definition word ) and the subsequent definition body . Normally, the definition does not need to end with a semicolon, at least not in the definition that Cesno already contains.

The following is the definition of a function:

function void greetings(string name)
{
    print("Hello", name);
}

function that marks the start of the function definition, the return value void , the function name greetings , the function parameter list (string name) and the function body { print("Hello", name); } . Among them, except that function is a definition word, the rest are all definitions.

This is the definition of a class:

class Test
{
    public int member;
}

It receives a class name Test , the body of a class. class is a definition word, and all the following are definitions.

Cesno is designed to be user-friendly: it allows users to customize their own statements. It is worth noting that because the definition word is also type , in order to prevent statement , the definition of Cesno is not recommended to use the equal sign.

Basic code structure

Cesno is object-oriented, but unlike Java, you need to create a common class for each piece of code. The following are several code structures that Cesno can recognize.

Usual structure

void main()
{
    print("Hello world!");
}

This is a standard Cesno program written in accordance with the usual structure, and it will output "Hello world!". There will not be much discussion about the return value type of the main function. Most of the time, the return type of the main function is set to void . Of course, Cesno does not rely on the return value type to identify the main function.

Simple structure

A simplest Cesno program might look like this:

print("Hello world!");

If complex code structure is not required, users can write Cesno code as Python or other scripting languages. When compiling, the user's code will be converted into the usual structure.


Ozelot_Vanilla
11 声望3 粉丝

希望能为更多人做出一点贡献