⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 grammar

📁 PL/0源码
💻
📖 第 1 页 / 共 2 页
字号:
                                dynamic_cast<st_declaration_t *>(lhs->node);                            decl->set_tail(lhs->node);                        }                        else {                          st_declaration_t *decl =                              dynamic_cast<st_declaration_t *>(lhs->node);                          st_declaration_t *next =                              dynamic_cast<st_declaration_t *>(rhs[3].node);                          decl->set_tail(next->tail());                        }                    ]]more_equates    ::= , equate_list                    [[                        *lhs = rhs[1];                    ]]                ::= [[                        lhs->node = NULL;                    ]]var_part_opt    ::= VAR ident_list ;                    [[                        *lhs = rhs[1];                    ]]                ::= [[                        lhs->node = NULL;                    ]]ident_list      ::= IDENT more_idents                    [[                        lhs->node = new st_variable_t(                            rhs[0].token.get_location(),                            new st_identifier_t(rhs[0].token), rhs[1].node);                        // set tail of list                        if (rhs[1].node == NULL) {                            st_declaration_t *decl =                                dynamic_cast<st_declaration_t *>(lhs->node);                            decl->set_tail(lhs->node);                        }                        else {                            st_declaration_t *decl =                                dynamic_cast<st_declaration_t *>(lhs->node);                            st_declaration_t *next =                                dynamic_cast<st_declaration_t *>(rhs[1].node);                            decl->set_tail(next->tail());                        }                    ]]more_idents     ::= , ident_list                    [[                        *lhs = rhs[1];                    ]]                ::= [[                        lhs->node = NULL;                    ]]proc_part_opt   ::= PROCEDURE IDENT ; block ; proc_part_opt                    [[                        if (rhs[3].node == NULL) {                            rhs[3].node = new st_block_t(                                rhs[4].token.get_location(), NULL, NULL);                        }                        lhs->node = new st_procedure_t(                            rhs[0].token.get_location(),                            new st_identifier_t(rhs[1].token),                            dynamic_cast<st_block_t *>(rhs[3].node),                            rhs[5].node);                    ]]                ::= [[                        lhs->node = NULL;                    ]]statement       ::= IDENT := expression                    [[                        lhs->node = new st_assignment_t(                            rhs[0].token.get_location(),                            new st_identifier_t(rhs[0].token),                            rhs[2].node, NULL);                    ]]                ::= CALL IDENT                    [[                        lhs->node = new st_call_t(rhs[0].token.get_location(),                            new st_identifier_t(rhs[1].token), NULL);                    ]]                ::= BEGIN stmt_list END                    [[                        *lhs = rhs[1];                    ]]                ::= IF condition THEN statement                    [[                        lhs->node = new st_if_t(rhs[0].token.get_location(),                            rhs[1].node, rhs[3].node, NULL);                    ]]                ::= WHILE condition DO statement                    [[                        lhs->node = new st_while_t(rhs[0].token.get_location(),                            rhs[1].node, rhs[3].node, NULL);                    ]]                ::= [[                        lhs->node = NULL;                    ]]expression      ::= sign_opt term                    [[                        if (rhs[0].node != NULL)                            rhs[2].node = new st_unary_op_t(                                rhs[0].node->get_location(),                                dynamic_cast<st_token_t *>(rhs[0].node),                                rhs[1].node);                        else                            rhs[2] = rhs[1];                    ]]                    more_terms                    [[                        *lhs = rhs[2];                    ]]sign_opt        ::= +    -- NB: + is a token class that includes both '+' and '-'                    [[                        if (rhs[0].token.minor == MIN_MINUS)                            lhs->node = new st_token_t(rhs[0].token);                        else                            lhs->node = NULL;                    ]]                ::= [[                        lhs->node = NULL;                    ]]term            ::= factor                    [[                        rhs[1] = rhs[0];                    ]]                    more_factors                    [[                        *lhs = rhs[1];                    ]]factor          ::= IDENT                    [[                        lhs->node = new st_identifier_t(rhs[0].token);                    ]]                ::= NUMBER                    [[                        lhs->node = new st_number_t(rhs[0].token);                    ]]                ::= ( expression )                    [[                        *lhs = rhs[1];                    ]]more_factors    ::= * factor    -- NB: * is a token class that includes both '*' and '/'                    [[                        rhs[2].node = new st_binary_op_t(                            lhs->node->get_location(),                            new st_token_t(rhs[0].token),                            lhs->node, rhs[1].node);                    ]]                    more_factors                    [[                        *lhs = rhs[2];                    ]]                ::=more_terms      ::= + term    -- NB: + is a token class that includes both '+' and '-'                    [[                        rhs[2].node = new st_binary_op_t(                            lhs->node->get_location(),                            new st_token_t(rhs[0].token),                            lhs->node, rhs[1].node);                    ]]                    more_terms                    [[                        *lhs = rhs[2];                    ]]                ::=stmt_list       ::= statement more_stmts                    [[                        // either, neither, or both of the rhs nodes could                        // be empty; either, neither, or both could be a                        // *list* of statements (e.g. from a begin..end)                        if (rhs[0].node == NULL)                            *lhs = rhs[1];                        else if (rhs[1].node == NULL)                            *lhs = rhs[0];                        else {                            st_statement_t *stmt =                                dynamic_cast<st_statement_t *>(rhs[0].node);                            while (stmt->next() != NULL)                                stmt = stmt->next();                            stmt->set_next(rhs[1].node);                            *lhs = rhs[0];                        }                    ]]more_stmts      ::= ; stmt_list                    [[                        *lhs = rhs[1];                    ]]                ::= [[                        lhs->node = NULL;                    ]]condition       ::= ODD expression                    [[                        lhs->node = new st_unary_op_t(                            rhs[0].token.get_location(),                            new st_token_t(rhs[0].token), rhs[1].node);                    ]]                ::= expression relation expression                    [[                        lhs->node = new st_binary_op_t(                            rhs[0].node->get_location(),                            dynamic_cast<st_token_t *>(rhs[1].node),                            rhs[0].node, rhs[2].node);                    ]]relation        ::= =                    [[                        lhs->node = new st_token_t(rhs[0].token);                    ]]                ::= >    -- NB: > is a token class that includes NE, LT, GT, LE, and GE    -- '=' is in a separate class because of its role in const declarations                    [[                        lhs->node = new st_token_t(rhs[0].token);                    ]]

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -