Hi, Thanks for the suggestion! And sometimes I have complex commands like: MOV.rp2 R1, R11<<3 in which .rp2 means repeat this instruction two more times (and increase the Register number ), i.e. MOV R1, R11<<3 MOV R2, R12<<3 MOV R3, R13<<3
And I can write something similar in ADD ADD.s.rp3 R1, R11<<2, R21 in which .s means signed add (if unsigned add, use .u instead), and its can be extends to four instructions ADD.s R1, R11<<2, R21 ADD.s R2, R12<<2, R22 ADD.s R3, R13<<2, R23 ADD.s R4, R14<<2, R24 As you can see, the combination of all the conditions are too complex to cover. And it seems impossible for me to write one rule for every possible instruction format. Is there any suggestion? Thanks! Davy On Aug 20, 4:52 am, "Marek Nowicki" <[EMAIL PROTECTED]> wrote: > Dnia 19-08-2008 o 12:57:04 Davy <[EMAIL PROTECTED]> napisał: > > > I am learning to write a assembly language parser. > > The assembly format is like: > > MOV R1, 0 //R1 = 0 > > ADD R2, R3, R4 // R2 = R3 + R3 > > > The question is, how to define the comma (,) between registers? Shall > > I define it as token or literals or something else? > > > Any suggestion are welcome:) > > I think that this is up to you. > > I personally will do somethink like this: > > t_COMMA = "," > t_MOV = "mov" > t_REGS = "R[0-4]+" > t_NUM = "[0-9]+" > ... > > def p_mov(t): > '''mov : REGS COMMA NUM > | REGS COMMA REGS''' > ... > > def p_add(t): > '''add : REGS COMMA REGS COMMA REGS''' > ... > > But as far as I know ADD work in other way: > mov eax, 123h > mov ebx, 12h > add eax ; eax = eax+ebx > > regards, > Marek --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "ply-hack" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/ply-hack?hl=en -~----------~----~----~----~------~----~------~--~---
