Re: Parsing functions - do I need a keyword like 'def' to indicate a function?

lars@bearnip.com (Lars Duening)
17 Oct 2004 16:12:23 -0400

          From comp.compilers

Related articles
Parsing functions - do I need a keyword like 'def' to indicate a funct clearm_ATSYMBOL_comcast_DOT_net@giganews.com (M Cleary) (2004-10-12)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f awwaiid@thelackthereof.org (Brock) (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f cdc@maxnet.co.nz (Carl Cerecke) (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f alexc@TheWorld.com (Alex Colvin) (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f vbdis@aol.com (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f cfc@shell01.TheWorld.com (Chris F Clark) (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f lkrupp@pssw.NOSPAM.com.INVALID (Louis Krupp) (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f lars@bearnip.com (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f codeworker@free.fr (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f zhouhui@wam.umd.edu (Hui Zhou) (2004-10-17)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f postmaster@paul.washington.dc.us (Paul Robinson) (2004-10-21)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f angagon@earthlink.net (Matt O'Connor) (2004-10-30)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f alexc@TheWorld.com (Alex Colvin) (2004-11-02)
Re: Parsing functions - do I need a keyword like 'def' to indicate a f david.thompson1@worldnet.att.net (Dave Thompson) (2004-11-02)
[4 later articles]
| List of all articles for this month |

From: lars@bearnip.com (Lars Duening)
Newsgroups: comp.compilers
Date: 17 Oct 2004 16:12:23 -0400
Organization: Compilers Central
References: 04-10-092
Keywords: syntax, design
Posted-Date: 17 Oct 2004 16:12:23 EDT

M Cleary <clearm_ATSYMBOL_comcast_DOT_net@giganews.com> wrote:


> I'm trying to create a simple scripting language using lex and yacc. I've
> noticed that the grammars for most scripting languages have some kind of
> keyword in front of function declarations. For example:
>
> ruby and python use "def"
> perl uses "sub"
> lua uses "function"
> tcl uses "proc"


There are multiple considerations here:


On a purely syntactical level, there is no necessity to have the keyword
precede the function name. However, doing so may simplify the compiler
as it is immediately clear if "foobar()" is the call or the definition
of a function.


Consistency with and disambiguation from other language constructs are
other factors in the placement decision. In Python, for example, 'def'
is not just a syntactical marker, but a statement creating the function
when it is executed; so by using 'def name()' order this statement is
kept consistent with the others.


Post a followup to this message

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