Ejecución
Antes de ejecutar el compilador, se cambia el fichero intput.txt para probar la etapa de comprobación de tipos:
DATA
float f;
int i;
CODE
i = 2.0; // Error
f = 2; // Error
print 1 + 2.5; // Error
2 = i; // Error (but not a type error)
Ahora, si se ejecuta el compilador, debería notificar los siguientes errores:
bash
Compiler starts...
Error in Type Checking: [6:2] The expression types don't match
Error in Type Checking: [7:2] The expression types don't match
Error in Type Checking: [9:8] The expression types don't match
Error in Type Checking: [10:2] The expression on the left is not modifiable
4 errors detected.
Se pueden observar los cambios realizados en el AST abriendo el fichero AST.html.
Program =
| varDefinitions List<VarDefinition> =
| . 0: VarDefinition = . . . . . . . . . . [2:11 2:12] float f;
| . | type FloatType = . . . . . . . . . .[null null]
| . | name = "f" string
| . 1: VarDefinition = . . . . . . . . . . [3:6 3:7] int i;
| . | type IntType = . . . . . . . . . . .[null null]
| . | name = "i" string
| statements List<Statement> =
| . 0: Assignment = . . . . . . . . . . . .[6:2 6:9] i = 2.0;
| . | left Variable = . . . . . . . . . . [6:2 6:3] i = 2.0;
| . | . name = "i" string
| . | . varDefinition = VarDefinition{ type=IntType{} name=i}
| . | . type = IntType{} Type
| . | . lvalue = true boolean
| . | right FloatLiteral = . . . . . . . .[6:6 6:9] i = 2.0;
| . | . floatValue = 2.0 float
| . | . type = FloatType{} Type
| . | . lvalue = false boolean
| . 1: Assignment = . . . . . . . . . . . .[7:2 7:7] f = 2;
| . | left Variable = . . . . . . . . . . [7:2 7:3] f = 2;
| . | . name = "f" string
| . | . varDefinition = VarDefinition{ type=FloatType{} name=f}
| . | . type = FloatType{} Type
| . | . lvalue = true boolean
| . | right IntLiteral = . . . . . . . . .[7:6 7:7] f = 2;
| . | . intValue = 2 int
| . | . type = IntType{} Type
| . | . lvalue = false boolean
| . 2: Print = . . . . . . . . . . . . . . [9:8 9:15] print 1 + 2.5;
| . | expression Arithmetic = . . . . . . [9:8 9:15] print 1 + 2.5;
| . | . left IntLiteral = . . . . . . . .[9:8 9:9] print 1 + 2.5;
| . | . | intValue = 1 int
| . | . | type = IntType{} Type
| . | . | lvalue = false boolean
| . | . operator = "+" string
| . | . right FloatLiteral = . . . . . . [9:12 9:15] print 1 + 2.5;
| . | . | floatValue = 2.5 float
| . | . | type = FloatType{} Type
| . | . | lvalue = false boolean
| . | . type = IntType{} Type
| . | . lvalue = false boolean
| . 3: Assignment = . . . . . . . . . . . .[10:2 10:7] 2 = i;
| . | left IntLiteral = . . . . . . . . . [10:2 10:3] 2 = i;
| . | . intValue = 2 int
| . | . type = IntType{} Type
| . | . lvalue = false boolean
| . | right Variable = . . . . . . . . . .[10:6 10:7] 2 = i;
| . | . name = "i" string
| . | . varDefinition = VarDefinition{ type=IntType{} name=i}
| . | . type = IntType{} Type
| . | . lvalue = true boolean
En el html anterior se puede ver, en color granate, el valor que han tomado los atributos type y lvalue en cada nodo expresión.