Skip to content

Comprobación de Tipos

Especificación de la etapa de comprobación de tipos (perteneciente a la fase de análisis semántico) utilizando como metalenguaje una gramática atribuida:

Attributes

SymbolAtribute NameJava TypeSyn/InhDescription
expressiontypeTypeSynthetizedType of the expression
expressionlvaluebooleanSynthetizedTrue if the expression can appear to the left of an assignment

Auxiliary Functions

NameDescription
sameType(type_a, type_b)True if the params are equal

Rules

NodePredicatesFunctions
program → varDefinition* statement*
varDefinition → type name:string
intType:type → ε
floatType:type → ε
print:statement → expression
assignment:statement → left:expression right:expressionsameType(left.type, right.type)

left.lvalue == true
arithmetic:expression → left:expression operator:string right:expressionsameType(left.type, right.type)arithmetic.type = left.type
arithmetic.lvalue = false
variable:expression → name:stringvariable.type = variable.varDefinition.type

variable.lvalue = true
intLiteral:expression → intValue:intintLiteral.type = intType
intLiteral.lvalue = false
floatLiteral:expression → floatValue:floatfloatLiteral.type = floatType
floatLiteral.lvalue = false