Beispiel #1
0
def p_halfcblock(p):
    '''halfcblock : Lcurly
                    | halfcblock pvar
                    | halfcblock dot
                    | halfcblock dvar
                    | halfcblock spaces
                    | halfcblock identifier
                    | halfcblock newline
                    | halfcblock cblock
                    | halfcblock pblock
                    | halfcblock colon
                    | halfcblock string
                    | halfcblock num
                    | halfcblock eq
                    | halfcblock lt
                    | halfcblock gt
                    | halfcblock not
                    | halfcblock tab
                    | halfcblock misc 
                    | halfcblock comma
                    | halfcblock fcall
    '''
    p[0] = Node('halfc','')
    if len(p)>2:
        p[0].args=p[1].args
        n=p[2]
        if isinstance(p[2],str):
            x= p[2]
            if x=='\n':
                x='newline'
            n=Node("token")
            n.str = x
        p[0].args.append(n)
    else:
        p[0].args= []
Beispiel #2
0
def p_Rparen(p):
    '''Rparen : rparen
                | spaces Rparen
    '''
    if len(p)>2:
        s = p[1].str
        s+=p[2].str
    else:
        s=p[1]
    p[0] = Node('Rparen')
    p[0].str=s
Beispiel #3
0
def p_Lparen(p):
    '''Lparen : lparen
                | spaces Lparen
    '''
    if len(p)>2:
        s = p[1].str
        s+=p[2].str
    else:
        s=p[1]
    p[0] = Node('Lparen')
    p[0].str=s
Beispiel #4
0
def p_Rcurly(p):
    '''Rcurly : rcurly
                | spaces Rcurly
                | Rcurly spaces
    '''
    if len(p)>2:
        s = p[1].str
        s+=p[2].str
    else:
        s=p[1]
    p[0] = Node('Rcurly')
    p[0].str=s
Beispiel #5
0
def p_Lcurly(p):
    '''Lcurly : lcurly
                | spaces Lcurly
                | Lcurly spaces
    '''
    if len(p)>2:
        s = p[1].str
        s+=p[2].str
    else:
        s=p[1]
    p[0] = Node('Lcurly')
    p[0].str=s
Beispiel #6
0
def p_spaces(p):
    '''spaces : spaces space
                | space
    '''
    if len(p)>2:
        c=p[1].cnt+1
        s=p[1].str+p[2]
    else:
        c=1
        s=p[1]
    p[0] = Node('spaces')
    p[0].cnt= c
    p[0].str =s
Beispiel #7
0
def p_halfblock(p):
    '''halfblock : label
                    | halfblock newline
                    | halfblock dot
                    | halfblock pvar
                    | halfblock dvar
                    | halfblock spaces
                    | halfblock identifier
                    | halfblock cblock
                    | halfblock assign
                    | halfblock pblock
                    | halfblock colon
                    | halfblock string
                    | halfblock num
                    | halfblock eq
                    | halfblock lt
                    | halfblock gt
                    | halfblock not
                    | halfblock tab
                    | halfblock misc 
                    | halfblock comma
                    | halfblock fcall
    '''
    if len(p)>2:
        p[0]=p[1]
        n=p[2]
        if isinstance(p[2],str) or isinstance(p[2],int):
            x= p[2]
            if x=='\n':
                x='newline'
            n=Node("token")
            n.str = x
        p[0].args.append(n)
    else:
        p[0] = Node('halfb')
        p[0].label = p[1]
Beispiel #8
0
def p_ceq(p):
    '''ceq : eq eq'''
    n = Node('ceq')
    n.str='=='
    return n
Beispiel #9
0
def p_pvar(p):
    '''pvar : percent identifier'''
    p[0] = Node('pvar')
    p[0].str=p[2]
Beispiel #10
0
def p_dvar(p):
    '''dvar : dollar identifier
                | dollar num'''
    p[0] = Node('dvar')
    p[0].str=str(p[2])