Mini Java编译器(三)——属性翻译文法

发表于:2007-07-04来源:作者:点击数: 标签:
三、属性翻译文法 变量声明(declaration) VarDeclaration ::= Type↑var_type,var_sizeIdetifier↑id_name @varDeclaration↓var_type,var_size,id_name @varAllocation↓var_size Type ↑var_type,var_size ::= ArrayType↑var_type,var_size |BooleanType
三、属性翻译文法
变量声明(declaration)
<VarDeclaration> ::= <Type>↑var_type,var_size<Idetifier>↑id_name

@varDeclaration↓var_type,var_size,id_name

@varAllocation↓var_size

<Type> ↑var_type,var_size ::= <ArrayType>↑var_type,var_size

|<BooleanType>↑var_type,var_size

|<IntegerType>↑var_type,var_size

|<Identifier>↑var_type,var_size



变量赋值(assignment)
<AssignmentStatement> ::= <Identifier>↑id_name,id_type

“=”

<Expression>↑exp_type,exp_value

“;”

@checkType↓id_type,exp_type

@insertIntoTable↓id_name,id_type.exp_value

<Expression>↑exp_type,exp_value ::= <AndExpression>↑exp_type,exp_value

|<CompareExpression>↑exp_type,exp_value

|<PlusExpression>↑exp_type,exp_value

|<MinusExpression>↑exp_type,exp_value

|<TimesExpression>↑exp_type,exp_value

|<ArrayLookup>↑exp_type,exp_value

|<ArrayLength>↑exp_type,exp_value

|<MessageSend>↑exp_type,exp_value

|<PrimaryExpression>↑exp_type,exp_value

<PrimaryExpression>↑exp_type,exp_value ::= <IntegerLiteral>↑exp_type,exp_value

|<TrueLiteral>↑exp_type,exp_value

|<FalseLiteral>↑exp_type,exp_value

|<Identifier>↑exp_type,exp_value

|<Expression>↑exp_type,exp_value

|<ArrayAllocationExpression>↑exp_type,exp_value

|<AllocationExpression>↑exp_type,exp_value

|<NotExpression>↑exp_type,exp_value

|<BracketExpression>↑exp_type,exp_value


(待续)


原文转自:http://www.ltesting.net