Re: Variable Declaration syntax?

Chris F Clark <cfc@shell01.TheWorld.com>
8 Apr 2006 16:03:32 -0400

          From comp.compilers

Related articles
Variable Declaration syntax? nvn_ravi@sify.com (Ravi) (2006-04-03)
Re: Variable Declaration syntax? cfc@shell01.TheWorld.com (Chris F Clark) (2006-04-08)
Re: Variable Declaration syntax? torbenm@app-4.diku.dk (2006-04-08)
| List of all articles for this month |

From: Chris F Clark <cfc@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: 8 Apr 2006 16:03:32 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 06-04-014
Keywords: design, syntax
Posted-Date: 08 Apr 2006 16:03:32 EDT

Ravi asked:
> I like to known why in most of the programming languages has a constran
> like the first character of the variable declaration should not be any
> special character,numbers,etc.


Beside making the lexing easier as our moderator mentioned, it has
other benefits. To my mind the most important reason is that it makes
it easier for human readers. You want names that match the human
readers intuition of what names are. Thus, because of the long (in CS
terms) history of identifiers starting with letters, new languages
tend to follow the same rules.


A secondary reason is that sometimes downstream tools, e.g. linkers
and/or assemblers, have restrictions on the names. The compilers
rules avoid passing the linker names that would violate that tools
rules.


There are exceptions to the above rules. For example, whether a
leading _ can start an identifier ofter varies from language to
language. PL/I used to consider the 3 characters @, #, and $ as
"national" alphabetic characters. Verilog allows $ to start
identifiers in certain instances (to indicate "system names").


You can do what ever you think your users will understand. But, not
that starting with a digit is particularly problematic, as it make
1e10 potentially a name rather than a number, and also can make hex
numbers difficult to lex.


In college, I defined a language where an arbitrary character
sequences could be identifiers, I simply required the first instance
(in a declaration) to be a properly quoted string. Fortunately, I
never implemented that language as it would have been one of the worst
write-only languages ever devised.


Hope this helps,
-Chris


*****************************************************************************
Chris Clark Internet : compres@world.std.com
Compiler Resources, Inc. Web Site : http://world.std.com/~compres
23 Bailey Rd voice : (508) 435-5016
Berlin, MA 01503 USA fax : (978) 838-0263 (24 hours)


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.