From: | Louis Krupp <lkrupp@pssw.NOSPAM.com.INVALID> |
Newsgroups: | comp.compilers |
Date: | 17 Oct 2004 16:11:07 -0400 |
Organization: | Posted via Supernews, http://www.supernews.com |
References: | 04-10-092 |
Keywords: | syntax, design |
Posted-Date: | 17 Oct 2004 16:11:06 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. For example:
>
> ruby and python use "def"
> perl uses "sub"
> lua uses "function"
> tcl uses "proc"
>
> 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
> with other language constructs, but I'm not sure. If possible, I don't want
> to use a keyword. The grammar I want to use for my scripting language would
> go something like this:
>
> func_name '(' param_list ')' IS_TOKEN
> func_body
> END_TOKEN
C doesn't use a keyword when defining functions. Function definitions
usually start with types like "int," but in the original K&R C, that was
optional.
And don't forget FORTRAN statement functions. They didn't need keywords.
And who remembers DCL subroutines? All they needed was a label, RETURN,
and GOSUB.
Note that C is harder to parse than most other languages, and the
FORTRAN parsing algorithm is still named after its inventor.
Louis Krupp
Return to the
comp.compilers page.
Search the
comp.compilers archives again.