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.
在 flex 中,我如何定义一个词法分析器规则,例如除了$$. 对于单个字符,定义为:
$$
[^\$]
对于$$, 是否等于[^\$\$]?
[^\$\$]
您有正确的单个字符,现在只需将其加倍:[^\$][^\$]. 这将接受任何两个不是“$”的字符。如果您想允许单个“$”,那么您需要提供它作为替代:[^\$][^\$]|\$[^\$]|[^\$]\$.
[^\$][^\$]
[^\$][^\$]|\$[^\$]|[^\$]\$
无论如何,这最终将成为 DFA,因此没有效率问题。如果您需要多次执行此操作,请为模式命名,以便您只需要使用一次。