C Statement

Here the statement grammar:

        /*
            Comment works as in C/C++
        */

        single_statement = [
            [compound_statement
            | labeled_statement
            | expression_statement
            ]:>_
        ]

        compound_statement = [
            [
            '{'
                __scope__:current_block
                #new_blockstmt(_, current_block)
                [
                    line_of_code
                ]*
            '}'
            ]
        ]

        line_of_code = [
            single_statement:line
            #end_loc(current_block, line)
        ]

        labeled_statement = [
            Expression.rootidentifier:ident
            [ #check_stmt(ident, "if") if_statement:>_
            | #check_stmt(ident, "for") for_statement:>_
            | #check_stmt(ident, "while") while_statement:>_
            | #check_stmt(ident, "switch") switch_statement:>_
            | #check_stmt(ident, "do") do_statement:>_
            | #check_stmt(ident, "return") return_statement:>_
            | #check_stmt(ident, "goto") goto_statement:>_
            | #check_stmt(ident, "case") case_statement:>_
            | #check_stmt(ident, "break") ';' #new_break(_)
            | #check_stmt(ident, "continue") ';' #new_continue(_)
            | ':' #new_label(_, ident)
            ]
        ]

        if_statement = [
            '(' expression:cond ')'
            single_statement:then
            __scope__:else
            [
                "else"
                single_statement:>else
            ]?
            #new_if(_, cond, then, else)
        ]

        for_statement = [
            '('
                expression_statement:init
                expression_statement:cond
                expression?:inc
            ')'
            single_statement:body
            #new_for(_, init, cond, inc, body)
        ]

        while_statement = [
            '('
                expression:cond
            ')'
            single_statement:body
            #new_while(_, cond, body)
        ]

        switch_statement = [
            '(' expression:cond ')'
            single_statement:body
            #new_switch(_, cond, body)
        ]

        do_statement = [
            single_statement:body
            "while" '(' expression:cond ')' ';'
            #new_do(_, cond, body)
        ]

        return_statement = [
            expression?:e ';'
            #new_return(_, e)
        ]

        goto_statement = [
            expression:e ';'
            #new_goto(_, e)
        ]

        range_expression = [
            constant_expression:>_
            [
                "..."
                constant_expression:r
                #new_range(_, r)
            ]?
        ]

        case_statement = [
            range_expression:e #new_case(_, e)
            ':'
        ]

        expression_statement = [
            [expression:e #new_expr(_, e)]?
            ';'
        ]
class cnorm.parsing.statement.Statement(content: str='', stream_name: str=None, raise_diagnostic=True)[source]

Bases: pyrser.grammar.Grammar

interaction with other CNORM PART:

Declaration.init_declarator -> compound_statement Expression.primary_expression -> block_item_list

entry = 'single_statement'
check_stmt(self, ident: Node, val: str) → bool
end_loc(self, current_block, line)
new_blockstmt(self, ast, current_block)
new_break(self, ast)
new_case(self, ast, expr)
new_continue(self, ast)
new_do(self, ast, cond, body)
new_expr(self, ast, expr)
new_for(self, ast, init, cond, inc, body)
new_goto(self, ast, expr)
new_if(self, ast, cond_expr, then_expr, else_expr)
new_label(self, ast, ident)
new_range(self, ast, expr)
new_return(self, ast, expr)
new_switch(self, ast, cond, body)
new_while(self, ast, cond, body)
cnorm.parsing.statement.new_expr(self, ast, expr)[source]
cnorm.parsing.statement.new_if(self, ast, cond_expr, then_expr, else_expr)[source]
cnorm.parsing.statement.new_for(self, ast, init, cond, inc, body)[source]
cnorm.parsing.statement.new_while(self, ast, cond, body)[source]
cnorm.parsing.statement.new_switch(self, ast, cond, body)[source]
cnorm.parsing.statement.new_do(self, ast, cond, body)[source]
cnorm.parsing.statement.new_return(self, ast, expr)[source]
cnorm.parsing.statement.new_goto(self, ast, expr)[source]
cnorm.parsing.statement.new_range(self, ast, expr)[source]
cnorm.parsing.statement.new_case(self, ast, expr)[source]
cnorm.parsing.statement.new_break(self, ast)[source]
cnorm.parsing.statement.new_continue(self, ast)[source]
cnorm.parsing.statement.new_label(self, ast, ident)[source]
cnorm.parsing.statement.new_blockstmt(self, ast, current_block)[source]
cnorm.parsing.statement.end_loc(self, current_block, line)[source]
cnorm.parsing.statement.check_stmt(self, ident: Node, val: str) → bool[source]