Decl -> Type Descs ( Descs.type = Type)
Descs -> Desc ( Desc.type = Descs.type)
Descs -> Desc , Descs' ( Desc.type = Descs.type Descs'.type = Descs.type)
Desc -> Id ( Id.type = Desc.type [ERROR]{ Id.name exists } )
Desc -> Id = Expr ( Id.type = Desc.type Id.val = Expr.val [ERROR]{ Id.type != Expr.type Id.name exists } )
Expr -> Factor ( Expr.val = Factor.val Expr.type = Factor.type)
Expr -> Expr' BinOp(+ - * /) Expr'' ( Expr.val = BinOp(Expr'.val, Expr''.val) Expr.type=Expr'.type [ERROR]{ Expr'.type != Expr''.type } )
Expr -> Expr' BinOp(> < >= <= ==) Expr'' ( Expr.val = BinOp(Expr'.val, Expr''.val) Expr.type = BOOL [ERROR]{ Expr'.type != Expr''.type } )
Factor -> Decimal_Number ( Factor.type = INT Factor.val = Number.val)
Factor -> Float_Number ( Factor.type = FLOAT Factor.val = Number.val)
Factor -> Id ( Factor.type = Id.type Factor.val = Id.val [ERROR]{ Id.name doesn't exist } )
Factor -> Id SingOp(++ --) ( Factor.val = Id.val Id.val=SingOp(Id.val) [ERROR]{ Id.type == BOOL Id.name doesn't exist } )
Factor -> SingOp(++ --) Id ( Id.val=SingOp(Id.val) Factor.val = Id.val [ERROR]{ Id.type == BOOL Id.name doesn't exist } )
Factor -> TF ( Factor.type = BOOL Factor.val = TF.val)
Factor -> (Expr) ( Factor.type = Expr.type Factor.val = Expr.val)
Asig_E -> Id = Expr ( Id.val = Expr.val [ERROR]{ Id.type != Expr.type Id.name doesn't exist } )
IF -> if ( Expr ) Block ( [ERROR]{ Expr.type == Empty } )
ELSE -> else if ( Expr ) Block ( [ERROR]{ Expr.type == Empty } )
WHILE -> while ( Expr ) Block ( [ERROR]{ Expr.type == Empty } )
FunDef -> Type FunName ( ParasDef ) Block ( FunDef.return_type = Type FunDef.parameters = ParasDef.paramters [ERROR]{ FunaName exists } )
ParasDef -> ParaDef ( ParasDef.parameters.add(ParaDef.paramter) )
ParasDef -> ParaDef , ParasDef' ( ParasDef.parameters.add(ParaDef.parameter) ParasDef.parameters.add(ParasDef'.parameters) )
ParasDef -> Empty ( ParaDef.paramater = Empty )
ParaDef -> Type Id ( ParaDef.parameter.name = Id.name ParaDef.parameter.type = Type )
// global variables : a, x
int a = 11+99;
float x = 1.19;
int main(){
// you can still create the variable 'a' in another scope(MAIN)
int a = 9900;
if(true){
// variable 'a' in the new scope(IF)
int a = 9991;
}
}
// step into another scope
if(true){
// declare variable b, assign it as the result of RHS(based on precedence of different operators)
int b = a-10000+(98*2+1);
}
// bool calculation
bool h = 1<(2*3+4+a);
// '--a' makes a = 9900 - 1 = 9989, but in calculation of 't' serves as 9990(new value)
int t = --a;
// define function without parameters
void g(){
int x= 1;
}
//define function with two parameters
int f(int a, int b){
int t = a*b;
return t+a+b;
}
int a = 9900;
//error : redefinition of variable 'a'
int a = 0;
// error : cannot assign variable 'i'(int) as float
int i = 1.11;
//error : variable 'c' is not defined
c = a;
//error : calculation between 'bool' and 'int' is illegal
h = 1+true;
// error : redefinition of function 'f'
int f(){
return 0;
}
// define function without parameters
void g(){
int x= 1;
}
//define function with two parameters
int f(int a, int b){
int t = a*b;
return t+a+b;
}
// error : redefinition of function 'f'
int f(){
return 0;
}
// global variables : a, x
int a = 11+99;
float x = 1.19;
int main(){
// you can still create the variable 'a' in another scope
int a = 9900;
//error : redefinition of variable 'a'
int a = 0;
// error : cannot assign variable 'a'(int) as float
a = 1.11;
// 'x--' makes x = 1.19 - 1 = 0.19, but in calculation of 'y' serves as 1.19(old value)
float y = (x--)+11.9;
// step into another scope
if(true){
// declare variable b, assign it as the result of RHS(based on precedence of different operators)
int b = a-10000+(98*2+1);
}
// bool calculation
bool h = 1<(2*3+4+a);
//error : calculation between 'bool' and 'int' is illegal
h = 1+true;
// '--a' makes a = 9900 - 1 = 9989, but in calculation of 't' serves as 9990(new value)
int t = --a;
//error : variable 'c' is not defined
c = a;
}