FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String literal / EBNF to regular expression

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
BLS



Joined: 28 Mar 2006
Posts: 44
Location: France

PostPosted: Mon Aug 27, 2007 5:49 am    Post subject: String literal / EBNF to regular expression Reply with quote

Hi just a question about String literals :
"hello world"
'hello world'
'hello "cruel" world' // and vice versa
What is legal ?

And ahem Embarassed I need some help in translating the int and float literals EBNF def. into regular expressions. Anybody willing to help ?
Given :

'a' character a
"abc" string abc - syntax is the same like in Java (\t, \n, ...)
"ab"i case-insensitive string, i.e. ab, Ab, aB or AB
['a' 'b' 'c'] charater a, b, or c (simple class)
[^'a' 'b' 'c'] any character except a, b, or c (negation)
['a'-'z' 'A'-'Z'] a through z or A through Z, inclusive (range)
. any character
'a'? character a once or not at all
'a'+ character a one or more time
'a'* character a zero or more time
XY X followed by Y
X/Y Either X or Y
(X) X, as a capturing group

Many thanks in advance Bjoern
Back to top
View user's profile Send private message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Mon Aug 27, 2007 7:53 am    Post subject: Reply with quote

The string literals are almost identical to those in D. That is, double-quoted strings can contain any character (except a double quote), escape code, or end of line (that is, they can be multiline). Backtick-quoted strings, or string that begin with @" are WYSIWYG strings and can contain any character (except backtick for backtick-quoted strings and double quotes for those that begin with @"), can span multiple lines, and do not interpret escape sequences. Character literals are single-quoted, and contain exactly one character or escape sequence. MiniD does not have single-quoted strings.

Ints should be something like...

(['0'-'9']['0'-'9' '_']*)/(0['b' 'B']['0' '1' '_']+)/(0['c' 'C']['0'-'7' '_']+)/(0['x' 'X']['0'-'9' 'a'-'f' 'A'-'F' '_']+)

Floats:

((['0'-'9']['0'-'9' '_']*)?\.['0'-'9' '_']+(['e' 'E']['+' '-']?['0'-'9' '_']+)?)/(['0'-'9']['0'-'9' '_']*(['e' 'E']['+' '-']?['0'-'9' '_']+)?)

The \. in there means a literal period. I don't know how your regex syntax escapes special characters but the backslash is pretty universal, so..
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group