View previous topic :: View next topic |
Author |
Message |
BLS
Joined: 28 Mar 2006 Posts: 44 Location: France
|
Posted: Sun Sep 09, 2007 5:39 am Post subject: MiniD grammar problem/doubt |
|
|
Hi Jarret;
mX = 1;
What do we have here , an AssignmentExpression or a VariableDeclaration ?
IMO a clean VariableDeclarations is :
VariableDeclaration:
[ 'local' | 'global' ] 'var' Identifier {',' Identifier} ['=' Expression]
A bit later (rethinking):
By implementing the var keyword we can reduce Var.Decl. to:
VariableDeclaration:
[ 'global' ] 'var' Identifier {',' Identifier} ['=' Expression]
f.i. var mX = 1; means local var mX = 1;
The effort to change this seems to me reasonable. What do you think ?
Bjoern |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Sun Sep 09, 2007 9:02 am Post subject: |
|
|
Quote: | mX = 1;
What do we have here , an AssignmentExpression or a VariableDeclaration ? |
It's unambiguously an assignment. Variable declarations always begin with 'local' or 'global'.
Quote: | The effort to change this seems to me reasonable. What do you think ? |
I'm not entirely sure what the benefit is. |
|
Back to top |
|
|
BLS
Joined: 28 Mar 2006 Posts: 44 Location: France
|
Posted: Sun Sep 09, 2007 10:06 am Post subject: |
|
|
Hi Jarret, thanks for answering even on Sunday !
Code: |
class Test
{
mX = 0;
....
|
Unambiguously a Assignment ?
IMO I have to make semantic analyses
to asure my parser that : mX = 0; is NOT an AssignmentExpression...
when we follow this code fragment a bit ...
Code: |
class Test
{
mX = 0;
function foo()
{
return mX;
}
}
|
THEN mX =0; is an implicit VariableDeclaration as well as an AssignmentStatement
Let me copy and paste a bit from your MiniD EBNF
Code: |
VariableDeclaration:
LocalVarDeclaration
GlobalVarDeclaration
LocalVarDeclaration:
'local' Identifier {',' Identifier} ['=' Expression]
GlobalVarDeclaration:
'global' Identifier {',' Identifier} ['=' Expression]
//and further/later
Assignment:
AssignmentLHS {',' AssignmentLHS} '=' Expression
|
Maybe I miss something, but I mean that what I've suggested still makes sense.
Kind regards, Bjoern
[/quote][/code] |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Mon Sep 10, 2007 8:36 am Post subject: |
|
|
Quote: | THEN mX =0; is an implicit VariableDeclaration as well as an AssignmentStatement |
Neither grammatically nor semantically is it a variable declaration or an assignment. Class fields have their own grammar rules:
Code: | ClassDeclaration:
['local' | 'global'] 'class' Identifier [':' Expression] '{' {ClassMember} '}'
ClassMember:
SimpleFunctionDeclaration
Identifier ['=' Expression] ';'
'this' '(' Parameters ')' BlockStatement |
Notice "Identifier ['=' Expression] ';'". Semantically, this is neither an assignment nor a variable declaration, it simply adds a field to the class. Semantically it's equivalent to "Test.mX = 0;" (which further degrades to "Test["mX"] = 0"), an indexed assignment.
Furthermore, when you're implicitly accessing mX in the function, it doesn't even necessarily mean "the mX defined in this class". It means "the mX that's found in 'this' or in the global namespace." For that matter, right after your class declaration, you could write "removeKey(fieldsOf(Test), "mX");" -- suddenly, there's no more mX field in Test, and the reference to mX in foo() will probably refer to a global instead.
The same ideas apply to tables as well, with their named fields (i.e. "{x = 5}"). |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|