www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Why is C++ so hard to parse?

reply Pete <Pete_member pathlink.com> writes:
Hi,

I don't know much about parsing programming language. But I want to know what
makes C++ hard to parse and does D these things right?
Jan 26 2005
next sibling parent reply Dejan Lekic <leka entropy.tmok.com> writes:
Pete, IMHO C++ is not harder to parse than any other modern language,
including D.

-- 
...........
Dejan Lekic
  http://dejan.lekic.org
  
Jan 26 2005
next sibling parent reply Pete <Pete_member pathlink.com> writes:
Pete, IMHO C++ is not harder to parse than any other modern language,
including D.

A large C++ project here takes mor then three minutes for a complete re-compilation. An even larger C# project takes only a few seconds. This isn't C# specific. Java is as fast. I did only some _very_ small D programs (if you want to call them programs), so I don't know how fast D will compile.
Jan 26 2005
parent Dejan Lekic <leka entropy.tmok.com> writes:
"Parsing process" != "Compilation (build process)"

-- 
...........
Dejan Lekic
  http://dejan.lekic.org
  
Jan 26 2005
prev sibling parent "Walter" <newshound digitalmars.com> writes:
"Dejan Lekic" <leka entropy.tmok.com> wrote in message
news:ct839i$1iqj$1 digitaldaemon.com...
 Pete, IMHO C++ is not harder to parse than any other modern language,
 including D.

I've written a parser for both C++ and D. C++ is a lot harder. In fact, C++ is probably the most difficult computer language to parse. D is one of the easier ones.
Jan 26 2005
prev sibling next sibling parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Pete wrote:
 Hi,
 
 I don't know much about parsing programming language. But I want to know what
 makes C++ hard to parse

Basically, the places where C++ grammar isn't context-free: - cast expressions - template syntax - preprocessor macros to twist the syntactical structure - probably other things.... This means that before C++ can parse something, it must know what the identifiers in it refer to. Consequently, to write a properly-working C++ parser, you almost have to go the whole hog and write a compiler. Consequently, writing code manipulation tools (syntax-directed editors, beautifiers, linters, whatever) becomes tricky. Moreover, parsing engines/parser generators such as yacc expect a context-free grammar. Maybe it's possible using lex/yacc to manipulate the lexer as part of the parsing process, but it must be quite hard to do.
 and does D these things right?

Yes, modulo a few bugs and one legacy waiting to be thrown out. The benefits of context-free grammar don't end there. For example, I think the ability to pre-parse is one thing enabling D to gradually eliminate forward declarations. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 26 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Stewart Gordon wrote:
<snip>
 The benefits of context-free grammar don't end there.  For example, I 
 think the ability to pre-parse is one thing enabling D to gradually 
 eliminate forward declarations.

JTAI, there is at least one bit of C++ that supports forward referencing. Not to mention Java, which has some of the non-context-free grammar from C++. But still, no doubt context-free grammar considerably simplifies the process of supporting forward referencing.... Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 26 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Wed, 26 Jan 2005 16:11:05 +0000, Stewart Gordon <smjg_1998 yahoo.com>  
wrote:
 JTAI

I hadn't seen this one before, and googling for it didn't help initially :) http://www.google.com/search?q=JTAI&sourceid=opera&num=0&ie=utf-8&oe=utf-8 - "Jewish Teen Arts Institue" I now know it means - "Just Thinking About It" Regan
Jan 26 2005
parent reply Stewart Gordon <smjg_1998 yahoo.com> writes:
Regan Heath wrote:
 On Wed, 26 Jan 2005 16:11:05 +0000, Stewart Gordon 
 <smjg_1998 yahoo.com>  wrote:
 
 JTAI

I hadn't seen this one before, and googling for it didn't help initially :) http://www.google.com/search?q=JTAI&sourceid=opera&num=0&ie=utf-8&oe=utf-8 - "Jewish Teen Arts Institue" I now know it means - "Just Thinking About It"

http://www.acronymfinder.com is a decent source ITR. (Except that it doesn't list the one I just used ... but hopefully it's understandable FTC.) Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 27 2005
parent reply "Regan Heath" <regan netwin.co.nz> writes:
On Thu, 27 Jan 2005 10:28:20 +0000, Stewart Gordon <smjg_1998 yahoo.com>  
wrote:
 Regan Heath wrote:
 On Wed, 26 Jan 2005 16:11:05 +0000, Stewart Gordon  
 <smjg_1998 yahoo.com>  wrote:

 JTAI

initially :) http://www.google.com/search?q=JTAI&sourceid=opera&num=0&ie=utf-8&oe=utf-8 - "Jewish Teen Arts Institue" I now know it means - "Just Thinking About It"

http://www.acronymfinder.com is a decent source ITR. (Except that it doesn't list the one I just used ... but hopefully it's understandable FTC.)

acronymfinder is where I got JTAI from... I cannot figure out ITR, but is FTC (From the context)? Regan
Jan 27 2005
parent reply Norbert Nemec <Norbert Nemec-online.de> writes:
Regan Heath wrote:

 I cannot figure out ITR,

In This Respect
Jan 27 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Norbert Nemec wrote:
 Regan Heath wrote:
 
 I cannot figure out ITR,

In This Respect
 but is FTC (From the context)?


Got it in two. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jan 28 2005
prev sibling parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Pete wrote:

 I don't know much about parsing programming language. But I want to know what
 makes C++ hard to parse and does D these things right?

I have full sympathy for the parser and compiler, as I can hardly parse regular C++ code myself :-) --anders
Jan 26 2005