spiffyscore
Diff
Not logged in

Differences From Artifact [b5bfbaf68dca2f5d]:

To Artifact [ba81961e5a244d10]:


31 31 32 t_ignore = " |" 32 t_ignore = " |" 33 33 34 lex.lex() 34 lex.lex() 35 35 36 #lex.input("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") 36 #lex.input("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") 37 #s = "GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD" 37 #s = "GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD" 38 s = "GF_G," | 38 s = "GF_G,/2" 39 lex.input(s) 39 lex.input(s) 40 for tok in iter(lex.token, None): 40 for tok in iter(lex.token, None): 41 print repr(tok.type), repr(tok.value) 41 print repr(tok.type), repr(tok.value) 42 42 43 43 44 # Parse (yacc) 44 # Parse (yacc) 45 45 ................................................................................................................................................................................ 76 # | REST 76 # | REST 77 # ''' 77 # ''' 78 # p[0] = p[1] 78 # p[0] = p[1] 79 # 79 # 80 #def p_pitch(p): 80 #def p_pitch(p): 81 81 82 def p_pitch_list(p): 82 def p_pitch_list(p): 83 '''score : score pitch | 83 '''score : score note 84 ''' 84 ''' 85 p[0] = p[1] + [p[2]] 85 p[0] = p[1] + [p[2]] 86 86 87 def p_sore(p): | 87 def p_score(p): 88 '''score : pitch | 88 '''score : note 89 ''' 89 ''' 90 p[0] = [p[1]] 90 p[0] = [p[1]] 91 91 92 92 93 def p_pitch_more(p): | 93 def p_note(p): 94 ''' score : pitch NOTE_LENGTH | 94 '''note : pitch 95 ''' 95 ''' 96 print "stuff" | 96 p[0] = p[1] > 97 > 98 > 99 def p_note_length(p): > 100 ''' note : note NOTE_LENGTH > 101 ''' 97 new_note = p[1] 102 new_note = p[1] 98 new_note.duration = p[2] 103 new_note.duration = p[2] 99 p[0] = new_note 104 p[0] = new_note 100 105 101 def p_pitch(p): < 102 '''pitch : BASENOTE < 103 ''' < 104 p[0] = Note(p[1]) < 105 < 106 def p_accidental(p): 106 def p_accidental(p): 107 '''pitch : ACCIDENTAL pitch 107 '''pitch : ACCIDENTAL pitch 108 ''' 108 ''' 109 p[2].accidental = p[1] 109 p[2].accidental = p[1] 110 p[0] = p[2] 110 p[0] = p[2] 111 111 112 def p_octave(p): 112 def p_octave(p): ................................................................................................................................................................................ 114 ''' 114 ''' 115 count = len(p[2]) 115 count = len(p[2]) 116 increment_or_decrement = 1 if p[2][0] == "," else -1 116 increment_or_decrement = 1 if p[2][0] == "," else -1 117 octave = 8 + (count * increment_or_decrement) 117 octave = 8 + (count * increment_or_decrement) 118 p[1].octave = octave 118 p[1].octave = octave 119 p[0] = p[1] 119 p[0] = p[1] 120 120 > 121 def p_pitch(p): > 122 '''pitch : BASENOTE > 123 ''' > 124 p[0] = Note(p[1]) > 125 121 def p_error(p): 126 def p_error(p): 122 print "Syntax error at '%s' of element type %s" % (p.value, p.type) 127 print "Syntax error at '%s' of element type %s" % (p.value, p.type) 123 128 124 yacc.yacc() 129 yacc.yacc() 125 130 126 #print yacc.parse("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") 131 #print yacc.parse("GFG B'AB,, | g/2fg gab | GFG BAB | d2A AFD") 127 print yacc.parse(s) 132 print yacc.parse(s)