-
Notifications
You must be signed in to change notification settings - Fork 2
Home
This document details the features and use cases of CPL for the 0.0 release. This release is intended to be Turing complete and serve as a demo of the possibilities of this language. Please file bugs to https://github.com/m-yuhas/cpl/issues.
- Install Swift:
- On macOS install X
- On Linux systems follow the instructions at https://swift.org/download/#releases
- Clone the repository:
git clone https://github.com/m-yuhas/cpl.git
- Build and Install:
chmod +x build.sh
./build.sh install
The install script will build and install the program to /usr/bin/ so that it is accessible via bash. If you would prefer to install in a different location then use the following command:
./build.sh install /path/to/install/directory
To uninstall, use the same script:
./build.sh uninstall
Or:
./build.sh uninstall /path/to/install/directory
- Start Programming:
Use your favorite text editor to write a program and save it as a utf-8 encoded file. To run your script simply type:
cpl <your script>
As of 0.0 release, the following features are implemented:
Just as with other scripting languages the first line of the program can define bash path of the program in case the user wants to make it executable. Only the first line of the program can take this value.
#!/usr/bin/cpl
This defines a single line comment. Text on this line will not be executed.
注解:这是一个注解
This command allows the user to print text and the current value of variables or expressions. The text to print must be in quotation marks. A variable or expression will be evaluated and printed if it follows the pound (#) sign. Note that unlike other programming languages, all types of quotes are accepted in this expression and the angle of the quotes is not dependent on their position.
输出:“你好世界 #2+2 #东西”
This command causes a branch in the program flow. 如果 evaluates an expression and if true the the lines between 如果 and 否则 will executed. If there is no 否则 then all the lines up to 结束支 will be executed. The three types of expressions that can be evaluated are equality (=), greater than (>), and less then (<). Note that unlike other programming languages, equality is expressed with a single equals sign, not a double one.
如果 东西=3.1
输出:“表达式对的”
否则
输出:“表达式否的”
结束支
This command takes an initial condition and loops over a block of code until the final condition is met. Note that the programmer must manually modify the loop counter every cycle. The loop counter will be available outside the scope of the loop, but variables declared within the loop will not be available after the loop terminates.
从 东西=1 直到 5
输出:“循环数:#东西”
东西=东西+1
结束圈
This command checks if a condition is true and then continues executing a block of code until the condition is no longer satisfied. All variables declared within the loop will not be available after the loop terminates.
东西=0
当 东西<10
输出:“#东西”
东西=东西+1
结束圈
This command will allow the programmer to break out of the current loop. If there are nested loops it breaks out of the loop that was most recently pushed onto the stack
循环数=0
当 1=1
循环数=循环数+1
如果 循环数>100
跳出
结束支
结束圈
输出:“#循环数”
Any string that does not contain !,@,#,$,%,^,&,*,(,),[,],{,},",+,-,\,|,/,<,=,>,/,or; and does not start with a number or a keyword can be used as a variable. A variable is set using a single equals sign (=). The expression on the right is stored to the variable on the left.
派=3.141592654