当前位置:网站首页>Programming language exercises (I)
Programming language exercises (I)
2022-07-24 16:46:00 【SakamataZ】
Can be in here Download Books, notes and answers .
welcome star/fork To participate in My compiler project
1.1
With C++ Language as an example :
a. Lexical errors
int a=$; //$ Report errors
b. Grammar mistakes
int c = .+ a; //. Wrong number
c. Static semantic error
int a=1;
int c=a+b;//b No definition
d. Dynamic semantic error
Access rights error , You may not report an error , But actually C++:“ Generate some code , Perform appropriate checks at runtime … The implementation of some rules may bring high 、 An unacceptable price , The implementation of language may not check them at all ”, in other words , This procedure " It's simply the wrong program "
The compiler is just as far as possible , Some dynamic semantic errors are detected , Static semantic errors can be detected . How much can be detected , It depends on the implementation of the language .
class Object
{
public:
int a;
};
int main() {
Object *b = (Object*)new Object;
delete(b);
cout << (*b).a;
}
e. Errors that violate language definitions
such , Instead of calling destructors, just free memory , The result will be an error that violates the language definition without the compiler running and reporting an error .
class Object
{
public:
int a;
};
int main() {
Object *b = (Object*)new Object;
free(b);
cout << (*b).a;
}
1.2
Compiled and interpreted languages have their own advantages . Interpretive languages have better performance , Compiled languages can bring more flexibility , And it can make a better diagnosis of the program .
1.3

1.4
Pascal division algorithm 
The time complexity is more reduced and higher .
1.5
make Dependency management will lead to some unnecessary compilation
such as :
Modification of local variables ; Local symbol table changes but does not affect other documents ; Character changes but no word changes, etc
1.6
lint Check C Potential errors in the program , Include ( But not limited to, ) Suspicious type combinations 、 Unused variables 、 Unreachable code and non portable code .lint It will produce a series of diagnostic information that programmers need to read carefully from beginning to end . Use lint Are the benefits of :1. It can check for errors that have been missed by the compiler ; 2. You can associate many files for error checking and code analysis , It has strong flexibility
1.8
I hope c++ Of static Assignment can be more convenient
But because c++ Of static Shared by all objects , Can only assign values outside the class
If you assign a value in the class , It is equivalent to changing this value every time you create a new object , It will definitely increase the complexity
1.9
Report errors
No,
If the semantic check of array out of bounds is added , Will increase O(n) Time complexity of .
1.11
Because we have to judge grammar , semantics , Whether it is right , Also check the boundary and access rights .
What can be found is abnormal errors , Cross the border, for example , Null pointer , overflow ; And logical errors cannot be found .
边栏推荐
- Concept of IP, classification of IP, IP multiplexing technology
- 【技术】uniapp之聊天室 demo
- 剑指 Offer 25. 合并两个排序的链表
- QT QML virtual keyboard
- 1163: 松哥的分数拆分(C语言)
- 1163: SongGe's score splitting (C language)
- QT keyboard event (II) -- long press the key to trigger the event event repeatedly, and the problem is solved
- Simple QQ? QT can also be achieved! (I)
- js,for循环内callback异步转换成同步执行
- 文件浏览器?Qt也可以实现!
猜你喜欢
随机推荐
Explain Apache Hudi schema evolution in detail
JS, call in the for loop is asynchronously converted to synchronous execution
【技术】uniapp 之 在线选座 demo
The industrial information security center takes the lead in building a data circulation platform, and ant group and other manufacturers provide technical support
Development dynamics | stonedb 2022 release milestone
简易版QQ?Qt也可以实现!(一)
会议OA项目进度(二)
工信安全中心牵头搭建数据流通平台 蚂蚁集团等厂商提供技术支持
How vscode mouse wheel enlarges the interface
.NET 测试框架 xUnit,MSTest, Specflow 使用经验汇总
Custom types: Enumeration
小端格式和大端格式(Little-Endian&Big-Endian)
JS simulation realizes the principles of call, apply, bind and new
How to realize seamless rotation map? Write it again with native JS
C font usage effect
ArcGIS layer annotation display
804. Unique Morse code word
QT embed Notepad under win10
剑指 Offer 22. 链表中倒数第k个节点
15、ARM嵌入式系统:如何用PC调试单板








