Building C++ modules

Jacob Carlborg doob at me.com
Tue Aug 13 09:19:16 UTC 2019


On 2019-08-12 21:58, H. S. Teoh wrote:

> This is a big part of why C++'s must-be-parsed-before-it-can-be-lexed
> syntax is a big hindrance to meaningful progress.  The only way such a
> needlessly over-complex syntax can be handled is a needlessly
> over-complex lexer/parser combo, which necessarily results in needlessly
> over-complex corner cases and other such gotchas.  Part of this
> nastiness is the poor choice of template syntax (overloading '<' and '>'
> to be delimiters in addition to their original roles of comparison
> operators), among several other things.

I don't know how this is implemented in a C++ compiler but can't the 
lexer use a more abstract token that includes both the usage for 
templates and for comparison operators? The parser can then figure out 
exactly what it is.

DMD is doing something similar, but at a later stage. For example, in 
the following code snippet: "int a = foo;", "foo" is parsed as an 
identifier expression. Then the semantic analyzer figures out if "foo" 
is a function call or a variable.

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list