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

Alex Colvin <alexc@TheWorld.com>
17 Oct 2004 16:06:41 -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)
[8 later articles]
| List of all articles for this month |
From: Alex Colvin <alexc@TheWorld.com>
Newsgroups: comp.compilers
Date: 17 Oct 2004 16:06:41 -0400
Organization: The World : www.TheWorld.com : Since 1989
References: 04-10-092
Keywords: syntax, design
Posted-Date: 17 Oct 2004 16:06:41 EDT

>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:


>for example in python you use: def setColor (r, g, b):


>I was wondering why that is. I suspect the point is to avoid of ambiguity


Most scripting languages, unlike most other languages, accept
statements outside of procedures, to be executed immediately.


This leads to an ambiguity for setColor(a,b,c), which is resolved in favor
of the statement. A definition requires the extra "def" token.
I suppose they could have required an extra token "call" in front of the
statement.


>func_name '(' param_list ')' IS_TOKEN
> func_body
>END_TOKEN


>Does anyone have any suggestions as to whether or not I should have/need a
>keyword in front?


Can your parser can handle it after the function? It means you don't know
whether you're looking at a call or a definition until the IS_TOKEN.


--
mac the naïf


Post a followup to this message

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