[Nice-commit] Nice/src/bossa/parser Parser.jj,1.158,1.159
Brought to you by:
bonniot
|
From: <ar...@us...> - 2003-04-28 23:28:49
|
Update of /cvsroot/nice/Nice/src/bossa/parser
In directory sc8-pr-cvs1:/tmp/cvs-serv17425/F:/nice/src/bossa/parser
Modified Files:
Parser.jj
Log Message:
Changed to syntax of localdeclaration to:
Type() Name() [ "=" expression() ] ";"
( "var" | "let") [ Type() ] Name() [ "=" expression() ] ";"
Give warnings when using "final" or "const" also warning by "const"
"var" without a typing doesn't work yet because it isn't implemented
"let" without a default value is broken see the testcases.
Index: Parser.jj
===================================================================
RCS file: /cvsroot/nice/Nice/src/bossa/parser/Parser.jj,v
retrieving revision 1.158
retrieving revision 1.159
diff -C2 -d -r1.158 -r1.159
*** Parser.jj 28 Apr 2003 20:57:53 -0000 1.158
--- Parser.jj 28 Apr 2003 23:28:46 -0000 1.159
***************
*** 191,194 ****
--- 191,195 ----
| < RETURN: "return" >
| < VARIABLE: "var" > /* Nice specific */
+ | < LET: "let" > /* Nice specific */
// modifiers
***************
*** 974,977 ****
--- 975,979 ----
boolean isFinal=false, isTransient = false, isVolatile = false;
Expression value = null;
+ Token t = null;
}
{
***************
*** 980,984 ****
| "private-write"
| ( ("public" | "private" | {} )
! [ ( "final" | "const" ) { isFinal=true; } ]
)
)
--- 982,992 ----
| "private-write"
| ( ("public" | "private" | {} )
! [ ( "final" | t="const" )
! { isFinal=true;
! if (t!=null)
! User.warning(new Location(t),
! "'const' is deprecated use 'final' instead.");
! }
! ]
)
)
***************
*** 2330,2340 ****
{
(
! LOOKAHEAD( "final" | "const" | monotype() <IDENT>)
! (
! LOOKAHEAD( ( "final" | "const" ) <IDENT> "=" )
! res = LocalConstant()
! |
res = LocalDeclaration()
- )
|
// There are two cases for tuples (declaring a variable or not).
--- 2338,2343 ----
{
(
! LOOKAHEAD( "final" | "const" | "var" | "let" | monotype() <IDENT>)
res = LocalDeclaration()
|
// There are two cases for tuples (declaring a variable or not).
***************
*** 2359,2402 ****
Statement LocalDeclaration() :
{
! Monotype t = null;
LocatedString id;
FormalParameters parameters;
Statement body;
Expression e=null;
! boolean constant = false;
}
{
! [ ( "final" | "const" ) { constant = true; } ]
! t = monotype()
! id=ident()
! (
! "(" parameters = formalParameters(false) ")" body = code()
! { return Block.LocalFunction.make(id, t, parameters, body); }
! |
! [ "=" e=Expression() ]
! { Block.LocalVariable res = new Block.LocalVariable(id,t,constant,e); }
! ( "," id=ident() {e=null;} [ "=" e=Expression() ] { res.addNext(id,e); } )*
";"
{ return res; }
)
- }
-
- Statement LocalConstant() :
- {
- LocatedString id;
- FormalParameters parameters;
- Statement body;
- Expression e=null;
- boolean constant = false;
- }
- {
- ( "final" | "const" )
- id=ident()
- "="
- e=Expression()
- { Block.LocalConstant res = new Block.LocalConstant(id,e); }
- ( "," id=ident() "=" e=Expression() { res.addNext(id,e); } )*
- ";"
- { return res; }
}
--- 2362,2415 ----
Statement LocalDeclaration() :
{
! Monotype type = null;
LocatedString id;
FormalParameters parameters;
Statement body;
Expression e=null;
! boolean constant = true;
! Token t = null;
}
{
! ( LOOKAHEAD( [ ("final"|"const"|"let"|"var") ] monotype() ident() )
! (
! (t="final" | t="const")
! {User.warning(new Location(t),
! "'"+t.toString()+"' is deprecated use 'let' instead.");
! }
! | "let"
! | "var" {constant = false;}
! | {constant = false;}
! )
! type = monotype()
! id=ident()
! (
! "(" parameters=formalParameters(false) ")" body=code()
! { return Block.LocalFunction.make(id, type, parameters, body); }
! |
! [ "=" e=Expression() ]
! { Block.LocalVariable res = new Block.LocalVariable(id,type,constant,e); }
! ( "," id=ident() {e=null;} [ "=" e=Expression() ] { res.addNext(id,e); } )*
! ";"
! { return res; }
! )
! |
! (
! (t="final" | t="const")
! {User.warning(new Location(t),
! "'"+t.toString()+"' is deprecated use 'let' instead.");
! }
! | "let"
! | t="var" {constant = false;}
! )
! id=ident()
! [ "=" e=Expression() ]
! { Block.LocalConstant res;
! if (constant) {res = new Block.LocalConstant(id,e);}
! else {throw new UserError(new Location(t), "'var' without type not implemented yet");}
! }
! ( "," id=ident() "=" e=Expression() { res.addNext(id,e); } )*
";"
{ return res; }
)
}
|