예제 #1
0
    def p_pop(self, p):
        '''pop          : empty
                        | LPOP VALUE RPOP
                        | LPOP empty RPOP
                        | POP'''

        p[0] = None if len(p) < 3 else Element(type='pop', value=p[2])
예제 #2
0
    def p_push(self, p):
        '''push         : empty
                        | LPUSH VALUE RPUSH
                        | LPUSH empty RPUSH
                        | PUSH'''

        p[0] = None if len(p) < 3 else Element(type='push', value=p[2])
예제 #3
0
 def parse(self, ast=None):
     if ast is None:
         first_token = self.token_stream.get_token()
         ast = Element(first_token.token)
     operator = self.token_stream.get_token()
     if operator.empty:
         return ast
     if operator.operator:
         return self.parse_operator(ast, operator)
예제 #4
0
    def p_right(self, p):
        '''right        : LRIGHT VALUE RRIGHT
                        | LRIGHT empty RRIGHT
                        | RIGHT empty'''

        p[0] = Element(type='right', value=p[2])
예제 #5
0
    def p_axiom(self, p):
        '''axiom        : empty
                        | LAXIOM VALUE RAXIOM'''

        p[0] = None if len(p) < 3 else Element(type='axiom', value=p[2])
예제 #6
0
 def parse_operator(self, left_ast, operator):
     right_token = self.token_stream.get_token()
     return self.parse(
         Operation(left_ast, Element(right_token.token),
                   Operator(operator.token)))
예제 #7
0
    def p_final(self, p):
        '''final        : empty
                        | FINAL'''

        p[0] = None if p[1] is None else Element(type='final')
예제 #8
0
    def p_block(self, p):
        '''block        : LBLOCK tag x y special RBLOCK'''

        p[0] = Element(type='block', children=[p[2], p[3], p[4]])
예제 #9
0
    def p_customblock(self, p):
        '''customblock  : LCUSTOMBLOCK inside RCUSTOMBLOCK'''

        p[0] = Element(type='customblock', value=p[1], children=[p[2]])
예제 #10
0
    def p_value(self, p):
        '''value         : LVALUE VALUE RVALUE'''

        p[0] = Element(type='left', value=p[2])
예제 #11
0
    def p_expression(self, p):
        '''expression   : LEXPRESSION VALUE REXPRESSION'''

        p[0] = Element(type='expression', value=p[2])
예제 #12
0
    def p_output(self, p):
        '''output       : empty
                        | LOUTPUT VALUE ROUTPUT
                        | LOUTPUT empty ROUTPUT'''

        p[0] = None if len(p) < 3 else Element(type='output', value=p[2])
예제 #13
0
    def p_parameter(self, p):
        '''parameter   : LPARAMETER name value RPARAMETER'''

        p[0] = Element(type='parameter', children=[p[2], p[3]])
예제 #14
0
    def p_read(self, p):
        '''read         : READ
                        | LREAD VALUE RREAD
                        | LREAD empty RREAD'''

        p[0] = Element(type='read') if len(p) < 3 else Element(type='read', value=p[2])
예제 #15
0
    def p_to(self, p):
        '''to           : LTO VALUE RTO '''

        p[0] = Element(type='to', value=p[2])
예제 #16
0
    def p_from(self, p):
        '''from         : LFROM VALUE RFROM'''

        p[0] = Element(type='from', value=p[2])
예제 #17
0
    def p_transition(self, p):
        '''transition   : LTRANSITION from to action pop push transout RTRANSITION'''

        p[0] = Element(type='transition', children=[p[2], p[3], p[4], p[5], p[6], p[7]])
예제 #18
0
    def p_structure(self, p):
        '''structure    : LSTRUCTURE type axiom tapes body RSTRUCTURE'''

        p[0] = Element(type='structure', children=[p[2], p[3], p[4], p[5]])
예제 #19
0
    def p_name(self, p):
        '''name         : LNAME VALUE RNAME'''

        p[0] = Element(type='left', value=p[2])
예제 #20
0
    def p_type(self, p):
        '''type         : LTYPE VALUE RTYPE'''

        p[0] = Element(type='type', value=p[2])
예제 #21
0
    def p_tapes(self, p):
        '''tapes        : empty
                        | LTAPES VALUE RTAPES'''

        p[0] = None if len(p) < 3 else Element(type='tapes', value=p[2])
예제 #22
0
    def p_transout(self, p):
        '''transout     : empty
                        | LTRANSOUT VALUE RTRANSOUT
                        | LTRANSOUT empty RTRANSOUT'''

        p[0] = None if len(p) < 3 else Element(type='transout', value=p[2])
예제 #23
0
    def p_automaton(self, p):
        '''automaton    : LAUTOMATON inside RAUTOMATON'''

        p[0] = Element(type='automaton', children=[p[2]])
예제 #24
0
    def p_write(self, p):
        '''write        : empty
                        | WRITE
                        | LWRITE VALUE RWRITE'''

        p[0] = None if len(p) < 3 else Element(type='write', value=p[2])
예제 #25
0
    def p_tag(self, p):
        '''tag          : LTAG VALUE RTAG'''

        p[0] = Element(type='tag', value=p[2])
예제 #26
0
    def p_move(self, p):
        '''move         : empty
                        | LMOVE VALUE RMOVE'''

        p[0] = None if len(p) < 3 else Element(type='move', value=p[2])
예제 #27
0
    def p_production(self, p):
        '''production   : LPRODUCTION left right RPRODUCTION'''

        p[0] = Element(type='production', children=[p[2], p[3]])
예제 #28
0
    def p_left(self, p):
        '''left         : LLEFT VALUE RLEFT'''

        p[0] = Element(type='left', value=p[2])
예제 #29
0
def test_ast():
    calcul_visitor = Interpreter()
    op = Operation(Element(7), Element(3), Operator('+'))
    Operation(op, op, Operator('+')).accept(calcul_visitor)
    calcul_visitor.print_result()
예제 #30
0
    def p_initial(self, p):
        '''initial      : empty
                        | INITIAL'''

        p[0] = None if p[1] is None else Element(type='initial')