[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: treecc/examples expr_ruby.tc,1.1,1.2
From: |
Peter Minten <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: treecc/examples expr_ruby.tc,1.1,1.2 |
Date: |
Sat, 09 Nov 2002 06:36:28 -0500 |
Update of /cvsroot/dotgnu-pnet/treecc/examples
In directory subversions:/tmp/cvs-serv18088/examples
Modified Files:
expr_ruby.tc
Log Message:
Worked on Ruby support.
Index: expr_ruby.tc
===================================================================
RCS file: /cvsroot/dotgnu-pnet/treecc/examples/expr_ruby.tc,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -r1.1 -r1.2
*** expr_ruby.tc 2 Nov 2002 04:38:21 -0000 1.1
--- expr_ruby.tc 9 Nov 2002 11:36:26 -0000 1.2
***************
*** 31,36 ****
class Eval_value
! int_value = 0;
! float_value = 0;
end
--- 31,36 ----
class Eval_value
! Int_value = 0
! Float_value = 0
end
***************
*** 44,50 ****
%enum Type_code =
{
! error_type,
! int_type,
! float_type
}
--- 44,50 ----
%enum Type_code =
{
! Error_type,
! Int_type,
! Float_type
}
***************
*** 54,69 ****
%node Expression %abstract %typedef =
{
! %nocreate Type_code type = {Type_code.error_type};
}
%node Binary Expression %abstract =
{
! expression expr1;
! expression expr2;
}
%node Unary Expression %abstract =
{
! expression expr;
}
--- 54,69 ----
%node Expression %abstract %typedef =
{
! %nocreate Type_code type = {Type_code::Error_type};
}
%node Binary Expression %abstract =
{
! Expression expr1;
! Expression expr2;
}
%node Unary Expression %abstract =
{
! Expression expr;
}
***************
*** 79,172 ****
%node Plus Binary
! /*%node Minus Binary
%node Multiply Binary
%node Divide Binary
%node Power Binary
! %node Negate Unary*/
! /*
! %node cast expression =
{
Type_code new_type;
! expr = expression.new;
}
! */
/*
* Define the "infer_type" operation as a non-virtual.
*/
! /*%operation void InferType::infer_type(expression e)
! infer_type(binary)
{
! infer_type(e.expr1)
! infer_type(e.expr2)
! if(e.expr1.type == Type_code.error_type ||
! e.expr2.type == Type_code.error_type)
! {
! e.type = Type_code.error_type
! }
! else if(e.expr1.type == Type_code.float_type ||
! e.expr2.type == Type_code.float_type)
! {
! e.type = Type_code.float_type
! }
! else
! {
! e.type = Type_code.int_type
! }
}
! infer_type(unary)
{
! infer_type(e.expr)
! e.type = e.expr.type
}
! infer_type(intnum)
{
! e.type = Type_code.int_type
}
! infer_type(floatnum)
{
! e.type = Type_code.float_type
}
! infer_type(power)
{
! infer_type(e.expr1)
! infer_type(e.expr2)
! if(e.expr1.type == Type_code.error_type ||
! e.expr2.type == Type_code.error_type)
! {
! e.type = Type_code.error_type
! }
! else if(e.expr2.type != Type_code.int_type)
! {
! Console.Error.WriteLine(e.getFilename() + ":" + e.getLinenum() +
! ": second argument to `^' is
not an integer")
! e.type = Type_code.error_type
! }
! else
! {
! e.type = e.expr1.type
! }
}
! infer_type(cast)
{
! infer_type(e.expr)
! if(e.expr.type != Type_code.error_type)
! {
! e.type = e.new_type
! }
! else
! {
! e.type = Type_code.error_type
! }
}
! */
/*
* Define the "eval_expr" operation as a virtual.
--- 79,155 ----
%node Plus Binary
! %node Minus Binary
%node Multiply Binary
%node Divide Binary
%node Power Binary
! %node Negate Unary
!
! %node Cast Expression =
{
Type_code new_type;
! Expression expr;
}
!
/*
* Define the "infer_type" operation as a non-virtual.
*/
! %operation void InferType::infer_type(Expression e)
! infer_type(Binary)
{
! infer_type(e.expr1)
! infer_type(e.expr2)
! if (e.expr1.type == Type_code::Error_type || e.expr2.type ==
Type_code::Error_type) then
! e.type = Type_code::Error_type
! elsif (e.expr1.type == Type_code::Float_type || e.expr2.type ==
Type_code::Float_type) then
! e.type = Type_code::Float_type
! else
! e.type = Type_code::Int_type
! end
}
! infer_type(Unary)
{
! infer_type(e.expr)
! e.type = e.expr.type
}
! infer_type(Intnum)
{
! e.type = Type_code::Int_type
}
! infer_type(Floatnum)
{
! e.type = Type_code::Float_type
}
! infer_type(Power)
{
! infer_type(e.expr1)
! infer_type(e.expr2)
! if (e.expr1.type == Type_code::Error_type || e.expr2.type ==
Type_code::Error_type) then
! e.type = Type_code::Error_type
! elsif (e.expr2.type != Type_code::Int_type) then
! p (e.getFilename() + ":" + e.getLinenum() + ": second argument to `^' is
not an integer")
! e.type = Type_code::Error_type
! else
! e.type = e.expr1.type
! end
}
! infer_type(Cast)
{
! infer_type(e.expr)
! if(e.expr.type != Type_code::Error_type)
! e.type = e.new_type
! else
! e.type = Type_code::Error_type
! end
}
!
/*
* Define the "eval_expr" operation as a virtual.
***************
*** 176,344 ****
eval_expr(Plus)
{
! # Evaluate the sub-expressions
! eval_value value1 = expr1.eval_expr
! eval_value value2 = expr2.eval_expr
!
! # Coerce to the common type
! # Coerce.coerce(value1, expr1.type, type)
! # Coerce.coerce(value2, expr2.type, type)
!
! # Evaluate the operator
! if(type == Type_code.int_type)
! value1.int_value += value2.int_value
! else
! value1.float_value += value2.float_value
! end
! # Return the result to the caller
! return value1
}
- /*
- eval_expr(minus)
- {*/
- /* Evaluate the sub-expressions */
- /* eval_value value1 = expr1.eval_expr()
- eval_value value2 = expr2.eval_expr()
- */
- /* Coerce to the common type */
- /* Coerce.coerce(value1, expr1.type, type)
- Coerce.coerce(value2, expr2.type, type)
- */
- /* Evaluate the operator */
- /* if(type == Type_code.int_type)
- {
- value1.int_value -= value2.int_value
- }
- else
- {
- value1.float_value -= value2.float_value;
- }
- */
- /* Return the result to the caller */
- /* return value1
- }
-
- eval_expr(multiply)
- {*/
- /* Evaluate the sub-expressions */
- /* eval_value value1 = expr1.eval_expr()
- eval_value value2 = expr2.eval_expr()
- */
- /* Coerce to the common type */
- /* Coerce.coerce(value1, expr1.type, type)
- Coerce.coerce(value2, expr2.type, type)
- */
- /* Evaluate the operator */
- /* if(type == Type_code.int_type)
- {
- value1.int_value *= value2.int_value;
- }
- else
- {
- value1.float_value *= value2.float_value;
- }
- */
- /* Return the result to the caller */
- /* return value1;
- }
-
- eval_expr(divide)
- {
- */ /* Evaluate the sub-expressions */
- /* eval_value value1 = expr1.eval_expr();
- eval_value value2 = expr2.eval_expr();
- */
- /* Coerce to the common type */
- /* Coerce.coerce(value1, expr1.type, type);
- Coerce.coerce(value2, expr2.type, type);
- */
- /* Evaluate the operator */
- /* if(type == Type_code.int_type)
- {
- if(value2.int_value != 0)
- {
- value1.int_value /= value2.int_value;
- }
- else
- {
- Console.Error.WriteLine(getFilename() + ":" +
getLinenum() +
- ": division by
zero");
- value1.int_value = 0;
- }
- }
- else
- {
- value1.float_value /= value2.float_value;
- }
- */
- /* Return the result to the caller */
- /*return value1;
- }
-
- eval_expr(power)
- {*/
- /* Evaluate the sub-expressions */
- /* eval_value value1 = expr1.eval_expr();
- eval_value value2 = expr2.eval_expr();
- */
- /* Evaluate the operator */
- /* if(type == Type_code.int_type)
- {
- value1.int_value = (int)(Math.Pow((double)(value1.int_value),
- (double)(value2.int_value)));
- }
- else
- {
- value1.float_value =
(float)(Math.Pow((double)(value1.float_value),
-
(double)(value2.int_value)));
- }
-
- */ /* Return the result to the caller */
- /* return value1;
- }
-
- eval_expr(negate)
- {*/
- /* Evaluate the sub-expression */
- /*eval_value value = expr.eval_expr();
- */
- /* Evaluate the operator */
- /* if(type == Type_code.int_type)
- {
- value.int_value = -(value.int_value);
- }
- else
- {
- value.float_value = -(value.float_value);
- }
- */
- /* Return the result to the caller */
- /* return value;
- }
-
- eval_expr(cast)
- {*/
- /* Evaluate the sub-expression */
- /* eval_value value = expr.eval_expr();*/
! /* Cast to the final type */
! /* Coerce.coerce(value, expr.type, type);*/
! /* Return the result to the caller */
! /* return value;
}
! */
eval_expr(Intnum)
{
! value = eval_value.new
! value.int_value = num
! return value
}
eval_expr(Floatnum)
{
! value = eval_value.new
! value.float_value = num
! return value
}
--- 159,309 ----
eval_expr(Plus)
{
! # Evaluate the sub-Expressions
! eval_value value1 = expr1.eval_expr
! eval_value value2 = expr2.eval_expr
!
! # Coerce to the common type
! Coerce.coerce(value1, expr1.type, type)
! Coerce.coerce(value2, expr2.type, type)
!
! # Evaluate the operator
! if (type == Type_code::Int_type) then
! value1.Int_value += value2.Int_value
! else
! value1.Float_value += value2.Float_value
! end
! # Return the result to the caller
! return value1
}
! eval_expr(Minus)
! {
! # Evaluate the sub-Expressions
! eval_value value1 = expr1.eval_expr()
! eval_value value2 = expr2.eval_expr()
!
! # Coerce to the common type
! Coerce.coerce(value1, expr1.type, type)
! Coerce.coerce(value2, expr2.type, type)
! # Evaluate the operator
! if(type == Type_code::Int_type) then
! value1.Int_value -= value2.Int_value
! else
! value1.Float_value -= value2.Float_value;
! end
!
! # Return the result to the caller
! return value1
}
!
! eval_expr(Multiply)
! {
! # Evaluate the sub-Expressions
! eval_value value1 = expr1.eval_expr()
! eval_value value2 = expr2.eval_expr()
!
! # Coerce to the common type
! Coerce.coerce(value1, expr1.type, type)
! Coerce.coerce(value2, expr2.type, type)
!
! # Evaluate the operator
! if(type == Type_code::Int_type) then
! value1.Int_value *= value2.Int_value
! else
! value1.Float_value *= value2.Float_value;
! end
!
! # Return the result to the caller
! return value1
! }
!
! eval_expr(Divide)
! {
! # Evaluate the sub-Expressions
! eval_value value1 = expr1.eval_expr()
! eval_value value2 = expr2.eval_expr()
!
! # Coerce to the common type
! Coerce.coerce(value1, expr1.type, type)
! Coerce.coerce(value2, expr2.type, type)
!
! # Evaluate the operator
! if(type == Type_code::Int_type) then
! value1.Int_value -= value2.Int_value
! else
! value1.Float_value -= value2.Float_value;
! end
!
! # Return the result to the caller
! return value1
! }
!
! eval_expr(Power)
! {
! # Evaluate the sub-Expressions
! eval_value value1 = expr1.eval_expr()
! eval_value value2 = expr2.eval_expr()
!
! # Coerce to the common type
! Coerce.coerce(value1, expr1.type, type)
! Coerce.coerce(value2, expr2.type, type)
!
! # Evaluate the operator
! if(type == Type_code::Int_type) then
! value1.Int_value = value1.Int_value ^ value2.Int_value
! else
! value1.Float_value = value1.Float_value ^ value2.Float_value;
! end
!
! # Return the result to the caller
! return value1
! }
!
! eval_expr(Negate)
! {
! # Evaluate the sub-Expression
! eval_value value = expr.eval_expr()
!
! # Coerce to the common type
! Coerce.coerce(value1, expr1.type, type)
! Coerce.coerce(value, expr.type, type)
!
! # Evaluate the operator
! if(type == Type_code::Int_type) then
! value.Int_value = -1 * value.Int_value
! else
! value.Float_value = -1 * value.Float_value;
! end
!
! # Return the result to the caller
! return value
! }
!
! eval_expr(Cast)
! {
! # Evaluate the sub-Expression
! eval_value value = expr.eval_expr()
!
! # Coerce to the common type
! Coerce.coerce(value, expr.type, type)
!
! # Return the result to the caller
! return value
! }
!
eval_expr(Intnum)
{
! value = eval_value.new
! value.Int_value = num
! return value
}
eval_expr(Floatnum)
{
! value = eval_value.new
! value.Float_value = num
! return value
}
***************
*** 346,364 ****
* Define the "coerce" operation as an inline non-virtual.
*/
! /*%operation %inline void Coerce::coerce
(value, [Type_code from], [Type_code to])
! coerce(int_type, float_type)
{
! // value.float_value = (float)(value.int_value);
}
! coerce(float_type, int_type)
{
! // value.int_value = (int)(value.float_value);
}
coerce(Type_code, Type_code)
{
! /* Nothing to do here *//*
! }*/
--- 311,329 ----
* Define the "coerce" operation as an inline non-virtual.
*/
! %operation %inline void Coerce::coerce
(value, [Type_code from], [Type_code to])
! coerce(Int_type, Float_type)
{
! value.Float_value = value.Int_value.to_f;
}
! coerce(Float_type, Int_type)
{
! value.Int_value = value.Float_value.to_i;
}
coerce(Type_code, Type_code)
{
! # Nothing to do here
! }
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: treecc/examples expr_ruby.tc,1.1,1.2,
Peter Minten <address@hidden> <=
- Prev by Date:
[Dotgnu-pnet-commits] CVS: pnet/support dir.c,1.5,1.6
- Next by Date:
[Dotgnu-pnet-commits] CVS: treecc gen_ruby.c,1.1,1.2 stream.h,1.2,1.3 stream.c,1.2,1.3 ChangeLog,1.49,1.50
- Previous by thread:
[Dotgnu-pnet-commits] CVS: pnet/support dir.c,1.5,1.6
- Next by thread:
[Dotgnu-pnet-commits] CVS: treecc gen_ruby.c,1.1,1.2 stream.h,1.2,1.3 stream.c,1.2,1.3 ChangeLog,1.49,1.50
- Index(es):