TeX方程的开始条件 [英] start condition for TeX equations
问题描述
在lex中,我可以为$...$
之间定义的方程式定义以下起始条件.
In lex, I can define the following starting condition for equations defined between $...$
.
%x EQN1
\$ { BEGIN(EQN1); }
<EQN1>{
\$ { BEGIN(INITIAL); }
[^\$]* {}
}
对于$$...$$
之间的方程式,如何定义除$$
规则以外的任何内容,例如在[^\$]*
中.我猜[^\$\$]*
无法正常工作.
For equations between $$...$$
, how can I define the anything but $$
rule, such as in [^\$]*
. I guess [^\$\$]*
wouldn't work.
推荐答案
I think you don't understand the way the patterns are matched, see flex manual
Flex始终尝试匹配可能的最长输入.您可以这样理解,较长的规则具有更高的优先级.
Flex always try to match longest input possible. You can understand it in way, that longer rules have higher priority.
因为"\ $ \ $"匹配两个字符和.".仅一个,下面的示例就可以正常工作.
Because "\$\$" match two characters and "." just one, the example below will work just fine.
%x EQN2
\$\$ { BEGIN(EQN2); }
<EQN2>{
\$\$ { BEGIN(INITIAL); }
. {}
}
在示例中,您还可以将[^\$]* {}
替换为. {}
,因为当规则匹配相同大小的输入时,lex.l中的第一个优先级更高.
You can also replace [^\$]* {}
with . {}
in your example, because when rules match same size of input, the first one in lex.l has higher priority.
这篇关于TeX方程的开始条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!