#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0

    Regular Expressions in Lex


    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
  2. #2
  3. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,850
    Rep Power
    6351
    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
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2010
    Posts
    2
    Rep Power
    0
    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.



    Originally Posted by ManiacDan
    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

IMN logo majestic logo threadwatch logo seochat tools logo