Skip to content

Commit

Permalink
enable -wall and -werror options
Browse files Browse the repository at this point in the history
format the codes

add cmake support

update token lexer

update doc and translate to english
  • Loading branch information
limuy2022 committed Nov 26, 2023
1 parent 0da62ac commit 86e81be
Show file tree
Hide file tree
Showing 36 changed files with 352 additions and 162 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@
build/
out/
bin/
cmake_third_party/
Testing/
CMakeFiles/
.ninja_deps
.ninja_log
build.ninja
cmake_install.cmake
CMakeCache.txt
CMakeLists.txt
Makefile
rules.ninja
compile_commands.json
Expand Down
72 changes: 72 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
cmake_minimum_required(VERSION 3.28)
project(Trc CXX)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_CXX_STANDARD 20)
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
link_directories("${PROJECT_SOURCE_DIR}/bin")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Werror")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror")

add_subdirectory("cmake_third_party/googletest")
include_directories("cmake_third_party/googletest/googletest/include")

add_library(language_module)
target_sources(language_module
PUBLIC
FILE_SET CXX_MODULES FILES
language/language.cppm
)

message("${LANGUAGE_SOURCES}")

add_library(Chinese language/chinese.cpp)

add_library(English language/english.cpp)

add_library(language language/english.cpp)

target_link_libraries(Chinese language_module)
target_link_libraries(English language_module)
target_link_libraries(language language_module)

file(GLOB_RECURSE CPPMSOURCES "*.cppm")
file(GLOB_RECURSE CPP_SOURCES "src/*.cpp")

message(${CPP_SOURCES})

add_library(foo)

target_sources(foo
PUBLIC
FILE_SET CXX_MODULES FILES
${CPPMSOURCES}
)

add_executable(Trc ${CPP_SOURCES})

target_link_libraries(Trc foo)
target_link_libraries(Trc language)


file(GLOB_RECURSE TEST_SOURCES "tests/unittest/*.cpp")
file(GLOB_RECURSE TEST_MODULE_SOURCES "tests/unittest/*.cppm")
add_library(testmodulefiles)

target_sources(testmodulefiles
PUBLIC
FILE_SET CXX_MODULES FILES
${CPPMSOURCES}
${TEST_MODULE_SOURCES}
)

add_executable(unittest
${CPP_SOURCES}
${TEST_SOURCES}
)
target_compile_definitions(unittest PRIVATE "UNITTEST")
target_link_libraries(unittest testmodulefiles language gtest)
58 changes: 28 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
# Trc

## Trc是一个基于栈的编程语言
## Trc is a stack-based programming language

Trc是一个功能强大,工具链完善,容易上手的解释型语言,易于学习和使用,并且也容易被其他c++项目使用。
Trc's syntax is easy,and have full toolchain.It is easy to learn modern c++ and compiler,too.

## 语言
## language

完全由C++编写,采用全新的c++20标准,并且完全使用模块(module)特性
100% C++

## 目标
Using c++ 20 standard and use module feature

#### Python的简洁
## Goal

#### Java的速度
#### as easy as Python

#### lua的体积
#### as fast as Java

## 项目站点
#### as small as lua

## project website

[Gitee](https://gitee.com/li-muyangangel/trc.git)
[GitHub](https://github.com/limuy2022/trc.git)

## 具体文档说明请参考
## All docs reference

[所有文档](doc)
[All docs](doc)

## 快速使用
#### 由于Linux系统兼容性过低,所以请参考下一章自行编译安装
#### windows请直接使用编译好的二进制文件或参考下一章的编译教程
## How to compile

## 如何编译此项目
[编译指南](doc/developer/build.md)
[Compilation guide](doc/developer/build.md)

## 更改语言
## International

trc支持多种语言,支持方式是用相应的动态链接库文件覆盖掉原有的language文件即可
trc support many languages,the way to change language is that uses the language's dynamic linked library to replace the original language library

## 简单例子
## Simple examples

### hello world

```
println("hello world!")
```

### 求1到n中的偶数
### calculate even numbers from 1 to n

```
a := int(input())
Expand All @@ -56,7 +55,7 @@ while a > 0 {
}
```

### 大整数运算
### Big num calculation

```
a := 1231234561234
Expand All @@ -70,19 +69,18 @@ del "c"
println(a * b)
```

### 更多例子请参考

[更多例子](tests/black_test/program)
[more example](tests/black_test/program)

## 联系作者
## Contact author

微信:angelgel2020
Wechat:angelgel2020

QQ:3570249647

## 引用的开源软件
| 库名 | 用途 |
## Referenced Open-source software

| Library |Usage |
|:-----------|:-------|
| googletest | 单元测试框架 |
| googletest | Uniitest |

在此向开源软件的作者表示感谢!
Express my thanks to Open-source software contributors!
15 changes: 13 additions & 2 deletions doc/developer/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
### First

You can run this python script to install toolchain, build and install Trc and run unittest(just for Linux and Windows user)

```
cd script
python3 easy.py
```

### notice:require a compiler that is support c++ 23 standard,especially module support.Advice getting the newest compiler to compile.
### notice:require a compiler that is support c++ 23 standard,especially module support.Advice getting the newest compiler to compile

Use cmake or xmake to compile project,should install cmake or xmake
Use cmake or xmake(Recommend,most easy) to compile project,should install cmake or xmake

Network is required.Because this project uses xrepo to download packages.

Expand Down Expand Up @@ -45,3 +46,13 @@ xmake install
xmake unittest
xmake run unittest
```

if you use cmake,you should first download [googletest](https://github.com/google/googletest)(because cmake don't have a package manager),and place it in dir ```cmake_third_party```,then run:

```
cmake . -GNinja
ninja
./bin/unittest
```

to build and run unittest
4 changes: 3 additions & 1 deletion doc/developer/system/Compiler/BNF.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
item -> expr | func_call | value
left_value -> id | func_call
sentence -> id = item
sentence -> id := item
func_call -> id(argv)
argv -> argv,value | value

expr -> expr + term | expr - term | term
term -> term * factor | term / factor | term ** factor | term % factor | factor
factor -> value | (expr)
factor -> item | (expr)

const_value -> string | int | float
value -> const_value | id
Expand All @@ -20,3 +21,4 @@ whilesentence -> while item {
sentnece -> ifsentence | whilesentence
sentence -> assert argv
sentence -> goto int
sentence -> func_call
3 changes: 0 additions & 3 deletions language/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,11 @@
target("Chinese")
set_kind("shared")
add_files("chinese.cpp", "./**.cppm")
add_defines("BUILD_language_DLL")

target("English")
set_kind("shared")
add_files("english.cpp", "./**.cppm")
add_defines("BUILD_language_DLL")

target("language")
set_kind("shared")
add_files("english.cpp", "./**.cppm")
add_defines("BUILD_language_DLL")
Loading

0 comments on commit 86e81be

Please sign in to comment.