Esempio n. 1
0
    def represent_py_output(self, presenter: CcScriptPresenter):
        if len(self.expr_list) == 1 and self.expr_list[0].element_type == 'fc':
            if self.expr_list[0].expr.l_expr.value_type.identifier == 'string':
                presenter.write_line(
                    f'presenter.write_line({self.expr_list[0].reference_py})')
                return

        expr_repr_list = []
        for expr in self.expr_list:
            expr_repr_list.append(f'CcObject.value_of({expr.reference_py})')
        presenter.write_line(
            f'presenter.write_line({", ".join(expr_repr_list)})')
Esempio n. 2
0
 def represent_py_output(self, presenter: CcScriptPresenter):
     if self.l_expr.l_expr.value_type.identifier == 'string':
         var_name = self.l_expr.l_expr.reference_py
         func_name = property_set_name(self.l_expr.indicator)
         argument = f'{{CcObject.value_of({self.r_expr.reference_py})}}'
         presenter.write_line(f'if {self.r_expr.reference_py}:')
         presenter.shift_indent(True)
         presenter.write_line(
             f'presenter.write_line({var_name}, f\'->{func_name}({argument});\')'
         )
         presenter.shift_indent(False)
     else:
         presenter.write_line(
             f'{self.l_expr.reference_py} = {self.r_expr.reference_py}')
Esempio n. 3
0
    def represent_py_output(self, presenter: CcScriptPresenter):
        if self.operator == '>':
            presenter.write_line('presenter.shift_indent(True)')
        elif self.operator == '<':
            presenter.write_line('presenter.shift_indent(False)')

        if self.operator == '$':
            if self.statement:
                self.statement.represent_py(presenter)
        else:
            if self.statement:
                self.statement.represent_py_output(presenter)
            else:
                presenter.write_line('presenter.write_line()')

        if self.operator == '>':
            presenter.write_line('presenter.shift_indent(False)')
        elif self.operator == '<':
            presenter.write_line('presenter.shift_indent(True)')
Esempio n. 4
0
    def represent_cc(self, presenter: CcScriptPresenter):
        presenter.write_line(f'while ({self.condition.reference_cc})')
        self.condition.represent_cc(presenter)

        presenter.shift_indent(True)
        self.statement.represent_cc(presenter)
        presenter.shift_indent(False)
Esempio n. 5
0
    def represent_py_output(self, presenter: CcScriptPresenter):
        presenter.write_line(f'while {self.condition.reference_py}:')
        self.condition.represent_py_output(presenter)

        presenter.shift_indent(True)
        self.statement.represent_py_output(presenter)
        presenter.shift_indent(False)
Esempio n. 6
0
    def represent_cc(self, presenter: CcScriptPresenter):
        presenter.write_line(
            f'for {self.var.reference_cc} in {self.iterable.reference_cc}')

        presenter.shift_indent(True)
        self.statement.represent_cc(presenter)
        presenter.shift_indent(False)
Esempio n. 7
0
 def represent_cc(self, presenter: CcScriptPresenter):
     presenter.write(f'{self.get_access_label()}:\n')
def generate_model_python(model_script):
    # model_file = sys.stdout
    model_file = open('cc_model/CcModel.py', 'w')
    model_presenter = CcScriptPresenter(model_file, '    ')
    model_script.represent_py(presenter=model_presenter)
    model_file.close()
Esempio n. 9
0
 def represent_cc(self, presenter: CcScriptPresenter):
     presenter.write_line(';')
Esempio n. 10
0
 def represent_py(self, presenter: CcScriptPresenter):
     presenter.write_line('pass')
Esempio n. 11
0
 def represent_cc(self, presenter: CcScriptPresenter):
     presenter.write_line(
         f'{self.l_expr.reference_cc} = {self.r_expr.reference_cc}')
Esempio n. 12
0
 def represent_cc(self, presenter: CcScriptPresenter):
     expr_repr_list = []
     for expr in self.expr_list:
         expr_repr_list.append(expr.reference_py)
     presenter.write_line(f'{", ".join(expr_repr_list)};')
Esempio n. 13
0
 def represent_py(self, presenter: CcScriptPresenter):
     for expr in self.expr_list:
         presenter.write_line(expr.reference_py)
 def represent_py(self, presenter: CcScriptPresenter):
     presenter.write_line('from cc_model.CcModelBase import CcObject')
     presenter.write_crlf(self.__class__.__name__,
                          self.crlf_for_statement * 2)
     super().represent_py(presenter)
     presenter.write_line('CcObject.generate_tag_map(globals())')
 def represent_py_output(self, presenter: CcScriptPresenter):
     for statement in self._statements:
         assert (isinstance(statement, CcStatement))
         statement.represent_py_output(presenter)
         presenter.write_crlf(self.__class__.__name__,
                              self.crlf_for_statement)
Esempio n. 16
0
 def represent_py(self, presenter: CcScriptPresenter):
     presenter.write_line(self.goto)
Esempio n. 17
0
 def represent_cc(self, presenter: CcScriptPresenter):
     if self.expr:
         presenter.write_line(f'return {self.expr.reference_cc};')
     else:
         presenter.write_line('return;')
Esempio n. 18
0
 def represent_cc(self, presenter: CcScriptPresenter):
     presenter.shift_indent(False)
     presenter.write_line('{')
     presenter.shift_indent(True)
     super().represent_cc(presenter)
     presenter.shift_indent(False)
     presenter.write_line('}')
     presenter.shift_indent(True)
Esempio n. 19
0
 def represent_py_output(self, presenter: CcScriptPresenter):
     presenter.write_line('presenter.write_line()')
Esempio n. 20
0
    def represent_cc(self, presenter: CcScriptPresenter):
        if presenter.follow_if:
            presenter.write_line(f'else if ({self.condition.reference_cc})')
        else:
            presenter.write_line(f'if ({self.condition.reference_cc})')

        presenter.shift_indent(True)
        self.if_statement.represent_cc(presenter)
        presenter.shift_indent(False)

        if self.else_statement:
            if isinstance(self.else_statement, CcIfStatement):
                presenter.follow_if = True
                self.else_statement.represent_cc(presenter)
            else:
                presenter.follow_if = False
                presenter.write_line('else')
                presenter.shift_indent(True)
                self.else_statement.represent_cc(presenter)
                presenter.shift_indent(False)
Esempio n. 21
0
    def represent_cc(self, presenter: CcScriptPresenter):
        presenter.write_line(f'{self.operator} {{')
        if self.operator == '>':
            presenter.shift_indent(True)
        elif self.operator == '<':
            presenter.shift_indent(False)

        if self.statement:
            self.statement.represent_cc(presenter)

        if self.operator == '>':
            presenter.shift_indent(False)
        elif self.operator == '<':
            presenter.shift_indent(True)
        presenter.write_line(f'}}')
def generate_model_python(model_script):
    # model_file = sys.stdout
    model_file = open('cc_model/CcModel.py', 'w')
    model_presenter = CcScriptPresenter(model_file, '    ')
    model_script.represent_py(presenter=model_presenter)
    model_file.close()


def parse(script_path, debug=False, tracking=False):
    script_file = open(script_path, 'r')
    data = script_file.read()
    global script
    parser = yacc.yacc()
    parser.script = script
    p = parser.parse(input=data, lexer=lexer, debug=debug, tracking=tracking)
    if p:
        generate_model_python(script)
        return parser.script
    return None


if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    if parse(script_path=sys.argv[1], debug=True, tracking=False):
        file = open('Data/CcScript.cpp', 'w')
        presenter = CcScriptPresenter(file)
        script.represent_cc(presenter=presenter)
        file.close()
        del file
        del presenter