Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
你如何区分标记序列“op_Minus”“数字”和简单的负数?
我认为它依赖于上下文并依赖于您在解析源代码时遇到的操作数的数量。
根据您选择/遇到的语法类型,您在处理减法时会遇到这样的情况:
operand1 - operand2
或者如果您的语言使用前缀表示法,您最终会得到如下内容:
- operand1 operand2 (- operand1 operand2)
在这两种情况下,如果您正在处理减法或负数,您应该能够从前一个标记(在中缀表示法的情况下)或从前瞻到下一个标记/下两个标记)进行推断,假设后者只有一个操作数。