Hi , i am working with regular expression and got into trouble how to differentiate between two patterns
LETTER [A-Za-z]
DIGIT [0-9]
LABELNAME {LETTER}(_|{LETTER}|{DIGIT})*
the above rule of labelname will accept anything. now i want to have another rule
REGNAME [pP]
REG_NUM [0-9]+
if i use first one i need to do further coding to get value of reg_num numerical value that why i want to use second one. problem is second rule fits in 1 rule also and so i get error results. is there any way i can have differen rules for second case and just able to have recognized patterns like p0 , P2 from second rule so that i dont need to do extra calculation to extract values as would have been in first case.
Thanks
What language are you writing this in? Is this actual code syntax or are you trying to explain something using this weird syntax?
The easiest way to get help is to tell us what language you're using, give us an example string, and tell us what you want to match.
Showing us what you have now is encouraged.
-Dan
Hi Dan,
This is specification in lex for probable strings/token.
i can have label name as label1 or label2
and
can have identifiers as p1,p2 p3.
if you see both of grammar second one is nothing but subset of first one. so when p1, p2 , p3 are encountered lex will not able able to decide what to do and will give syntax error.
i want some way by which i can differentiate between two cases.
Thanks for your reply.
i had found and alternative solution of my problem.
What language are you writing this in? Is this actual code syntax or are you trying to explain something using this weird syntax?
The easiest way to get help is to tell us what language you're using, give us an example string, and tell us what you want to match.