crex

所属分类:编程语言基础
开发工具:C
文件大小:0KB
下载次数:0
上传日期:2023-08-03 14:56:00
上 传 者sh-1993
说明:  一种编程语言,
(A programming language,)

文件列表:
.vscode/ (0, 2023-11-28)
.vscode/c_cpp_properties.json (373, 2023-11-28)
.vscode/settings.json (375, 2023-11-28)
.vscode/tasks.json (713, 2023-11-28)
a.out (0, 2023-11-28)
src/ (0, 2023-11-28)
src/.main.crf.swp (1024, 2023-11-28)
src/__pycache__/ (0, 2023-11-28)
src/__pycache__/stdlib.cpython-38.pyc (293, 2023-11-28)
src/a.out (962048, 2023-11-28)
src/ast/ (0, 2023-11-28)
src/ast/a.out (16848, 2023-11-28)
src/ast/ast.c (4340, 2023-11-28)
src/ast/ast.h (4326, 2023-11-28)
src/build.sh (104, 2023-11-28)
src/code-gen/ (0, 2023-11-28)
src/code-gen/gen.c (9406, 2023-11-28)
src/code-gen/gen.h (152, 2023-11-28)
src/code.py (115, 2023-11-28)
src/lexer/ (0, 2023-11-28)
src/lexer/a.out (21520, 2023-11-28)
src/lexer/lexer.c (15997, 2023-11-28)
src/lexer/lexer.h (776, 2023-11-28)
src/main.c (1497, 2023-11-28)
src/main.crf2 (3811, 2023-11-28)
src/output_file (0, 2023-11-28)
src/parser/ (0, 2023-11-28)
src/parser/a.out (16856, 2023-11-28)
src/parser/parser.c (11786, 2023-11-28)
src/parser/parser.h (226, 2023-11-28)
src/parser/parser.o (1368, 2023-11-28)
src/runtime-stuff/ (0, 2023-11-28)
src/runtime-stuff/a.out (18192, 2023-11-28)
src/runtime-stuff/code.cpp (147, 2023-11-28)
src/runtime-stuff/core.h (344, 2023-11-28)
src/stdlib.py (64, 2023-11-28)

### Download Not done yet. ### Documentation ## Hello world ``` cout("Hello World"); ``` # Contents [Syntax](https://github.com/shourdev/crex/blob/master/#syntax)
[Data](https://github.com/shourdev/crex/blob/master/#data)
[Expressions](https://github.com/shourdev/crex/blob/master/#expressions)
[Conditionals](https://github.com/shourdev/crex/blob/master/#conditionals)
[Loop](https://github.com/shourdev/crex/blob/master/#loops)
[Functions](https://github.com/shourdev/crex/blob/master/#functions) # Syntax Syntax are the rules that define how the statements and expressions of the language should be.
All this means is that it's like the grammer of the language.
Here is the basic syntax
Statements and expressions(individual) are terminated with a ";"
``` cout("hi"); ``` Blocks can't be used alone, they only work with functions,ifs,structs,loops etc. They end with a # ``` if (2+2==4) cout("true"); # ``` # Data In crex to store data we can use a variable and a list. A variable is a named memory location, you can store 5 types of data in it those are:
int (integers),
float (decimals),
strings (text),
bool (true or false) and
structs
We will talk about structs later on.
## Variables To make an int variable ``` int myvar = 2; ``` ``` int myvar2 = 2+2; ``` The first example makes an int called as myvar and store 2 in it and in the second we have myvar2 which stores the value of 2+2 which is 4
For float ``` float myvar = 2.2; ``` For strings ``` string myvar = "hello!"; ``` and for bool ``` bool myvar = true; ``` or ``` bool myvar2 = false; ``` Structs will be in the [structs](https://github.com/shourdev/crex/blob/master/)
## Lists Lists is a sequence of several variables grouped under one name called the list
Int lists ``` int[] mylist; addelementonindex(mylist,0,4); ``` This stores 4 in the 0 index, using addelementonindex function you can add list element, only one however, as you give the index. You can use the addlistelements to add multiple elements.
``` addlistelements(mylist,3,52,25); ``` Float ``` float[] mylist = [2.2,3.4]; ``` String ``` string[] mylist = ["hi","hello"]; ``` ## Accessing variables and lists Variables can be accessed using their name, while to access list you use the name and [] where you mention the index, for example to access ``` int[] numbers = [2,3]; ``` use ``` numbers[0]; ``` This will refer to the data in the 0th index which is 2 (keep in mind the index starts at 0 not 1!)
Obviously just writing the name of the variable or doing numbers[0] won't do anything they are the part of *expressions* which will be in the next section, and these expressions can be passed to functions to do something out of their data.
If you want to output the values you can do like this. ``` cout(myvar); cout(mylist[0]); ``` I will go in an order so these functions like cout shall be in the functions chapter but cout is a pretty common function, so knowing it from now can benefit you, in the next section. ## Assignment To change value of a variable just write the name = the new data. ``` int t; t = 1 ``` (Note, when you don't give any =, strings will be null, int will be 0 and float will be 0.0)
Here we reassign the data of t as 1
For lists ``` int[] list = [2,3]; list[0] = 1; ``` this changes 2 to 1 # Expressions Expressions are anything that will execute and turns into a value, like 2+2 is an expression test+test2 is an expression. In crex we have 3 types of expressions they are arithmetic,relational and logical. Expressions is made up of - Literals: are anything like int data (2,3,43 etc) string literals are "hi", "hello" etc float are 2.2,2.4
- Variables: as you know was in the last section
- Operators: like + for addition - for subtraction * for multiplication etc
- Functions calls: are calling functions like we called cout()
## Types of expressions ### Arithmetic Addition,subtraction,multiplication and division
Addition ``` 2+2 ``` Multiplication ``` 2*2 ``` Subtraction ``` 2-2 ``` Division ``` 2/2 ``` ### Relational They produce output as true or false
Evaluates to true is 2+2 is equal to 4 ``` 2+2==4 ``` Evaluates to true is 2+2 is not equal to 5 ``` 2+2!=5 ``` Evaluates to true is 2 is greater than 1 ``` 2>1 ``` Evaluates to true is 2 is smaller than 4 ``` 2<4 ``` ### Logical They combine relational expressions.
Evaluates to true if 2+2 is 4 and 3+3 is 6 ``` 2+2==4 && 3+3==6 ``` Evaluates to true if either of the two expressions are true ``` 2+2==4 || 3+3 == 9 ``` ## Misc stuff Assignment of variables (when you change value of a variable) is an expression in crex like languages like c.
# Conditionals Conditionals in crex are if and else statements.
First use the if keyword followed by a ( the expression, which must evaluate to 1 or true, then followed by the ) if the condition is true or 1 the if block will run if not then the else block will run and if their is any other if that matches the condition that will run. ``` if (2+2==4) cout("Yes true"); # if (2+2==5) cout("HOW!"); # else cout("Maths is broken or something!"); # ``` In this code if 2+2 is 4 it will print yes true if 2+2 is 5 it will print "HOW!" and if none of these if are evaluated than the else will be run

近期下载者

相关文件


收藏者