dcsimg


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Regular expression

  1. #1
    Join Date
    Jan 2007
    Posts
    17

    Regular expression

    Hi,
    I want to write a parser in C(may be borland or MS-VC). I want to know is there any function to use regular expression in C. I dont want third parties library. If any native function on Windows platform please let me know.
    Thank you.
    Regards,
    Chirag.

  2. #2
    Join Date
    Jan 2005
    Location
    UK
    Posts
    604
    Hi,

    if you want to write a parser in C there are two programs I recommend: lex/yacc.
    There are various clones out there,too bison/byacc ....
    Many of them let you generate C++ classes as well as pure C functions and types.
    Just put something like "Parser generator" into your favourite search engine.
    I know, it's not exactly what you asked, but if you seriously want to write a compiler,
    that's the way to go.
    By the way: the Boost library has templates/classes for regex and parsing, but they will only work with C++. Probably you should consider that?

    Cheers,

    D
    DKyb
    -------------------------------
    Life is a short warm moment -
    Death is the long cold rest.
    Pink Floyd
    -------------------------------

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    You can download a regex library from www.boost.org
    It uses object-oriented, STL style iterators to search, replace and manipulate sequences fo text. This library is already part of standard C++, so if you can download an up-to-date versions of the Standard Library (Dinkum's for example), you can use it directly, without having to install any other patches or third-party libraries. I know that you're not looking for third-party libraries but since this is part of C++03, it's standard.
    If you're looking for C regex, you can use the POSIX regex libraries. However, I'm, not sure they're available on Windows.
    Last edited by Danny; 01-12-2007 at 07:33 AM.
    Danny Kalev

  4. #4
    Join Date
    Dec 2006
    Posts
    13
    C does not include any regular expression support in its standard library. Neither does C++. Visual C++ contains some regular expression support as part of ATL (the Regex class), but that's C++, not C. I'm not familiar with Borland C++ Builder's libraries so I could not tell if it contains some support for regexes.

    Boost (www.boost.org) does contain two different regular expression libraries for C++ (Regexp and Xpressive), and the Spirit parser (this is perhaps interesting for you, since you are able to define the grammar for the language you wish to parse by means of a BNF-like syntax, and the library takes care of all the parsing). A compiler-compiler tool such as Bison/Lex/Yacc, as drkybelk rightly indicates, is a valid alternate solution which does not require including external libraries.

    On a side note, parsing by means of regular expressions is not the best idea in the block, unless the grammar you intend to parse is very simple and linear. Regular expressions are capable of managing regular grammars (with a few enhancements for irregular grammars) but cannot deal correctly with context-free grammars (which include XML/HTML, a simple math string as "(b - 3) / 2 + 5" or even an URL string). It's difficult to explain why in simple terms without resorting to formal language theory, but context-free grammars require a very different approach for parsing, not the one used by regular expressions.

    Cheers.

Similar Threads

  1. Regular Expression Performance
    By Massif in forum Java
    Replies: 0
    Last Post: 07-19-2006, 04:42 PM
  2. Convert String to Regular Expression
    By alexl22 in forum Java
    Replies: 1
    Last Post: 11-18-2005, 11:26 AM
  3. Replies: 2
    Last Post: 09-29-2005, 02:09 AM
  4. regular expression
    By Claudiu in forum Database
    Replies: 1
    Last Post: 02-05-2003, 08:50 AM
  5. vbscript regular expression match HTML Tag
    By ac7117 in forum ASP.NET
    Replies: 0
    Last Post: 01-30-2002, 05:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center