所有以“#”开头的文本的正则表达式但不是#define
我使用的正则表达式用于在 Flex 中实现预处理器。 这个预处理器有点简单。 它遵循以下规则:
- 预处理器指令以 #define 开头,后跟大写字母的标识符;
- 预处理器标识符的用例以
#
符号开头。
例如:
#define CONSTANT 100
//...
int x = #CONSTANT;
所以我做的第一件事是
#define {
//store the identifier following #define in a lookup table
//do the relevant error checking
}
NO_POUND_DEFINE {
//The string should begin with a '#' sign but not with `#define`
//check if the string following '#' is upper case or not
//if in upper case do the lookup otherwise throw an error
}
the regex i am using is for an implementation of preprocessor, in flex.
This preprocessor is kindof simple.
It obeys following rules:
- the preprocessor directive starts with #define followed by identifier in capital letters
- the use-case of preprocessor identifier begins with a
#
sign.
for example:
#define CONSTANT 100
//...
int x = #CONSTANT;
so first thing i did was
#define {
//store the identifier following #define in a lookup table
//do the relevant error checking
}
NO_POUND_DEFINE {
//The string should begin with a '#' sign but not with `#define`
//check if the string following '#' is upper case or not
//if in upper case do the lookup otherwise throw an error
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
^#([^d]|d[^e]|de[^f]|def[^i]|defi[^n]|defin[^e]).*
字符串开始带有“#”后不跟“d”或后跟“d”但后不跟“e”等。^#([^d]|d[^e]|de[^f]|def[^i]|defi[^n]|defin[^e]).*
The string starts with a '#' not followed by a 'd' or followed by a 'd' but not followed by an 'e' etc.也许您想看看这个: regular-expression-匹配不包含单词的字符串
Maybe you want to take a look at this: regular-expression-to-match-string-not-containing-a-word