g*********s 发帖数: 1782 | 1 如果两个词法单位有共同前缀,匹配的优先级是怎么定的?最长优先吗?
比如:
id [A-Za-Z]+
array id[[0-9]]
%%
{id} { return "ID"; }
{array} { return "ARRAY"; }
记不清有限自动机是怎么处理这种情况了。 | c*****t 发帖数: 1879 | 2 Nope. If both patterns match the same string, the rule specified
earlier has the precedence.
Typically, the patterns specified later can be less stringent, because
they only cover strings "leaked" by earlier patterns.
However, in your case, the two patterns are simply different.
p.s [[0-9]] isn't a valid character set I think. [[:digit:]] is.
[a-Z] is dangerous since no one remembers the whole ascii map, unless
you meant [A-Za-z].
【在 g*********s 的大作中提到】 : 如果两个词法单位有共同前缀,匹配的优先级是怎么定的?最长优先吗? : 比如: : id [A-Za-Z]+ : array id[[0-9]] : %% : {id} { return "ID"; } : {array} { return "ARRAY"; } : 记不清有限自动机是怎么处理这种情况了。
| g*********s 发帖数: 1782 | 3 哦,我是说共同前缀。abc和abc[1]是识别成id还是array。
【在 c*****t 的大作中提到】 : Nope. If both patterns match the same string, the rule specified : earlier has the precedence. : Typically, the patterns specified later can be less stringent, because : they only cover strings "leaked" by earlier patterns. : However, in your case, the two patterns are simply different. : p.s [[0-9]] isn't a valid character set I think. [[:digit:]] is. : [a-Z] is dangerous since no one remembers the whole ascii map, unless : you meant [A-Za-z].
| c*****t 发帖数: 1879 | 4 array. lex/flex 总是尽量 match 最长的。你的 regex 让人糊涂 :(
【在 g*********s 的大作中提到】 : 哦,我是说共同前缀。abc和abc[1]是识别成id还是array。
| g*********s 发帖数: 1782 | 5 hehe, sorry and thx.
【在 c*****t 的大作中提到】 : array. lex/flex 总是尽量 match 最长的。你的 regex 让人糊涂 :(
|
|