在LEX中,如何解析某些代码,直到出现特殊符号? [英] In LEX, how to parse some code until a special symbol?
问题描述
我想知道在LEX中是否要解析一些代码直到出现特殊符号.
I was wondering that in LEX, if i want to parse some code until a special symbol.
例如:$display("Hello World");
在这里,我想获取$display("Hello World")
,但;
除外.
Here, I want to get $display("Hello World")
but except ;
.
我已经尝试过:\$"display".*[^;]
,它似乎没有用.
I've already tried this: \$"display".*[^;]
, it didn't seem to work.
任何帮助将不胜感激.谢谢.
Any help will be appreciated. Thanks.
推荐答案
.
匹配任何字符,而Kleene star *
将匹配其前面的许多字符.在这种情况下,您要匹配display
,后跟任何其他字符的列表.碰巧会包含您要捕获的位以及分号.
.
matches any character, and the Kleene star *
will match many of whatever precedes it. In this case, you're matching display
followed by a list of any other character. That'll happen to include the bit you want to capture and also the semicolon.
一个明显的解决方法是删除表达式的该部分,并将Kleene星移到[^;]
表达式之后.它将说匹配不是;
的任何字符的多个实例".这可能需要在子表达式周围加上括号(我不记得prices语法,因为它在词法分析器之间会有所不同).
Obvious fix is to remove that part of the expression, and move the Kleene star to after the [^;]
expression. Which will say "match multiple instances of any character which is not ;
". This might need parens around the sub-expression (I can't remember pricese syntax as it varies between lexers).
\$"display"([^;])*
或\$"display"[^;]*
这篇关于在LEX中,如何解析某些代码,直到出现特殊符号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!