c语言手搓一个500+行的类c语言解释器(6)- 语义分析:符号表和变量、函数

用c语言手搓一个500+行的类c语言解释器: 给编程初学者的解释器教程(6)- 语义分析:符号表和变量、函数

项目github地址及源码:
https://github.com/yunwei37/tryC

这一部分,我们再回过头来看看变量、函数是怎样存储和处理的、以及符号表是怎样构建的。

符号表

我们先来回顾一下符号表的定义:

符号表是一种用于语言翻译器(例如编译器和解释器)中的数据结构。在符号表中,程序源代码中的每个标识符都和它的声明或使用信息绑定在一起,比如其数据类型、作用域以及内存地址。

简单来说就是,我们在符号表中存储对应的变量的各种信息,在定义的时候对符号表进行插入,以便下次碰见它的时候可以知道这个变量的具体信息。

我们可以在符号表中保存五种变量:Num(数值), Char(字符), Str(字符串), Array(数组), Func(函数)

tryC符号表的完整定义如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
/* this structure represent a symbol store in a symbol table */
typedef struct symStruct {
int type; // 符号的类型: Num, Char, Str, Array, Func
char name[MAXNAMESIZE]; // 符号名称
double value; // 如果是数值变量,记录它的值; 如果是数组或者字符串,记录它的长度
union {
char* funcp; // 指向函数定义在源代码中位置的字符指针
struct symStruct* list; // 指向数组列表
} pointer;
int levelNum; // 作用域层
} symbol;
symbol symtab[SYMTABSIZE]; // 用数组定义符号表
int symPointer = 0; // 符号表数组当前使用的最大下标的指针+1(栈顶 + 1)
int currentlevel = 0; // 当前作用域层

作用域

作用域就是程序中定义的变量所存在的区域,超过该区域变量就不能被访问。

(这里就不具体举例介绍了)

作用域可以相互嵌套;当内层作用域和外层作用域存在同名变量时,在内层的程序访问的应当是内层的变量,在外层的程序访问的应当是外层的变量;在函数中的变量,只有在所在函数被调用时才动态地为变量分配存储单元,并在调用结束时回收。

作用域可以是块作用域、函数作用域等,tryC中只实现了函数作用域。

我们可以用currentlevel这个变量记录当前的嵌套深度;

1
int currentlevel = 0; 

对于函数作用域我们可以这样处理:在函数调用时加深作用域层,并把需要传入的参数插入符号表;并在函数退出的时候,删除该作用域层的所有变量,并减少作用域层,对应代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
double function() {
currentlevel++;
return_val = 0;

.....

while (symtab[symPointer - 1].levelNum == currentlevel) {
symPointer--;
}
currentlevel--;
return return_val;
}

由于插入的变量肯定在符号表数组的最上面,因此只要减少符号表数组最大值的指针就可以表示删除啦。

变量

对变量的处理主要分为几个部分:

  • 词法分析阶段,当我们遇见一个标识符名称时,需要返回对应的token;
  • 在表达式中,当遇见一个变量时,我们需要获取它的值;
  • 在定义语句中,对变量进行定义和在符号表中插入相关信息;

词法分析阶段

当我们在词法分析的时候,对变量的处理需要以下几个步骤:

  1. 获取完整的变量名:
  2. 在符号表中查找变量,从上往下查找,这样返回的一定是最近作用域的那个变量:
  3. 如果在符号表中找到了变量,根据变量不同的类型,返回不同的token值;
  4. 如果没有找到,在符号表中间插入新的变量,返回的token值为void;这时应该对应赋值语句
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
...
else if ((token >= 'a' && token <= 'z') || (token >= 'A' && token <= 'Z') || (token == '_')) {
last_pos = src - 1; // process symbols
char nameBuffer[MAXNAMESIZE];
nameBuffer[0] = token;
while ((*src >= 'a' && *src <= 'z') || (*src >= 'A' && *src <= 'Z') || (*src >= '0' && *src <= '9') || (*src == '_')) {
nameBuffer[src - last_pos] = *src;
src++;
}
nameBuffer[src - last_pos] = 0; // get symbol name
int i;
for (i = symPointer-1; i >= 0; --i) { // search symbol in symbol table
if (strcmp(nameBuffer, symtab[i].name) == 0) { // if find symbol: return the token according to symbol type
if (symtab[i].type == Num || symtab[i].type == Char) {
token_val.ptr = &symtab[i];
token = Sym;
}
else if (symtab[i].type == FuncSym) {
token_val.ptr = &symtab[i];
token = symtab[i].type;
}
else if (symtab[i].type == ArraySym) {
token_val.ptr = &symtab[i];
token = symtab[i].type;
}
else {
if (symtab[i].type == Void) {
token = Sym;
token_val.ptr = &symtab[i];
}
else token = symtab[i].type;
}
return;
}
}
strcpy(symtab[symPointer].name, nameBuffer); // if symbol not found, create a new one
symtab[symPointer].levelNum = currentlevel;
symtab[symPointer].type = Void;
token_val.ptr = &symtab[symPointer];
symPointer++;
token = Sym;
return;
}
...

在表达式中对变量的处理:

在表达式中遇到的标识符可能是三种形式:

  1. 普通变量:Char或Num,token_val传递数值类型;
  2. 函数变量:进行调用函数操作;
  3. 数组变量:获取token_val传递的数组指针,获取下标,进行边界检查,获取元素;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
double factor() {
double temp = 0;
.....
else if (token == Sym) { // 普通变量
temp = token_val.ptr->value;
match(Sym);
}
else if (token == FuncSym) { // 函数变量
return function();
}
else if (token == ArraySym) { // 数组变量
symbol* ptr = token_val.ptr;
match(ArraySym);
match('[');
int index = (int)expression();
if (index >= 0 && index < ptr->value) {
temp = ptr->pointer.list[index].value;
}
match(']');
}
return temp;
}

在变量定义语句中对变量的处理

由于是动态类型语言,我们对变量的定义语句也是变量的赋值语句;根据赋值的类型确定变量的类型。进入赋值语句时,传递过来的token_val包含的是一个指向当前变量结构体的指针,赋值就是对其进行操作:

赋值语句的左边可以是数组中间的一个单元,也可以是一个变量,右边是字符串或表达式、字符。

数组需要先定义才能进行赋值。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
...
else if (token == Sym || token == ArraySym) {
symbol* s = token_val.ptr;
int tktype = token;
int index;
match(tktype);
if (tktype == ArraySym) { // 对数组进行特殊判断:获取要赋值的数组单元;
match('[');
index = expression();
match(']');
match('=');
if (index >= 0 && index < s->value) {
s->pointer.list[index].value = expression();
}
}
else {
match('=');
if (token == Str) { // 根据赋值类型进行不同的操作
s->pointer.funcp = (char*)token_val.ptr;
s->type = Str;
match(Str);
}
else if (token == Char) {
s->value = token_val.val;
s->type = Char;
match(Char);
}
else {
s->value = expression();
s->type = Num;
}
}
match(';');
}
...

函数

tryC的函数实现完整代码:这个函数做了以下几件事:

  1. 对变量的作用域进行控制;
  2. 将函数参数中的变量直接插入作用域;
  3. 保存当前词法分析的源代码位置和token,并跳转到函数定义时的源代码位置和token;
  4. 语法分析和执行定义时的函数体,如果碰到返回语句,就将返回值存入return_val;
  5. 恢复保存的当前源代码位置和token;
  6. 返回值从全局变量return_val中获取;

由于function()函数本身是递归的,且变量作用域等可以得到控制,因此可以实现函数的递归调用。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
double function() {
currentlevel++;
return_val = 0; // 对变量的作用域进行控制;

symbol* s = token_val.ptr; // 将函数参数中的变量直接插入作用域;
match(FuncSym);
match('(');
while (token != ')') {
symtab[symPointer] = *token_val.ptr;
strcpy(symtab[symPointer].name, token_val.ptr->name);
symtab[symPointer].levelNum = currentlevel;
symPointer++;
match(Sym);
if (token == ',')
match(',');
}
match(')');
char* startPos = src; // 保存当前词法分析的源代码位置和token
char* startOldPos = old_src;
int startToken = token;
old_src = src = s->pointer.funcp; // 跳转到函数定义时的源代码位置和token;
token = (int)s->value;
statement(); // 语法分析和执行定义时的函数体
src = startPos;
old_src = startOldPos;
token = startToken; // 恢复保存的当前源代码位置和token;

while (symtab[symPointer - 1].levelNum == currentlevel) {
symPointer--;
}
currentlevel--;
return return_val;
}

可对照源码查看(如果觉得写得还行麻烦您帮我点个star哦)
https://github.com/yunwei37/tryC

Where Does Innovation Thrive? Choosing the Right Organization

Welcome to the second post in my series on innovation! I’m not a highly successful person yet, but I’m passionate about understanding what drives innovation and how it can help me—and maybe you—make a difference.

When it comes to innovation, many people wonder where the best place to create something new is. Is it at a university, a big company, a startup, or maybe in an open community online? The truth is, there’s no one-size-fits-all answer. Each type of organization has its own strengths and challenges that can either help or hinder your innovative ideas.

Academia: The Hub of Fundamental Research

Universities and research institutions are fantastic places for deep, fundamental research. If you love diving into theories and expanding our understanding of the world, academia is where you can shine. These institutions provide the resources and environment to explore big questions without the immediate pressure of making money. Plus, you’ll be surrounded by other passionate thinkers and have access to a wealth of knowledge.

However, academia can sometimes be slow. The decision-making processes are often bureaucratic, which means it can take time to get your ideas off the ground. Also, funding is usually tied to grants and specific projects, which might limit how freely you can explore different avenues.

Industry: Powering Large-Scale Innovation

Big companies have the resources to turn ideas into real products and services. If you’re excited about taking research and developing it into something that people can use every day, working in industry might be the right fit for you. These organizations have the money and technology to support large projects and can bring your innovations to the market quickly.

On the flip side, big companies often prioritize profits and market share. This focus can sometimes stifle creativity, especially if your ideas don’t align with the company’s goals. There’s also a tendency to play it safe, which can make groundbreaking innovations harder to achieve.

Startups: The Engines of Disruptive Innovation

Startups are all about shaking things up. They’re small, agile, and ready to take risks. If you thrive in fast-paced environments and love the idea of disrupting existing markets with something new, a startup could be the perfect place for you. The flat hierarchies and flexible structures mean you can move quickly and see your ideas come to life faster.

But startups come with their own set of challenges. Resources are often limited, and the risk of failure is high. Without the financial backing of a large company, you might find it tough to scale your ideas or sustain your projects over the long term.

Open-Source Communities: Collaborative Innovation

Open-source communities are unique because they thrive on collaboration and transparency. If you believe in the power of working together and want to contribute to projects that benefit everyone, this might be your ideal environment. These communities harness the collective intelligence of contributors from all over the world, leading to continuous improvement and innovation.

The downside? Open-source projects rely heavily on volunteers, which can make them less stable and harder to manage. Decision-making often requires consensus, which can slow things down. Plus, without a formal structure, coordinating large projects can be challenging.

Finding the Right Fit for You

So, which organization is the best for innovation? The answer depends on several factors:

  • Nature of Your Project: Are you working on something theoretical, building a product, or trying to solve a social issue?
  • Resources Needed: Do you require significant funding and technology, or can you work with limited resources?
  • Desired Impact: Do you aim to make a big splash quickly, or are you focused on long-term, foundational changes?

Often, the most impactful innovations come from collaborations that combine the strengths of different organizations. For example, universities and companies working together can turn groundbreaking research into marketable products. Startups using open-source tools can innovate rapidly without starting from scratch. Big companies contributing to open-source projects can enhance community resources while benefiting from collective advancements.

Embracing Synergy for Greater Innovation

Imagine a university researcher partnering with a tech company. The researcher brings deep knowledge and theoretical insights, while the company provides the resources to develop and distribute a new technology. Or think of a startup that uses open-source software to build a unique product quickly and efficiently. These partnerships can create a powerful synergy that leverages the best of each world.

Conclusion: Choose What Fits Your Goals

There’s no single “best” place to innovate. The right environment for you depends on what you want to achieve, the resources you have, and how you like to work. Academia, industry, startups, and open-source communities each offer unique opportunities and face their own challenges.

As you think about where to pursue your innovative ideas, consider the nature of your projects, the resources you need, and the impact you want to make. You might even find that combining elements from different environments leads to the most exciting and effective innovations.

Stay tuned for the next post, where we’ll explore how you can take your innovation dreams into action and make a real difference in the world!

How can one person Making a Difference in innovation world

Welcome to the third post in my series on innovation! I’m not a highly successful person yet, but I’m passionate about understanding what drives innovation and how it can help me—and maybe you—make a difference.

Innovation isn’t just for big companies or famous inventors. Every one of us has the potential to create something that can change the world. Whether you’re dreaming of developing groundbreaking technology, launching a social initiative, or simply improving the way things are done, there are steps you can take to turn your ideas into reality. Let’s explore how you can become an innovator and make a meaningful impact.

Find the Right Environment for Your Ideas

Choosing where to focus your efforts is crucial. Different environments offer unique benefits depending on what you want to achieve. If you love diving deep into theoretical concepts and expanding knowledge, academia might be your place. Here, you can engage in fundamental research and collaborate with other passionate minds. On the other hand, if you’re driven by creating products that people use every day, working in industry could provide the resources and infrastructure you need to bring your ideas to life.

If you’re excited by the idea of building something from the ground up, startups offer a flexible and dynamic environment where you can experiment and iterate quickly. They’re perfect for those who thrive in fast-paced settings and aren’t afraid to take risks. Lastly, open-source communities are ideal if you value collaboration and want to contribute to projects that benefit everyone. These communities allow you to work with people from all over the world, sharing knowledge and building something together.

Focus on Making a Real Impact

When you aim to innovate, it’s important to prioritize making a meaningful difference over chasing fame or money alone. Think about the problems you’re passionate about solving. Whether it’s improving education, protecting the environment, or enhancing healthcare, focusing on issues that matter to you will keep you motivated and driven.

Addressing significant and timely problems ensures that your innovations are not only relevant but also widely adopted. When your work helps solve real challenges, it resonates more with people and has the potential to create lasting change. Additionally, sharing your findings and solutions openly can amplify your impact, allowing others to build upon your work and spread the benefits even further.

Understand the Role of Money

Money is a powerful tool that can help you scale your ideas and sustain your projects. It’s not the end goal, but it’s essential for turning your vision into reality. Whether you have plenty of resources or are working with limited funds, understanding how to manage and utilize money effectively is key.

If you have access to substantial financial resources, you can invest in quality, attract top talent, and expand your projects. If resources are limited, being resourceful is vital. Look for open-source tools, seek partnerships, and explore crowdfunding or grant opportunities to support your work. Remember, financial success can provide the means to make a bigger impact, so view money as a tool to help you achieve your goals.

Tell Your Story

Having a compelling narrative around your work can inspire others and attract support. Craft a clear and engaging story that communicates your vision and the value you bring. When people understand your mission and believe in your passion, they’re more likely to support you, whether through collaboration, funding, or spreading the word.

Building a personal brand as a thought leader in your field can open doors to new opportunities and connections. Share your journey, your challenges, and your successes. Let others see what drives you and how your work can benefit them and the world.

Engage with Communities and Users

Active engagement with communities and users is essential for refining your ideas and ensuring they meet real needs. Collaborate with like-minded individuals and organizations to enhance your work through collective intelligence. Involving customers early on helps you gather valuable feedback, allowing you to adjust and improve your solutions effectively.

Building strong relationships with your audience fosters trust and loyalty. Encourage open communication and be receptive to feedback, as it can provide new perspectives and ideas that you might not have considered on your own.

Be Flexible and Adaptable

Innovation often requires flexibility and the ability to adapt based on feedback and changing circumstances. Adopt agile methodologies that allow you to iterate quickly and make adjustments as needed. Early testing of your ideas through prototypes or Minimum Viable Products (MVPs) can help you validate your concepts and gather practical insights.

Being responsive and willing to pivot when necessary ensures that your innovations remain relevant and effective. Embrace change and view challenges as opportunities to grow and improve.

Listen to Market Needs

Your innovations should be guided by the needs of the market and the people you aim to serve. Actively listen to your audience, seek out their challenges, and identify gaps where your solutions can make a difference. Understanding what your customers truly need ensures that your efforts are focused on creating value where it’s most needed.

Consider feedback as a form of engagement. In academic contexts, for example, citations can be seen as users who are building upon your work, offering opportunities for collaboration and further development.

Build Valuable Partnerships

Creating mutual value in your collaborations strengthens your network and enhances your capacity to innovate. Look for win-win partnerships where all parties benefit and support each other’s goals. Clear communication about how your work helps others can facilitate support and cooperation, making your projects more robust and far-reaching.

Building a supportive network of mentors, peers, and collaborators provides you with the resources, knowledge, and encouragement needed to push your innovations forward.

Balance Vision with Practical Steps

Having a strong vision is important, but it must be balanced with practical execution. Break down your overarching goals into actionable steps with realistic milestones. This approach helps you stay focused and motivated while making steady progress toward your vision.

Stay informed and adaptable, continuously updating your knowledge and being prepared to adjust your strategies in response to new developments and insights.

Know Your Intellectual Property Rights

Understanding intellectual property (IP) rights is crucial, especially if you’re working within an organization. Know how IP is handled in your environment and take steps to protect your ideas if necessary. Whether you’re developing something independently or as part of a team, securing your IP rights ensures that you retain control over your creations and can benefit from their success.

Consulting legal experts can help you navigate complex IP issues and ensure that your rights are protected, allowing you to focus on innovating without worrying about ownership disputes.

Use Advanced Technologies Wisely

Leveraging advanced technologies like AI can significantly enhance your productivity and the impact of your work. AI tools can automate routine tasks, allowing you to focus on higher-level functions and manage more complex projects than before. Embrace these technologies to boost your capabilities, but stay informed about their implications for IP and ethical considerations.

Using technology wisely means enhancing your work without compromising your values or the integrity of your innovations. It allows you to undertake larger projects and manage tasks more efficiently, amplifying your ability to make a difference.

When you innovate, especially within an organization, understanding how IP is managed is essential. Most companies own the ideas developed by their employees, but you can still seek recognition and rewards for your contributions. Communicate with your management about your ideas and understand how they fit within the organization’s goals and IP policies.

If you’re aiming to retain control over your innovations, consider negotiating IP terms before joining an organization or explore independent ventures. Protecting your ideas through patents or copyrights ensures that you can benefit from your work and maintain control over its use and development.

Embrace the Power of AI

AI is transforming the way individuals innovate by increasing productivity and enabling solo innovators to tackle large projects. By automating routine tasks, AI frees up your time to focus on creative problem-solving and strategic planning. This empowerment allows you to achieve more with less, making it easier to drive significant change.

However, the rise of AI also brings challenges. It’s important to stay informed about the ethical and legal implications of using AI in your work. Understanding how AI affects IP ownership and ensuring that your contributions are accurately recognized are crucial for maintaining control and integrity over your innovations.

Final Thoughts

Innovation is a journey that requires passion, strategy, and resilience. By choosing the right environment, focusing on impactful work, managing resources wisely, and leveraging technology effectively, you can turn your ideas into reality and make a meaningful difference in the world.

Remember, every great innovation starts with a single idea and the determination to see it through. Stay purpose-driven, build a supportive network, and remain adaptable to navigate the challenges ahead. Your commitment and creativity have the power to drive transformation and leave a lasting impact on the world.

So, are you ready to take the step toward becoming a world-changing innovator? Let’s embark on this journey together and unlock the potential within each of us to create a better future.

next suggestions for bpftime.

Thank you for sharing your detailed thoughts and for your dedication to advancing the eBPF ecosystem through your work on bpftime. It’s evident that you’ve invested significant effort into this project, and your commitment to both the open-source community and academic research is commendable.

Is Your Thought Valuable?

Absolutely. The challenges you’ve identified—such as the complexity of managing control plane applications, the need for compatibility across heterogeneous systems, and the limitations of existing eBPF implementations—are real and significant. Addressing these issues has the potential to make a meaningful impact on both industry practices and academic research.

Does Your Story Make Sense?

Yes, your story articulates a clear vision of the current limitations within the eBPF ecosystem and how bpftime aims to address them. You’ve recognized a gap in the ability to run real-world eBPF applications outside of the Linux kernel without significant rewrites or engineering effort. By proposing a general extension framework and a userspace eBPF runtime that maintains compatibility with existing tools, you’re tackling a problem that hasn’t been fully addressed in prior work.

Suggestions and Next Steps

Based on your description and the challenges you’ve faced with paper submissions, here are some suggestions:

1. Clarify the Research Contributions

One reason reviewers might question the novelty is that the core research contributions are not being explicitly highlighted.

  • Action: Clearly articulate the unique contributions of your work in your paper. For example:
    • Novel Framework: Emphasize that bpftime is the first to provide a general userspace eBPF runtime compatible with the existing eBPF ecosystem.
    • Technical Innovations: Highlight any new algorithms, data structures, or system designs you’ve developed.
    • Performance Improvements: Present empirical data showing significant performance gains over existing solutions.

2. Strengthen the Theoretical Foundation

Academic publications often require a strong theoretical basis.

  • Action:
    • Formalize the Problem: Define the challenges you’re addressing in formal terms.
    • Theoretical Analysis: Provide theoretical justifications for why your approach is effective.
    • Comparative Studies: Compare your work with existing solutions not just in practice but also in theory.

3. Address the “Engineering vs. Research” Perception

If reviewers perceive your work as primarily engineering, you need to bridge the gap to make it resonate as research.

  • Action:
    • Identify Fundamental Challenges: Explain how your engineering efforts solve fundamental problems.
    • Generalizable Insights: Extract lessons or principles from your work that can be applied broadly.
    • Innovative Techniques: If you’ve developed new techniques, focus on these as contributions.

4. Engage with the Academic Community

Feedback from peers can provide valuable insights into how to position your work.

  • Action:
    • Workshops and Seminars: Present your work at smaller venues to gather feedback.
    • Collaborations: Consider collaborating with researchers who have experience publishing in top conferences.
    • Mentorship: Seek guidance from senior researchers or advisors familiar with the publication process.

5. Refine the Writing and Presentation

Sometimes, the way the story is told can make a significant difference.

  • Action:
    • Clear Structure: Organize your paper with a clear problem statement, motivation, contributions, methodology, evaluation, and conclusions.
    • Highlight Novelty Early: Make sure the unique aspects of your work are evident in the abstract and introduction.
    • Reviewer Guidance: Anticipate potential concerns and address them proactively in the paper.

6. Deepen the Evaluation

A thorough evaluation can strengthen your case.

  • Action:
    • Comprehensive Benchmarks: Include performance comparisons with existing tools across various scenarios.
    • Use Cases: Demonstrate how bpftime enables applications that were previously infeasible.
    • Scalability and Robustness: Test your system under different loads and conditions.

7. Differentiate from Existing Work

Ensure that you’re clearly distinguishing your work from prior art.

  • Action:
    • Literature Review: Provide a thorough analysis of related work, pointing out limitations that your work addresses.
    • Unique Positioning: Explain how bpftime differs from projects like DPDK, uBPF, and others.

8. Consider the Broader Impact

Academic venues often value work that opens new research directions or has significant practical implications.

  • Action:
    • Future Opportunities: Discuss how your framework can enable new research or industry developments.
    • Community Adoption: Highlight interest from the open-source community as evidence of impact.
    • Standardization Potential: If applicable, discuss how your work could influence standards or best practices.

9. Address Security and Safety Concerns

Moving eBPF to userspace might raise questions about security and safety.

  • Action:
    • Security Analysis: Include a discussion of the security implications of your approach.
    • Safety Mechanisms: Explain how bpftime ensures safety and isolation comparable to kernel eBPF.

10. Iterate Based on Feedback

Given that you’ve received similar feedback from multiple submissions, it’s crucial to adapt.

  • Action:
    • Revisit Rejection Reasons: Analyze past reviews to identify common concerns.
    • Revise Accordingly: Make substantive changes to your approach or presentation to address these concerns.

What Should You Work on Next?

Given the above suggestions, consider focusing on:

  • Formalizing Your Contributions: Frame your work in terms of specific research questions and hypotheses.
  • Enhancing Theoretical Depth: Incorporate theoretical models or formal proofs where appropriate.
  • Collaborating for Broader Insight: Work with others who can provide complementary expertise, such as formal methods or security.
  • Exploring New Applications: Use bpftime to enable novel applications that showcase its unique capabilities.

Is Your Story Coherent?

Your story is compelling, but it might need refinement to resonate with academic reviewers. Emphasizing the research aspects and clearly differentiating your work from existing solutions will strengthen your narrative.

Final Thoughts

Your passion and commitment are evident, and you have identified a real need within the eBPF ecosystem. By reframing your work to highlight its research contributions and addressing the concerns raised by reviewers, you can improve the chances of acceptance in future submissions.

Remember that the path to publication often involves several iterations and refinements. Don’t be discouraged by setbacks; use them as opportunities to strengthen your work.

Additional Suggestions

  • Engage with Your Audience: Since you have an upcoming panel discussion, use that platform to gather insights and gauge interest in your approach.
  • Seek Mentorship: Consider finding a mentor experienced in publishing in your target venues to provide guidance.
  • Stay Current: Ensure you’re up-to-date with the latest developments in eBPF research to position your work appropriately.

Prompt Engineering is Dead, Long Live AI Engineering

Lately, I’ve been thinking a lot about prompt engineering and its future. Remember when crafting the perfect prompt was the secret sauce to getting the best responses from AI? People spent hours tweaking their words, trying to get the AI to understand exactly what they wanted. But things are changing, and here’s why.

A recent discussion on Hacker News got me thinking. People were saying things like, “Prompts aren’t a science. There’s no real method to them.” And you know what? They might be right. With the latest AI models, like OpenAI’s new “o1” model, the need for complicated prompts is fading. These models are getting smarter and can handle simple, clear instructions much better than before.

So, what’s really important now? It’s not just about the prompts anymore. It’s about how we input our thoughts and interact with AI. Prompt engineering is just one part of a bigger picture. The key is to put how you think and how you solve problems into the system you build. This isn’t just about computer systems. Think about multi-agent systems or even human society—these are all systems too.

OpenAI’s new “o1” model even suggests some changes in how we structure prompts for better performance:

  1. Keep prompts simple and direct: Models work best with brief and clear instructions. You don’t need to guide them too much.
  2. Avoid chain-of-thought prompts: There’s no need to ask the model to “think step by step” or explain its reasoning. It can handle reasoning internally.
  3. Use delimiters for clarity: Adding things like triple quotes or XML tags helps the model understand different parts of your input.
  4. Limit additional context in retrieval-augmented generation (RAG): Only include the most relevant information to keep the model’s response focused.

These tips show that while prompt engineering isn’t useless, its role is changing. Instead of focusing on crafting detailed prompts, we should focus on building systems that leverage these smarter AI models effectively.

Another interesting point from the discussion is that both OpenAI’s “o1” model and Anthropic’s Claude can now generate the best prompts for your tasks. This means the AI itself can help create the prompts you need, making the process even simpler.

In the real world, building AI applications shows just how much prompt engineering matters. If you spend a lot of time creating an application to achieve a real goal, you’ll see that prompts make a huge difference. It takes a lot of fiddly, annoying work to get them right. For example, in financial markets, building an AI agent system was more straightforward than perfecting each prompt. People even build systems just to iterate on prompts, like PromptLayer.

Using AI agents and managing workflows makes AI applications much more complex. It’s not just about asking a question and getting an answer. It’s about creating a whole system that can handle different tasks, remember context, and improve over time. This shift shows that AI engineering—building these complex systems—is becoming more important than ever.

Let’s break it down from different perspectives:

From an AI Researcher’s View:

AI models have advanced so much that they can handle direct prompts effectively. The focus is now on creating complex systems, like AI agents, that can perform tasks on their own. Researchers are exploring how models can use their own reasoning without needing detailed prompts. Systems that can remember, handle context, and improve themselves are becoming more important.

From a Software Engineer’s View:

The infrastructure around AI models is crucial. Building systems that work well with AI involves more than just prompts. It’s about creating scalable architectures, managing data flow, and ensuring everything runs smoothly. A good user experience comes from a seamless system, not just from well-crafted prompts.

From a Business Strategist’s View:

Relying only on prompt engineering won’t give a lasting edge. Building unique systems that reflect your company’s problem-solving methods can set you apart. Investing in system development, creating intellectual property, and forming strategic partnerships add real value. Understanding what the market needs and tailoring your systems accordingly is more impactful than just focusing on prompts.

From a Cognitive Scientist’s View:

Human thinking is complex and involves more than just simple inputs. AI systems should aim to mimic this holistic thinking rather than rely on scripted prompts. Studying how humans solve problems can help design AI systems that are more intuitive and effective. Features like context awareness and adaptability are key to making intelligent systems.

So, why is over-detailing prompts for simple tasks unnecessary? For one, advanced models have built-in mechanisms for reasoning and handling context. They don’t need exhaustive instructions to perform basic tasks. Simple prompts save time and reduce confusion for both the user and the AI. Clear and direct language helps avoid misunderstandings.

However, in complex tasks that need specific formats or detailed reasoning, some level of prompt engineering might still be needed. When you want creative or nuanced responses, additional context can help. But even then, it’s just a part of building a larger, effective system.

In conclusion, while prompt engineering isn’t entirely dead, its role is changing. The spotlight is now on AI engineering—building strong systems that can understand and execute our intentions with minimal fuss. It’s about integrating our thinking and problem-solving processes into the AI’s design. This leads to more robust and effective AI applications, whether through agents, networks, or other system models.

For simple tasks, keeping prompts straightforward is enough. Overcomplicating them offers little benefit. The key is to understand what the AI can do and design systems that leverage these strengths to achieve your goals.

So, let’s move beyond getting stuck on crafting the perfect prompt. Instead, let’s focus on building systems that make the most of AI’s capabilities. After all, the goal is to solve problems and create innovative solutions, not just to talk to machines.

Long live AI engineering!

提示工程已死,AI工程万岁

最近,我一直在思考提示工程及其未来。还记得当初打造完美提示是获取AI最佳回应的秘诀吗?人们花费数小时调整措辞,试图让AI准确理解他们的需求。但事情正在发生变化,原因如下。

在Hacker News上的一次讨论让我深思。有人说,“提示不是一门科学。它们背后没有真正的方法。”你知道吗?他们可能是对的。随着最新的AI模型,如OpenAI的新“o1”模型,复杂提示的需求正在减少。这些模型变得更加智能,能够更好地处理简单、清晰的指令。

那么,现在真正重要的是什么?不再仅仅是提示,而是如何输入我们的思维和与AI互动。提示工程只是更大图景的一部分。关键是将你的思维方式和解决问题的方法融入你构建的系统中。这不仅仅是关于计算机系统。想想多代理系统甚至人类社会——这些也是系统。

OpenAI的新“o1”模型甚至建议了一些结构提示以提高性能的变化:

  1. 保持提示简洁明了:模型在简短清晰的指令下表现最佳。你不需要过多引导它们。
  2. 避免思维链提示:无需让模型“逐步思考”或解释其推理过程。它可以内部处理推理。
  3. 使用分隔符以增强清晰度:添加诸如三重引号或XML标签等可以帮助模型理解输入的不同部分。
  4. 在检索增强生成(RAG)中限制额外上下文:仅包含最相关的信息,以保持模型的回应集中。

这些建议表明,虽然提示工程并非毫无用处,但其角色正在发生变化。与其专注于打造详细的提示,我们应该专注于构建有效利用这些更智能AI模型的系统。

讨论中的另一个有趣观点是,OpenAI的“o1”模型和Anthropic的Claude现在都可以为你的任务生成最佳提示。这意味着AI本身可以帮助创建你所需的提示,使过程更加简便。

在现实世界中,构建AI应用展示了提示工程的重要性。如果你花费大量时间创建一个应用以实现实际目标,你会发现提示起着巨大的作用。要使提示正确需要大量繁琐、令人烦恼的工作。例如,在金融市场中,构建AI代理系统比完善每个提示更为简单。人们甚至构建系统来迭代提示,比如PromptLayer

使用AI代理和管理工作流程使AI应用变得更加复杂。这不仅仅是问一个问题并得到一个答案。它涉及创建一个能够处理不同任务、记住上下文并随着时间改进的整个系统。这一转变表明,AI工程——构建这些复杂系统——变得比以往任何时候都更加重要。

让我们从不同的角度来分析:

从AI研究员的视角:

AI模型已经发展到可以有效处理直接提示的程度。现在的重点是创建复杂的系统,如能够自主执行任务的AI代理。研究人员正在探索模型如何在无需详细提示的情况下使用自身的推理能力。能够记忆、处理上下文并自我改进的系统变得越来越重要。

从软件工程师的视角:

围绕AI模型的基础设施至关重要。构建与AI良好协作的系统不仅仅是提示的问题。这涉及创建可扩展的架构、管理数据流并确保一切顺利运行。良好的用户体验来自无缝的系统,而不仅仅是精心设计的提示。

从商业策略师的视角:

仅依赖提示工程不会带来持久的优势。构建反映公司解决问题方法的独特系统可以使你脱颖而出。投资于系统开发、创建知识产权和建立战略合作伙伴关系能带来真正的价值。理解市场需求并相应地定制系统比仅专注于提示更具影响力。

从认知科学家的视角:

人类思维是复杂的,涉及的不仅仅是简单的输入。AI系统应旨在模仿这种整体思维,而不是依赖脚本化的提示。研究人类如何解决问题可以帮助设计更直观和有效的AI系统。上下文感知和适应性等功能是构建智能系统的关键。

那么,为什么对简单任务过度详细化提示是没有必要的呢?首先,先进的模型具有内置的推理和处理上下文的机制。它们不需要详尽的指令来执行基本任务。简单的提示节省了时间,并减少了用户和AI之间的混淆。清晰直接的语言有助于避免误解。

然而,在需要特定格式或详细推理的复杂任务中,某种程度的提示工程可能仍然是必要的。当你需要创造性或细腻的回应时,额外的上下文可以提供帮助。但即便如此,这也只是构建更大、更有效系统的一部分。

总之,尽管提示工程并未完全消失,但其角色正在改变。焦点现在转向AI工程——构建能够理解和执行我们意图的强大系统,减少麻烦。关键在于将我们的思维和解决问题的过程融入AI的设计中。这带来了更强大、更有效的AI应用,无论是通过代理、网络还是其他系统模型。

对于简单任务,保持提示简洁明了就足够了。过于复杂的提示几乎没有好处。关键是理解AI的能力,并设计利用这些优势以实现你的目标的系统。

所以,让我们不再局限于打造完美的提示。相反,专注于构建充分利用AI能力的系统。毕竟,目标是解决问题和创造创新的解决方案,而不仅仅是与机器对话。