The Artima Developer Community
Sponsored Link

Design Forum
Need help with my programming homwork!

2 replies on 1 page. Most recent reply: Jan 5, 2006 12:38 PM by Cleo Saulnier

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Frank Miller

Posts: 1
Nickname: ten0d
Registered: Nov, 2005

Need help with my programming homwork! Posted: Nov 25, 2005 9:25 AM
Reply to this message Reply
Advertisement
Hey everyone. Great looking board here. Hopefully I came to the right place. :)

I'm in college right now and I'm a database developer by trade, but not a programmer. I'm doing my programming homework though and I'm stumped on a problem and I'm wondering if you could help me! Here's the question.

A FIXED number is defined by the BNF grammar:
N -> D. | D.D
D -> ND | N
N -> 0|1|2|3|4|5|6|7|8|9
Give a regular expression for FIXED numbers


I don't get it.. Any help? Thanks!


Joumon He

Posts: 1
Nickname: joumon
Registered: Jul, 2005

Re: Need help with my programming homwork! Posted: Jan 5, 2006 1:33 AM
Reply to this message Reply
Maybe like this^_^

N->D ['.' [D]]
D->C [D]
C->0|1|2|3|4|5|6|7|8|9

Cleo Saulnier

Posts: 77
Nickname: vorlath
Registered: Dec, 2005

Re: Need help with my programming homwork! Posted: Jan 5, 2006 12:38 PM
Reply to this message Reply
Homework usually isn't answered, but I think it's been long enough.

N -> "[0-9]"

That'll give you a digit from 0 to 9 in regular expression notation.

D is any sequence of digits with at least 1 digit.

D -> "[0-9]+"

The "+" means one or more, so that's exactly what "ND | N" means.

Finally, we have digits followed by a "." and optional following digits.

N -> "[0-9]+\.[0-9]*"

That's your answer. The last digits, I used a "*" which means 0 or more. Since 0 digits is allowable, this makes it optional. The backslash is used on the "." because in regular expression notation a dot means any character. A backslash takes the following character as is.

Flat View: This topic has 2 replies on 1 page
Topic: design pattern Previous Topic   Next Topic Topic: Struts with Ajax problem

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use