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

Carl Cerecke <cdc@maxnet.co.nz>
17 Oct 2004 16:05:36 -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)
[9 later articles]
| List of all articles for this month |
From: Carl Cerecke <cdc@maxnet.co.nz>
Newsgroups: comp.compilers
Date: 17 Oct 2004 16:05:36 -0400
Organization: TelstraClear
References: 04-10-092
Keywords: syntax, design
Posted-Date: 17 Oct 2004 16:05:36 EDT

M Cleary 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.
> I was wondering why that is. I suspect the point is to avoid of ambiguity
> with other language constructs.


Well, yes and no. Without a function definition keyword, a parser cannot
tell the difference between a function definition and a function call
until after the closing parenthesis. (Assuming the function argument
syntax is the same for calling and definition, as it is in python, but
not in, say, C or Java).


So, for example, given the statement "foo(a,b,c)", the parser would have
to get to the end of the statement before it can disambiguate between
function call, and function def. It's easier to be able to decide
before-hand, especially for plain top-down parsers. An LR-based parser
shouldn't have much trouble, unless there are other interfering language
constructs.


Cheers,
Carl.


Post a followup to this message

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