MESSAGE
DATE | 2016-05-08 |
FROM | Ruben Safir
|
SUBJECT | Re: [Hangout-NYLXS] Your version of tYpEcheCkingvIsiTor is
|
On 05/08/2016 10:00 PM, Ruben Safir wrote:
> So for ConvertToIR.java
>
> So we have operators, like the + operator for instructions.
>
> So the NODE can have one of three types
> a string, in integer or a float. So I'm
> trying to do it like you did it which means I need to know
> if it is a string... so that is I think easy because the node
> remembers its type when you run the constructor
>
> /**
> * Run the converter on the parse tree after it has been type-checked.
> */
>
> public ConvertToIR(TypeChecker typeChecker) {
> this.typeChecker = typeChecker;
> this.typeChecker.getParseTree().accept(this);
> }
>
>
> So you used this, and I think that now wee have to all the types and
> accessory methods through typeChecker, which is a ctx.
>
> So now I think I can do this, but I'm not sure, because ConvertToIR
> inherits from the same base visitor as TypeChecker, but they are not the
> same object. The parsetrees are the same so I think I can do this
>
> 63 ¦ Type base_type = typeChecker.GetNodeType(ctx);
> 64 ¦ Type current_type = typeChecker.GetCoercion(ctx);
> 65 ¦ Address a;
>
>
>
> or more exactly
>
> 55 ¦-at-Override
> 56 ¦public Address visitOpExpr(CalcLangParser.OpExprContext ctx) {
> 57 ¦ ¦ // ASSUME this represents addition.
> 58 ¦ ¦ // ASSUME these are integers
> 59
> 60 ¦ String op = ctx.op.getText();
> 61 ¦ ¦ Address left = ctx.left.accept(this);
> 62 ¦ ¦ Address right = ctx.right.accept(this);
> 63 ¦ Type base_type = typeChecker.GetNodeType(ctx);
> 64 ¦ Type current_type = typeChecker.GetCoercion(ctx);
> 65 ¦ Address a;
> 66
> 67 ¦ if(current_type == null ){
> 68 ¦ current_type = base_type;
> 69 ¦ }
>
>
>
>
> If not, saving the Type values in TypChecker is fabulously useless.
>
> __But that is not what really is confusing me :) (Lights Camera, Strum
> Alice's Restaurant and Hum)__
>
> Your version of TypeChecker has the following code and I'm trying to
> follow this code syntax for ConvertToIR
>
> -at-Override
> public Type visitOpExpr(CalcLangParser.OpExprContext ctx) {
> Type leftType = ctx.left.accept(this);
> Type rightType = ctx.right.accept(this);
> // OpExpr is used for arithmetic, relational, equality, logical
> String op = ctx.op.getText();
> switch(op)
> {
> case "^":case "*":case "/":case "+":case "-": // arithmetic
> {
> if(leftType == Type.STRING && rightType == Type.STRING
> && op.equals("+"))
> {
> return trace(ctx, Type.STRING);
> }
> if (!leftType.isNumeric()) {
> return typeMismatch(ctx, leftType, Type.FLOAT);
> }
> if (!rightType.isNumeric()) {
> return typeMismatch(ctx, rightType, Type.FLOAT);
> }
> Type resultType = unify(ctx.left, leftType, ctx.right,
> rightType);
> return trace(ctx, resultType);
> }
>
>
> Type.isNumeric is defined (really do we have enough files and classes
> here) in Class Type.java
>
>
> public boolean isNumeric() {
> return leastUpperBound(FLOAT) == FLOAT;
> }
> }
>
> UGGGG
>
> Good thing ctags is now working:
>
> /**
> * The types form a hierarchy, with ERROR at the root.
> * -at-return The least upper bound of this and that.
> */
> public Type leastUpperBound(Type that) {
> if(this == that)
> return this;
> if((this == INT && that == FLOAT)
> ||(this == FLOAT && that == INT))
> return FLOAT;
> return ERROR;
> }
>
> SO WHAT'S HAPPENING? isNumeric() is calling leastUpperBound with FLOAT.
> Is this a type? This is a reference to an instance of a class. What
> class? It depends if it is inherited or not. Worse this is an enum and
> not even a standard class. Can you guarantee "this" will be a Type or a
> the enum values?
>
> This is more than an hour to take this apart.
>
> in ConvertToIR, I need to make Address and Instruction
> I need to know if the node is an INT or a FLOAT and then
> convert it to and Instruction. I need to know if that node
> Type is a Float or an Int ... different instructions.
>
>
>
FWIW - from usenet
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
On 5/7/2016 11:58 PM, ruben safir wrote:
> How is there no closing paran and a method included as an enum entry?
>
> what is this syntax ?
There's a good explanation at
http://docs.oracle.com/javase/tutorial/java/javaOO/enum.html
Read it, then post again if you still have questions.
--
So many immigrant groups have swept through our town
that Brooklyn, like Atlantis, reaches mythological
proportions in the mind of the world - RI Safir 1998
http://www.mrbrklyn.com
DRM is THEFT - We are the STAKEHOLDERS - RI Safir 2002
http://www.nylxs.com - Leadership Development in Free Software
http://www2.mrbrklyn.com/resources - Unpublished Archive
http://www.coinhangout.com - coins!
http://www.brooklyn-living.com
Being so tracked is for FARM ANIMALS and and extermination camps,
but incompatible with living as a free human being. -RI Safir 2013
_______________________________________________
hangout mailing list
hangout-at-nylxs.com
http://www.nylxs.com/
|
|