In LEX, how to parse some code until a special symbol?

▼魔方 西西 提交于 2019-12-11 10:57:16

问题


I was wondering that in LEX, if i want to parse some code until a special symbol.

For example: $display("Hello World");

Here, I want to get $display("Hello World") but except ;.

I've already tried this: \$"display".*[^;], it didn't seem to work.

Any help will be appreciated. Thanks.


回答1:


. 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.

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).

Either \$"display"([^;])* or \$"display"[^;]*



来源:https://stackoverflow.com/questions/14441674/in-lex-how-to-parse-some-code-until-a-special-symbol

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!