Skip to content

Commit

Permalink
Merge pull request #65 from iewnfod/nightly
Browse files Browse the repository at this point in the history
Update to Stable
  • Loading branch information
iewnfod authored Dec 12, 2023
2 parents c2f5639 + e77523d commit 5e22224
Show file tree
Hide file tree
Showing 25 changed files with 802 additions and 520 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"Ucase",
"UMINUS",
"UPLUS",
"VARTYPE",
"WRITEFILE"
]
}
File renamed without changes.
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# CAIE Code (cpc)

<br/>
<p align="center">
<a href="./assets/cpc.svg">
<img src="./assets/cpc.svg" width="100" height="100" alt="logo">
Expand Down Expand Up @@ -64,6 +63,7 @@ It runs the entire file if `filepath` is provided, otherwise, it enters playgrou
| Mnemonic | Option | Description |
| -------- | ------ | ----------- |
| `-c` | `--config` | To set configs of this interpreter |
| `-d` | `--document` | To show the official document |
| `-h` | `--help` | To show the help page |
| `-k` | `--keywords` | To show all the keywords |
| `-m` | `--migrate` | To migrate `.p` files to `.cpc` in a specified directory |
Expand All @@ -73,8 +73,8 @@ It runs the entire file if `filepath` is provided, otherwise, it enters playgrou
| `-v` | `--version` | To show the version of this interpreter |
| `-gt` | `--get-tree` | To show the tree of the program after being parsed |
| `-lc` | `--list-configs` | To list all the configs of the interpreter |
| `-rc` | `--reset-configs` | To reset all the configs of the interpreter |
| `-ne` | `--no-error` | To remove all error messages |
| `-rc` | `--reset-configs` | To reset all the configs of the interpreter |

### Config

Expand Down Expand Up @@ -298,15 +298,15 @@ The following items give the `DATATYPE`, its description, and the default value
IF <condition> THEN
<statements>
ENDIF
IF <condition> THEN
<statements>
ELSE
<statements>
ENDIF
```
* CASE statements
> IMPORTANT: official standards do not have semicolons;` here
> IMPORTANT: official standards do not have semicolons `;` here
```
CASE OF <identifier>
<value> : <statements>;
Expand Down Expand Up @@ -339,15 +339,15 @@ The following items give the `DATATYPE`, its description, and the default value
PROCEDURE <identifier> ()
<statements>
ENDPROCEDURE

PROCEDURE <identifier> (<param> : <data type>, ...)
<statements>
ENDPROCEDURE
```
* call a procedure
```
CALL <identifier> ()

CALL <identifier> (<value>, ...)
```
* functions with return values
Expand All @@ -356,15 +356,15 @@ The following items give the `DATATYPE`, its description, and the default value
<statements>
RETURN <value>
ENDFUNCTION

FUNCTION <identifier> (<param> : <data type>, ...) RETURNS <data type>
<statements>
RETURN <value>
ENDFUNCTION
* call a function with return values
```
<identifier> ()
<identifier> (<value>, ...)
```
* Before the parameters of those sub-routines, you *can* use `BYREF` or `BYVAL` to force the program to pass those parameters by reference or by-value respectively. If no `BYREF` nor `BYVAL` is given, the program will follow the prior parameter. If the program cannot find a clear indication it will, by default pass parameters by value.
Expand Down Expand Up @@ -433,15 +433,15 @@ The following items give the `DATATYPE`, its description, and the default value
PRIVATE PROCEDURE <identifier> (<params>)
<statements>
ENDPROCEDURE
PUBLIC PROCEDURE <identifier> (<params>)
<statements>
ENDPROCEDURE
PRIVATE FUNCTION <identifier> (<params>) RETURNS <type>
<statements>
ENDFUNCTION
PUBLIC FUNCTION <identifier> (<params>) RETURNS <type>
<statements>
ENDFUNCTION
Expand Down Expand Up @@ -533,6 +533,10 @@ The following items give the `DATATYPE`, its description, and the default value
> if the Python code does not assign a value to `_result`, the function will return `None`.
> you *must* pass all variables used in the Python code in `*args`, otherwise, it will not run correctly.
* `VARTYPE(v)` is an interface to get the type of `v` and return it as a string.

* `ANY` is a type that used to allow some unknown type data.

* For more non-official scripts, please see [scripts](./scripts).

## Targets
Expand All @@ -544,8 +548,8 @@ The following items give the `DATATYPE`, its description, and the default value
- [ ] Implement a high performance virtual machine to run. (Similar as the solution of Java)
### Version 0.3.x Target
- [ ] Allow building into executable binary file.
### 长期目标
- [ ] Provide more [unofficial functions](./scripts/README.md).
### Long-term Targets
- [ ] Provide more packages for use.
- [ ] Increase running speed and stability.
- [ ] Implement bootstrap.

Expand Down
39 changes: 21 additions & 18 deletions README_zh.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
# CAIE Code (cpc)

<br/>

<p align="center">
<a href="./assets/cpc.svg">
<img src="./assets/cpc.svg" width="100" height="100" alt="logo">
</a>
<h3 align="center">the CAIE Pseudocode Interpreter</h3>
<h3 align="center">CAIE 伪代码解释器</h3>
</p>
<p align="center">
<a href="./README_cn.md">中文</a> | <a href="./README.md">English</a>
Expand Down Expand Up @@ -52,6 +50,7 @@ cpc [file_paths] [options]
| Mnemonic | Option | Description |
| -------- | ------ | ----------- |
| `-c` | `--config` | 对解释器进行设置 |
| `-d` | `--document` | 使用系统默认方式打开官方规范文件 |
| `-h` | `--help` | 显示帮助页面 |
| `-k` | `--keywords` | 显示所有的关键字 |
| `-m` | `--migrate` | 将一个目录中的所有 `.p` 文件切换为 `.cpc` |
Expand All @@ -61,8 +60,8 @@ cpc [file_paths] [options]
| `-v` | `--version` | 显示解释器当前版本 |
| `-gt` | `--get-tree` | 显示脚本解析后生成的可运行的树 |
| `-lc` | `--list-configs` | 显示解释器的所有设置 |
| `-rc` | `--reset-configs` | 删除解释器的所有设置 |
| `-ne` | `--no-error` | 禁止所有错误的输出 |
| `-rc` | `--reset-configs` | 删除解释器的所有设置 |

### 可选配置

Expand Down Expand Up @@ -104,24 +103,24 @@ cpc [file_paths] [options]
- `true`: 开启模拟更新
- `false`: 关闭模拟更新

### 常见问题
## 常见问题

#### 出现 `Import Error`
### 出现 `Import Error`
尝试手动安装依赖:
```shell
pip install -r requirements.txt
```

#### 成功执行了第四步的依赖安装但还是无法正常运行
### 成功执行了第四步的依赖安装但还是无法正常运行
`cpc`文件会优先选择 `PyPy3` 运行
因此,在安装依赖时,请确保安装在了正确版本的 `Python3`
可以使用 `<指定Python版本> -m pip install -r requirements.txt` 进行安装

#### Playground 模式下,上下左右键无法正常使用
### Playground 模式下,上下左右键无法正常使用
使用 `pip install readline` 安装依赖并尝试运行
`readline` 无法正常安装,请安装 `gnureadline`,即 `pip install gnureadline`,再尝试运行

#### cpc在启动时报OSError
### cpc在启动时报OSError
进入`cpc`安装目录,可使用
删除`.cpc_history`文件
更新`cpc`
Expand Down Expand Up @@ -278,7 +277,7 @@ NEXT i
IF <condition> THEN
<statements>
ENDIF
IF <condition> THEN
<statements>
ELSE
Expand Down Expand Up @@ -319,15 +318,15 @@ NEXT i
PROCEDURE <identifier> ()
<statements>
ENDPROCEDURE

PROCEDURE <identifier> (<param> : <data type>, ...)
<statements>
ENDPROCEDURE
```
* 无返回值函数调用
```
CALL <identifier> ()

CALL <identifier> (<value>, ...)
```
* 有返回值函数定义
Expand All @@ -336,15 +335,15 @@ NEXT i
<statements>
RETURN <value>
ENDFUNCTION

FUNCTION <identifier> (<param> : <data type>, ...) RETURNS <data type>
<statements>
RETURN <value>
ENDFUNCTION
* 有返回值函数调用
```
<identifier> ()
<identifier> (<value>, ...)
```
* 在定义函数的每个参数前,都可以使用 `BYREF` 或是 `BYVAL` 声明是需要引用还是复制。若一个参数前没有声明传入方式,会向上一个参数靠齐。在没有全部都没有声明,或者没有前一个参数可供参考时,默认的传入方式为 `BYVAL`
Expand Down Expand Up @@ -412,15 +411,15 @@ NEXT i
PRIVATE PROCEDURE <identifier> (<params>)
<statements>
ENDPROCEDURE
PUBLIC PROCEDURE <identifier> (<params>)
<statements>
ENDPROCEDURE
PRIVATE FUNCTION <identifier> (<params>) RETURNS <type>
<statements>
ENDFUNCTION
PUBLIC FUNCTION <identifier> (<params>) RETURNS <type>
<statements>
ENDFUNCTION
Expand Down Expand Up @@ -503,6 +502,10 @@ NEXT i
1
```

* `VARTYPE(v)` 获取`v`的数据类型并以字符串的形式返回

* `ANY` 这是一个任意类型用于允许一些未知类型的输入

* 更多非官方内置函数,请查阅 [scripts](./scripts)

## 目标
Expand All @@ -515,7 +518,7 @@ NEXT i
### Version 0.3.x 目标
- [ ] 支持直接编译为可执行文件
### 长期目标
- [ ] 提供更多[非官方函数](./scripts/README.md)
- [ ] 提供更多包
- [ ] 提高运行速度与效率
- [ ] 实现自举

Expand Down
9 changes: 9 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from ply import yacc
from ply import lex
from chardet import detect
import signal
# 导入色彩基础库,保证\033能正确的转译
import colorama
colorama.init()
Expand All @@ -31,6 +32,11 @@
multi_preline = '.'
home_path = HOME_PATH

# 处理keyboard interrupt
def signal_handler(_signal, _frame):
stack.raise_keyboard_interrupt()

signal.signal(signal.SIGINT, signal_handler)

# 错误的argument
def wrong_argument(msg):
Expand Down Expand Up @@ -112,6 +118,7 @@ def with_line():
options.standard_output()
# 运行
while 1:
stack.reset_keyboard_interrupt()
text = multi_input()
lexer.lineno = 1
# 尝试运行特殊指令
Expand Down Expand Up @@ -144,6 +151,8 @@ def with_file(path, preload=False):
text = remove_comment(f.read())
if not text:
return
# reset stack
stack.reset_keyboard_interrupt()

# 尝试运行
try:
Expand Down
16 changes: 11 additions & 5 deletions man/cpc.1
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ For more detailed information about this, you may look at README or
\f[B]-c\f[R], \f[B]\[en]config\f[R]
To set configs of this interpreter
.TP
\f[B]-gt\f[R], \f[B]\[en]get-tree\f[R]
To show the tree of the program after being parsed
\f[B]-d\f[R], \f[B]\[en]document\f[R]
To show the official document
.TP
\f[B]-h\f[R], \f[B]\[en]help\f[R]
To show the help page
Expand All @@ -49,9 +49,6 @@ To show all the keywords
\f[B]-m\f[R], \f[B]\[en]migrate\f[R]
To migrate .p files in a specified directory
.TP
\f[B]-ne\f[R], \f[B]\[en]no-error\f[R]
To remove all error messages
.TP
\f[B]-p\f[R], \f[B]\[en]parse\f[R]
To show parse information during running
.TP
Expand All @@ -65,8 +62,17 @@ git)
\f[B]-v\f[R], \f[B]\[en]version\f[R]
To show the version of installed \f[I]cpc\f[R]
.TP
\f[B]-gt\f[R], \f[B]\[en]get-tree\f[R]
To show the tree of the program after being parsed
.TP
\f[B]-lc\f[R], \f[B]\[en]list-configs\f[R]
To show all configs of the interpreter
.TP
\f[B]-ne\f[R], \f[B]\[en]no-error\f[R]
To remove all error messages
.TP
\f[B]-rc\f[R], \f[B]\[en]reset-configs\f[R]
To reset all the configs of the interpreter
.SS CONFIGS
.TP
\f[B]remote\f[R] - \f[I]Github\f[R] \f[I]Gitee\f[R]
Expand Down
16 changes: 11 additions & 5 deletions man/cpc.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ cpc - An interpreter for CAIE Pseudocode.
**-c**, **--config**
: To set configs of this interpreter

**-gt**, **--get-tree**
: To show the tree of the program after being parsed
**-d**, **--document**
: To show the official document

**-h**, **--help**
: To show the help page
Expand All @@ -31,9 +31,6 @@ cpc - An interpreter for CAIE Pseudocode.
**-m**, **--migrate**
: To migrate .p files in a specified directory

**-ne**, **--no-error**
: To remove all error messages

**-p**, **--parse**
: To show parse information during running

Expand All @@ -46,9 +43,18 @@ cpc - An interpreter for CAIE Pseudocode.
**-v**, **--version**
: To show the version of installed *cpc*

**-gt**, **--get-tree**
: To show the tree of the program after being parsed

**-lc**, **--list-configs**
: To show all configs of the interpreter

**-ne**, **--no-error**
: To remove all error messages

**-rc**, **--reset-configs**
: To reset all the configs of the interpreter

## CONFIGS
**remote** - *Github* *Gitee*
: To decide the update source
Expand Down
Loading

0 comments on commit 5e22224

Please sign in to comment.