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

类别:Java 点击:0 评论:0 推荐:
三、属性翻译文法 变量声明(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://com.8s8s.com/it/it11465.htm