Slafs ha scritto:
Hi ALL!I have to write in yacc an acceptor of files with lines matching this regexp: '[0-9],[0-9]' and I don't know what I am doing wrong beacuse this: -------- tokens = ( 'NUMBER', ) literals = [','] t_NUMBER = r'\d' ... def p_statement_exp(p): '''statement : NUMBER ',' NUMBER ''' print "OK!" sys.exit() ------- also accepts lines like 2,abcdef3 which of could someone please tell me what's wrong in my code? full source on http://paste-it.net/public/vba22d5/
Your code works for me (Python 2.5 and ply 2.3 on ubuntu 8.10), except that, from the rest of your code, I see that you parse separately each line of file. Since you put a sys.exit() in the parsing rule, it means that at the first line successfully parsed your program will quit.
Try putting a simple print in it and instead putting the sys.exit in your p_error function (if you want to exit at the first 'wrong' line line).
BTW, are you aware that exists a specific google group for ply users? Specific ply questions could be answered here : http://groups.google.com/group/ply-hack?pli=1
Ciao ---- FB -- http://mail.python.org/mailman/listinfo/python-list
