Skip to content
Snippets Groups Projects
Commit 901bc79d authored by Eric Li's avatar Eric Li
Browse files

initail commit

parents
No related branches found
No related tags found
No related merge requests found
Pipeline #72415 passed
# This file is used to ignore files which are generated
# ----------------------------------------------------------------------------
build/
*~
*.autosave
*.a
*.core
*.moc
*.o
*.obj
*.orig
*.rej
*.so
*.so.*
*_pch.h.cpp
*_resource.rc
*.qm
.#*
*.*#
core
!core/
tags
.DS_Store
.directory
*.debug
Makefile*
*.prl
*.app
moc_*.cpp
ui_*.h
qrc_*.cpp
Thumbs.db
*.res
*.rc
/.qmake.cache
/.qmake.stash
# qtcreator generated files
*.pro.user*
# xemacs temporary files
*.flc
# Vim temporary files
.*.swp
# Visual Studio generated files
*.ib_pdb_index
*.idb
*.ilk
*.pdb
*.sln
*.suo
*.vcproj
*vcproj.*.*.user
*.ncb
*.sdf
*.opensdf
*.vcxproj
*vcxproj.*
# MinGW generated files
*.Debug
*.Release
# Python byte code
*.pyc
# Binaries
# --------
*.dll
*.exe
# .gitlab-ci.yml
stages:
- build_release
- upload
- release
before_script:
# - set PATH=%QT_PATH%\bin;%PATH% # 将Qt安装目录添加到PATH环境变量
- cmake --version # 打印Qt版本信息,可以根据需要进行调整
variables:
PACKAGE_VERSION: "$CI_COMMIT_TAG"
FILE_NAME: "Project.exe"
PACKAGE_REGISTRY_URL: "${CI_API_V4_URL}/projects/${CI_PROJECT_ID}/packages/generic/autorelease/${PACKAGE_VERSION}"
build:
tags:
- cmake_pwsh
stage: build_release
rules:
- if: '$CI_COMMIT_TAG'
script:
- echo "Running release_build"
- $releaseDirectory = "./build_release"
- if (!(Test-Path -Path $releaseDirectory)) {New-Item -ItemType Directory -Path $releaseDirectory}
- Remove-Item -Path "./build_release/*" -Recurse -Force
- cd $releaseDirectory
- cmake -G "Ninja" -DCMAKE_BUILD_TYPE=Release -S .. -B .
- ninja
- cd ..
artifacts:
paths:
- build_release/
upload:
stage: upload
tags:
- cmake_pwsh
rules:
- if: '$CI_COMMIT_TAG'
script:
- |
Invoke-WebRequest -Uri "${PACKAGE_REGISTRY_URL}/${FILE_NAME}" -Headers @{ "JOB-TOKEN" = "${CI_JOB_TOKEN}" } -InFile "build_release/Project.exe" -Method PUT
release:
stage: release
tags:
- release_pwsh
rules:
- if: '$CI_COMMIT_TAG'
script:
- $Url_ = "${PACKAGE_REGISTRY_URL}/${FILE_NAME}"
- echo $Url_
- $env:asset = "{`"name`":`"Project`",`"url`":`"$Url_`",`"type`":`"package`"}"
- $env:assetjson = $env:asset | ConvertTo-Json
- release-cli create --name $CI_COMMIT_TAG --description "Release $CI_COMMIT_TAG" --ref $CI_COMMIT_TAG --tag-name $CI_COMMIT_TAG --assets-link=$env:assetjson
\ No newline at end of file
cmake_minimum_required(VERSION 3.5)
project(Project LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOUIC ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
# QtCreator supports the following variables for Android, which are identical to qmake Android variables.
# Check http://doc.qt.io/qt-5/deployment-android.html for more information.
# They need to be set before the find_package(Qt5 ...) call.
#if(ANDROID)
# set(ANDROID_PACKAGE_SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/android")
# if (ANDROID_ABI STREQUAL "armeabi-v7a")
# set(ANDROID_EXTRA_LIBS
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libcrypto.so
# ${CMAKE_CURRENT_SOURCE_DIR}/path/to/libssl.so)
# endif()
#endif()
find_package(Qt5 COMPONENTS Widgets REQUIRED)
if(ANDROID)
add_library(Project SHARED
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
SaveAction.cpp
SaveAction.h
analysis.cpp
analysis.h
)
else()
add_executable(Project
main.cpp
mainwindow.cpp
mainwindow.h
mainwindow.ui
View.h
View.cpp
Lexer.h
Lexer.cpp
linenumberarea.h
linenumberarea.cpp
texteditor.h
texteditor.cpp
Exceptions.h
expression.cpp
expression.h
analizer.cpp
analizer.h
statement.cpp
statement.h
datawindow.cpp
datawindow.h
command.h
command.cpp
modifyvaluecommand.h
modifyvaluecommand.cpp
)
endif()
target_link_libraries(Project PRIVATE Qt5::Widgets)
This diff is collapsed.
# Change log
## 6/25 20:20
目前已经实现的功能:
- 主窗口实现编辑、当前行高亮、显示行号、将内容保存到指定目录下
- 完成Token分析,可以对固定路径的文章进行Token分析,并存入一个vector中
- 实现了debug模式和Editor模式的切换,在debug模式中显示对应的两个窗口,并在Editor模式中隐藏
- 实现了依照“~[”对特定行进行高亮,并呈现在主窗口
还需要实现的功能:
- 后端基于表达式的递归处理还没有完成
- 想办法把输入文件拆分成行传递给表达式处理部分
- 想办法保存变量的值
## 6/25 20:32
已经完成:
- 可以对指定路径的文档进行Token分析
## 6/26
### TODO
- 尝试使用流水线模式处理输入的Token,分为一下几步:
```mermaid
graph TB
A(开始)
B[Tokenize]
C[使用divider按照每一行处理为一个vector<token>]
D[递归调用函数处理每一行返回的vector<token>]
E{是否存在错误}
F[抛出异常该行前面加入标识符]
G[原样不变]
H[结果返回输出函数逐行处理输出并写入一个string中]
I[将string写入文件]
A-->B-->C-->D-->E
E-->|是|F
E-->|否|G
F-->H
G-->H
H-->I
```
- 细分步骤:
- [x] Tokenizer
- [x] divider
- [ ] analyzer
- [ ] bugCatcher
- [ ] fileOutput
- 重新梳理一下文件系统,在E:\下建立文件夹TmpFiles,其中包含:
- MainWindowInput.txt:含义是从主窗口中获取的用户输入的内容,每次写入前清空
- MainWindowOutput.txt:含义是调用方法analyzeText处理结束后需要呈现在屏幕上的内容,其中包含Error字段标识符~[
- DebugWindowInput.txt:含义是从debugInputWindow窗口获取的内容,每次写入前清空
- DebugWindowOutput.txt:该文件由后端生成,写入前不清空,首次开始程序时清空,含义是呈现在debugOutputWindow上的内容
- TargetText.txt:该文件由Debug模式下高亮行及以前的内容和DebugWindowInput.txt中的内容拼接而成,该文件生成后调用analyzeText方法分析运算,运行结果以追加模式写入DebugWindowOutput.txt并呈现在窗口上
- Variables.txt:该文件为TargetText.txt运行后各个变量的值
### 10:57
#### 已完成
- 完成divider并测试通过
- 修改了一下Debug模式下重新进入高亮不消失的问题
#### Bug Log
- Debug模式下重新进入高亮行不会回退至第一行,已尝试在setup的时候重新初始化该变量,用处不大
### 16:10
#### TODO
- 重新构建项目结构:
```mermaid
graph TB
A[Analizer]
B[Statement]
C[Expression]
D[Lexer]
A-->B-->C-->D
```
从上到下依次包含
### 21:51
#### 已完成
- 递归分析语法
- 红色高亮错误语句
#### Bug log
- Debug模式下重新进入高亮行不会回退至第一行,已尝试在setup的时候重新初始化该变量,用处不大
- 分析语法时有概率错误退出
#### TODO
- 语法分析结束运行结果输出到Debug界面
- Debug模式下将需要执行的语句写入对应文件
- 修改一下交互,定义一个默认的全局路径,save和analyze的时候直接保存到默认路径,重新写一个change path的QAction用于修改路径
## 6/29
### Bug log
- 在Editor模式与Debug模式重复切换时,高亮行不会回退至第一行的错误似乎不是因为错误的初始化导致的,在使用输出调试后发现,第二次进入Debug模式时,每点击一次next,槽函数会被触发两次,查询ChatGPT之后,怀疑为以下原因:
- 信号和槽被重复连接:确保信号和槽的连接代码只执行一次。如果在每次程序运行的过程中都多次执行了连接代码,那么每次连接都会触发相应的槽函数。
- 信号和槽被多次连接到同一个对象:如果你将同一个信号连接到同一个槽函数多次,那么每次信号触发时,槽函数都会被调用相应的次数。
- 信号发射的频率超过了程序处理的能力:如果一个信号被频繁的发射并且槽函数执行时间较长,可能导致槽函数被调用的次数超过你预期的次数。
- 程序中存在多个对象之间的循环信号连接:如果对象 A 的信号连接到了对象 B 的槽函数,同时对象 B 的信号又连接到了对象 A 的槽函数,会导致一个无限的循环调用,最终可能导致槽函数被多次调用。
其中第三个原因不太可能,怀疑为第一个原因
- 现在在Editor模式下也可以点击next,需要修改
- 文档合并似乎并没有合并
### Solution
虽然最后也没有发现到底问题出在哪里,不过通过一个全局变量保证只连接一次
### Done
- 对于整个文件的运行
- 查错显示错误
- Debug模式下逐行运行
### TODO
- 修改一下交互模式,在有错误的情况下不能进入run模式和Debug模式
- 写一个窗口展示变量值
#ifndef EXCEPTIONS_H
#define EXCEPTIONS_H
#include <exception>
class MyException : public std::exception {
public:
static const int UNEXPECTED_CHAR_TYPE = 0x1;
static const int ERROR_STREAM_STATUS = 0x2;
static const int ERROR_TOKEN_IN_LINE = 0x4;
static const int ERROR_FOR_UNKNOWN_OPERATOR = 0x8;
static const int ERROR_UNKNOWN_TOKEN_TYPE = 0xf;
static const int ERROR_UNKNOWN_LEVEL_4_EXPRESSION = 0x10;
static const int ERROR_MISSING_RIGHT_BRANKET = 0x20;
static const int ERROR_GRAMMAR_IN_LINE = 0x40;
static const int ERROR_UNKNOWN_STATEMENT_TYPE = 0x80;
MyException(const char *message, int errorCode)
: m_message(message), m_errorCode(errorCode) {}
const char *what() const noexcept override { return m_message; }
int getErrorCode() const { return m_errorCode; }
private:
const char *m_message;
int m_errorCode;
};
#endif // EXCEPTIONS_H
HEAD 0 → 100644
ref: refs/heads/main
LICENSE 0 → 100644
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright 2023 Eric Li
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
#include "Lexer.h"
#include "Exceptions.h"
#include <bits/stdc++.h>
using namespace std;
// Lexer Begin
Lexer::Lexer(const vector<Token> &tokens)
: tokens(tokens), pos(0), len(tokens.size()) {
for (auto i : tokens) {
if (i.type == TypeForToken::Error)
throw(MyException("Error in line", MyException::ERROR_TOKEN_IN_LINE));
}
}
void Lexer::GetNextToken() {
if (pos < len)
pos++;
}
Token Lexer::GetCurToken() const { return tokens[pos]; }
void Lexer::Output() const {
for (auto i : tokens) {
i.Output();
}
}
// Lexer End
Lexer.h 0 → 100644
#ifndef LEXER_H
#define LEXER_H
#include "Exceptions.h"
#include <QDebug>
#include <QHash>
#include <QString>
#include <vector>
using namespace std;
enum class TypeForToken {
Integer,
Identifier,
SingleOperator,
DoubleOperator,
EndofLine,
Error,
ErrorSignal
};
enum class TypeForStream { Integer, Identifier, Empty, EndOfFile, Error };
enum class TypeForChar { Number, Letter, Operator, Blank, Error, Eof, Eol };
struct Token {
TypeForToken type;
int value;
QString name;
void Output() {
if (type == TypeForToken::Error) {
qDebug() << "This is an error token";
return;
} else if (type == TypeForToken::EndofLine) {
qDebug() << "This is the end of line";
return;
}
qDebug() << "Type = " << (int)type << " Value = " << value
<< " Name = " << name;
}
QString toString() {
if (type == TypeForToken::ErrorSignal) {
return "~[";
} else if (type == TypeForToken::Integer) {
return QString::number(value);
} else if (type == TypeForToken::DoubleOperator) {
return name;
} else if (type == TypeForToken::SingleOperator) {
return "output";
} else if (type == TypeForToken::DoubleOperator) {
return name;
} else if (type == TypeForToken::Error) {
return name;
} else if (type == TypeForToken::EndofLine) {
return "";
} else if (type == TypeForToken::Identifier) {
return name;
} else
throw(MyException("Unknown Token Type",
MyException::ERROR_UNKNOWN_TOKEN_TYPE));
};
};
// vector<Token> tokens;
class Lexer {
private:
vector<Token> tokens;
int pos;
int len;
public:
Lexer(const vector<Token> &tokens);
void GetNextToken();
Token GetCurToken() const;
void Output() const;
};
#endif // LEXER_H
# FinalProject
## Getting started
To make it easy for you to get started with GitLab, here's a list of recommended next steps.
Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
## Add your files
- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
```
cd existing_repo
git remote add origin https://git.nju.edu.cn/EricLi/finalproject.git
git branch -M main
git push -uf origin main
```
## Integrate with your tools
- [ ] [Set up project integrations](https://git.nju.edu.cn/EricLi/finalproject/-/settings/integrations)
## Collaborate with your team
- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
- [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
## Test and Deploy
Use the built-in continuous integration in GitLab.
- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
***
# Editing this README
When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
## Suggestions for a good README
Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
## Name
Choose a self-explaining name for your project.
## Description
Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
## Badges
On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
## Visuals
Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
## Installation
Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
## Usage
Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
## Support
Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
## Roadmap
If you have ideas for releases in the future, it is a good idea to list them in the README.
## Contributing
State if you are open to contributions and what your requirements are for accepting them.
For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
## Authors and acknowledgment
Show your appreciation to those who have contributed to the project.
## License
For open source projects, say how it is licensed.
## Project status
If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
#include <QString>
#include <QDebug>
#include <QApplication>
#include <QFile>
#include <QTextEdit>
#include <QTextStream>
#include <QTextCursor>
#include <QTextCharFormat>
#include <QTextBlock>
extern QString strOfMainEditor;
extern QString strOfDebugEditor;
extern QString strOfOutputEditor;
void SaveMainEditor(QString str) {
QFile file("E:\\input.txt");
if (file.open(QIODevice::WriteOnly | QIODevice::Text))
{
QTextStream stream(&file);
stream << str;
file.close();
qDebug() << "save success";
} else {
qDebug() << "fail to open file";
}
};
bool ShowErrorInMainEditor(QTextEdit *textEdit){
QFile file("E:\\input.txt");
textEdit->clear();
if (file.open(QIODevice::ReadOnly | QIODevice::Text))
{
QTextStream stream(&file);
QString line;
while (stream.readLineInto(&line))
{
// 判断行首是否有 error 字段
if (line.startsWith("error"))
{
// 去掉行首的 error 并改变文本颜色为红色
line.remove(0, 5);
QTextCharFormat charFormat;
charFormat.setFontPointSize(22);
charFormat.setForeground(QBrush(Qt::red));
QTextBlock block = textEdit->document()->findBlockByLineNumber(textEdit->document()->blockCount() - 1);
QTextCursor cursor(block);
cursor.movePosition(QTextCursor::End);
cursor.insertText(line, charFormat);
}
else
{
// 改变文本颜色为黑色
QTextCharFormat charFormat;
charFormat.setFontPointSize(22);
charFormat.setForeground(QBrush(Qt::black));
QTextBlock block = textEdit->document()->findBlockByLineNumber(textEdit->document()->blockCount() - 1);
QTextCursor cursor(block);
cursor.movePosition(QTextCursor::End);
cursor.insertText(line, charFormat);
}
// 换行
textEdit->append("");
}
file.close();
}
// 显示 QTextEdit 组件
textEdit->show();
return true;
}
#include <QString>
#include <QDebug>
#include <QApplication>
#include <QFile>
#include <QTextEdit>
#include <QTextStream>
#include <QTextCursor>
#include <QTextCharFormat>
#include <QTextBlock>
extern QString strOfMainEditor;
extern QString strOfDebugEditor;
extern QString strOfOutputEditor;
bool ShowErrorInMainEditor(QTextEdit *textEdit);
void SaveMainEditor(QString strOfMainEditor);
View.cpp 0 → 100644
#include <QApplication>
#include <QDebug>
#include <QFile>
#include <QString>
#include <QTextBlock>
#include <QTextCharFormat>
#include <QTextCursor>
#include <QTextEdit>
#include <QTextStream>
extern QString strOfMainEditor;
extern QString strOfDebugEditor;
extern QString strOfOutputEditor;
void SaveMainEditor(QString str) {
QFile file("E:\\input.txt");
if (file.open(QIODevice::WriteOnly | QIODevice::Text)) {
QTextStream stream(&file);
stream << str;
file.close();
qDebug() << "save success";
} else {
qDebug() << "fail to open file";
}
};
bool ShowErrorInMainEditor(QTextEdit *textEdit) {
QFile file("E:\\input.txt");
textEdit->clear();
if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
QTextStream stream(&file);
QString line;
while (stream.readLineInto(&line)) {
// 判断行首是否有 error 字段
if (line.startsWith("error")) {
// 去掉行首的 error 并改变文本颜色为红色
line.remove(0, 5);
QTextCharFormat charFormat;
charFormat.setFontPointSize(22);
charFormat.setForeground(QBrush(Qt::red));
QTextBlock block = textEdit->document()->findBlockByLineNumber(
textEdit->document()->blockCount() - 1);
QTextCursor cursor(block);
cursor.movePosition(QTextCursor::End);
cursor.insertText(line, charFormat);
} else {
// 改变文本颜色为黑色
QTextCharFormat charFormat;
charFormat.setFontPointSize(22);
charFormat.setForeground(QBrush(Qt::black));
QTextBlock block = textEdit->document()->findBlockByLineNumber(
textEdit->document()->blockCount() - 1);
QTextCursor cursor(block);
cursor.movePosition(QTextCursor::End);
cursor.insertText(line, charFormat);
}
// 换行
textEdit->append("");
}
file.close();
}
// 显示 QTextEdit 组件
textEdit->show();
return true;
}
View.h 0 → 100644
#include <QString>
#include <QDebug>
#include <QApplication>
#include <QFile>
#include <QTextEdit>
#include <QTextStream>
#include <QTextCursor>
#include <QTextCharFormat>
#include <QTextBlock>
extern QString strOfMainEditor;
extern QString strOfDebugEditor;
extern QString strOfOutputEditor;
bool ShowErrorInMainEditor(QTextEdit *textEdit);
void SaveMainEditor(QString strOfMainEditor);
#include "analizer.h"
#include "Exceptions.h"
#include <fstream>
extern map<QString, int> GlobalMap;
Token ErrorSignal;
vector<Token> EmptyVector;
TypeForChar getTypeForChar(char ch) {
TypeForChar ans;
if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z')) {
ans = TypeForChar::Letter;
} else if (ch >= '0' && ch <= '9') {
ans = TypeForChar::Number;
} else if (ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '=' ||
ch == '(' || ch == ')') {
ans = TypeForChar::Operator;
} else if (ch == '\t' || ch == ' ') {
ans = TypeForChar::Blank;
} else if (ch == EOF) {
ans = TypeForChar::Eof;
} else if (ch == '\n' || ch == '\r') {
ans = TypeForChar::Eol;
} else
ans = TypeForChar::Error;
return ans;
}
void analyzeText(const char *filePath) {
ErrorSignal.type = TypeForToken::ErrorSignal;
vector<vector<Token>> t;
try {
t = divider(getToken(filePath));
} catch (MyException exp) {
qDebug() << "In line " << __LINE__ << "Get Exception" << exp.what() << endl
<< "Error Code 0x" << exp.getErrorCode();
}
writeToFile(vecToString(solve(t)));
}
vector<Token> getToken(const char *filePath) {
freopen(filePath, "r", stdin);
vector<Token> tokens;
char ch;
TypeForStream typeForStream = TypeForStream::Empty;
TypeForChar typeForChar = TypeForChar::Blank;
Token ans;
do {
ch = getchar();
typeForChar = getTypeForChar(ch);
switch (typeForStream) {
case TypeForStream::Empty:
switch (typeForChar) {
case TypeForChar::Blank:
break;
case TypeForChar::Eol:
ans.type = TypeForToken::EndofLine;
tokens.push_back(ans);
ans.name.clear();
ans.value = 0;
break;
case TypeForChar::Letter:
typeForStream = TypeForStream::Identifier;
ans.type = TypeForToken::Identifier;
ans.name.clear();
ans.value = 0;
ans.name += ch;
break;
case TypeForChar::Number:
typeForStream = TypeForStream::Integer;
ans.type = TypeForToken::Integer;
ans.name.clear();
ans.value = ch - '0';
break;
case TypeForChar::Operator:
ans.type = TypeForToken::DoubleOperator;
ans.name = ch;
tokens.push_back(ans);
ans.name.clear();
ans.value = 0;
break;
case TypeForChar::Error:
typeForStream = TypeForStream::Error;
ans.type = TypeForToken::Error;
ans.name = ch;
break;
case TypeForChar::Eof:
ans.type = TypeForToken::EndofLine;
tokens.push_back(ans);
break;
default:
throw MyException("Unexcepted Type for Char",
MyException::UNEXPECTED_CHAR_TYPE);
}
break;
case TypeForStream::Integer:
switch (typeForChar) {
case TypeForChar::Number:
ans.value = ans.value * 10 + ch - '0';
break;
case TypeForChar::Letter:
ans.type = TypeForToken::Error;
ans.name = QString::number(ans.value);
ans.name += ch;
typeForStream = TypeForStream::Error;
break;
case TypeForChar::Blank:
tokens.push_back(ans);
ans.value = 0;
ans.name.clear();
typeForStream = TypeForStream::Empty;
break;
case TypeForChar::Operator:
tokens.push_back(ans);
ans.type = TypeForToken::DoubleOperator;
ans.name = ch;
ans.value = 0;
tokens.push_back(ans);
ans.name.clear();
typeForStream = TypeForStream::Empty;
break;
case TypeForChar::Eof:
tokens.push_back(ans);
ans.type = TypeForToken::EndofLine;
ans.name = ch;
ans.value = 0;
tokens.push_back(ans);
ans.name.clear();
typeForStream = TypeForStream::EndOfFile;
break;
case TypeForChar::Eol:
tokens.push_back(ans);
ans.type = TypeForToken::EndofLine;
ans.name = ch;
ans.value = 0;
tokens.push_back(ans);
ans.name.clear();
typeForStream = TypeForStream::Empty;
break;
case TypeForChar::Error:
ans.type = TypeForToken::Error;
ans.name = QString::number(ans.value);
ans.name += ch;
ans.value = 0;
typeForStream = TypeForStream::Error;
default:
throw MyException("Unexcepted Type for Char",
MyException::UNEXPECTED_CHAR_TYPE);
}
break;
case TypeForStream::Identifier:
switch (typeForChar) {
case TypeForChar::Letter:
ans.name += ch;
break;
case TypeForChar::Number:
ans.name += ch;
break;
case TypeForChar::Blank:
if (ans.name == "output") {
ans.type = TypeForToken::SingleOperator;
tokens.push_back(ans);
ans.name.clear();
ans.value = 0;
typeForStream = TypeForStream::Empty;
break;
}
tokens.push_back(ans);
ans.name.clear();
ans.value = 0;
typeForStream = TypeForStream::Empty;
break;
case TypeForChar::Eol:
if (ans.name == "output") {
ans.type = TypeForToken::SingleOperator;
tokens.push_back(ans);
ans.type = TypeForToken::EndofLine;
ans.name.clear();
ans.value = 0;
tokens.push_back(ans);
typeForStream = TypeForStream::Empty;
break;
}
tokens.push_back(ans);
ans.type = TypeForToken::EndofLine;
ans.name.clear();
ans.value = 0;
tokens.push_back(ans);
typeForStream = TypeForStream::Empty;
break;
case TypeForChar::Eof:
if (ans.name == "output") {
ans.type = TypeForToken::SingleOperator;
tokens.push_back(ans);
ans.type = TypeForToken::EndofLine;
ans.name.clear();
ans.value = 0;
tokens.push_back(ans);
typeForStream = TypeForStream::EndOfFile;
break;
}
tokens.push_back(ans);
ans.type = TypeForToken::EndofLine;
ans.name.clear();
ans.value = 0;
tokens.push_back(ans);
typeForStream = TypeForStream::EndOfFile;
break;
case TypeForChar::Operator:
if (ans.name == "output") {
ans.type = TypeForToken::SingleOperator;
tokens.push_back(ans);
ans.type = TypeForToken::DoubleOperator;
ans.name.clear();
ans.name = ch;
ans.value = 0;
tokens.push_back(ans);
typeForStream = TypeForStream::Empty;
break;
}
tokens.push_back(ans);
ans.type = TypeForToken::DoubleOperator;
ans.name.clear();
ans.name = ch;
ans.value = 0;
tokens.push_back(ans);
typeForStream = TypeForStream::Empty;
break;
case TypeForChar::Error:
ans.type = TypeForToken::Error;
ans.name += ch;
typeForStream = TypeForStream::Error;
break;
default:
throw MyException("Unexcepted Type for Char",
MyException::UNEXPECTED_CHAR_TYPE);
}
break;
case TypeForStream::EndOfFile:
break;
case TypeForStream::Error:
switch (typeForChar) {
case TypeForChar::Letter:
ans.name += ch;
break;
case TypeForChar::Number:
ans.name += ch;
break;
case TypeForChar::Operator:
tokens.push_back(ans);
ans.name.clear();
ans.value = 0;
ans.type = TypeForToken::DoubleOperator;
ans.name = ch;
tokens.push_back(ans);
ans.name.clear();
typeForStream = TypeForStream::Empty;
break;
case TypeForChar::Blank:
tokens.push_back(ans);
ans.name.clear();
ans.value = 0;
typeForStream = TypeForStream::Empty;
break;
case TypeForChar::Error:
ans.name += ch;
break;
case TypeForChar::Eof:
tokens.push_back(ans);
ans.name.clear();
ans.value = 0;
ans.type = TypeForToken::EndofLine;
tokens.push_back(ans);
typeForStream = TypeForStream::EndOfFile;
break;
case TypeForChar::Eol:
tokens.push_back(ans);
ans.name.clear();
ans.value = 0;
ans.type = TypeForToken::EndofLine;
tokens.push_back(ans);
typeForStream = TypeForStream::Empty;
break;
}
break;
default:
throw MyException("Error Stream Status",
MyException::ERROR_STREAM_STATUS);
}
} while (ch != EOF);
for (auto &i : tokens) {
i.Output();
}
return tokens;
}
vector<vector<Token>> divider(const vector<Token> &input) {
vector<vector<Token>> ans;
vector<Token> thisline;
thisline.clear();
ans.clear();
for (auto &t : input) {
if (t.type != TypeForToken::EndofLine) {
thisline.push_back(t);
} else {
thisline.push_back(t); //上次就是这里没有写,一直程序异常退出!!!!!
ans.push_back(thisline);
thisline.clear();
}
}
//输出调试测试
int cnt = 0;
for (auto &i : ans) {
qDebug() << "In line " << cnt << "tokens are:";
for (auto &j : i) {
j.Output();
}
}
return ans;
}
vector<vector<Token>> solve(const vector<vector<Token>> &src) {
vector<vector<Token>> ans;
int cnt = 0;
for (auto &line_origin : src) {
qDebug() << "Line " << cnt++ << "Start";
auto line = line_origin;
bool initialized = true;
Lexer lexer(EmptyVector);
try {
lexer = Lexer(line);
qDebug() << "Lexer initialized";
initialized = true;
} catch (MyException exp) {
if ((exp.getErrorCode() & MyException::ERROR_TOKEN_IN_LINE) != 0) {
line.insert(line.begin(), ErrorSignal);
qDebug() << "Lexer failed to initialize";
}
initialized = false;
}
if (initialized) {
try {
lexer.Output();
Token tk = lexer.GetCurToken();
// qDebug() << "The first token is";
// tk.Output();
if (tk.type != TypeForToken::EndofLine) {
// if(tk.type==TypeForToken::Error) return 0;
if (tk.name != "output" || tk.type != TypeForToken::SingleOperator) {
lexer.GetNextToken();
Token tk2 = lexer.GetCurToken();
qDebug() << "The second token is";
tk2.Output();
if (tk2.name == "=") {
// qDebug() << "Now the third token is";
// lexer.GetCurToken().Output();
Assignment(tk.name.toStdString()).execute(lexer);
} else if(tk2.type == TypeForToken::EndofLine) {
GlobalMap[tk.name] = 0;
} else {
qDebug() << "error for unknown statement in 359" << endl;
throw(MyException("error for unknown statement",
MyException::ERROR_UNKNOWN_STATEMENT_TYPE |
MyException::ERROR_GRAMMAR_IN_LINE));
}
} else {
Output().execute(lexer);
}
}
qDebug() << "This line is empty";
} catch (MyException exp) {
qDebug() << "The error is " << exp.what() << " Error code "
<< exp.getErrorCode() << endl;
if (exp.getErrorCode() & MyException::ERROR_GRAMMAR_IN_LINE) {
line.insert(line.begin(), ErrorSignal);
} else
throw std::move(exp);
}
}
ans.push_back(line);
qDebug() << "Line " << cnt++ << "Done";
// qDebug() << "variables are";
// for(auto i : GlobalMap) {
// qDebug() << i.first << "=" << i.second;
// }
}
//输出场上所有变量
qDebug() << "All lines are solved";
qDebug() << "variables are";
for (auto &i : GlobalMap) {
qDebug() << i.first << "=" << i.second;
}
return ans;
}
string vecToString(const vector<vector<Token>> &src) {
string ans;
for (auto &line : src) {
for (auto token : line) {
ans += token.toString().toStdString();
ans += " ";
}
ans += '\n';
}
return ans;
}
void writeToFile(const string &src) {
std::ofstream fout("E:\\TmpFiles\\MainWindowOutput.txt");
fout << src;
fout.close();
qDebug() << "Input to file succeed";
outputAllVaribles();
}
void outputAllVaribles() {
for (auto &item : GlobalMap) {
qDebug() << item.first << "=" << item.second << endl;
}
}
#ifndef ANALIZER_H
#define ANALIZER_H
#include "statement.h"
TypeForChar getTypeForChar(char);
void analyzeText(const char *);
vector<Token> getToken(const char* FilePath);
vector<vector<Token>> divider(const vector<Token>&);
vector<vector<Token>> solve(const vector<vector<Token>>&);
string vecToString(const vector<vector<Token>>&);
void writeToFile(const string &);
void outputAllVaribles();
#endif // ANALIZER_H
#include "command.h"
Command::Command()
{
}
#ifndef COMMAND_H
#define COMMAND_H
class Command
{
public:
Command();
};
#endif // COMMAND_H
config 0 → 100644
[core]
repositoryformatversion = 0
filemode = false
bare = true
symlinks = false
ignorecase = true
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment