On Aug 19, 10:52 pm, "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'''
> ...
I've approached it differently. To make the assembler flexible and not
over-complicate the parser, I left the parser only with the task of
recognizing syntax and not instructions themselves and what kinds of
arguments they accept. When you have dozens of sometimes-similar
instructions to handle (talking about RISC here), this helps.
>
> But as far as I know ADD work in other way:
> mov eax, 123h
> mov ebx, 12h
> add eax ; eax = eax+ebx
>
This is x86 assembly, which is far from being the only one in
existence.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---