Re: Assembler in Lex/Yacc
- From: Tim Roberts <spamtrap@xxxxxxxxxx>
- Date: Sat, 03 Dec 2005 20:06:49 GMT
"Sanky" <spamtrap@xxxxxxxxxx> wrote:
>
>I was working on an assembler for X64 architecture. I was wondering
>what are the tradeoffs in designing an assembler using lex or re2c and
>yacc? Why is that handwritten assemblers are more popular than those
>developed using lex/yacc? Developing a grammar is the toughest part,
>but once you have a grammar ready, I think the rest of the routines are
>pretty strightforward? Is it that code generated by Lex/Yacc is not as
>efficient?
>YASM does get close, but again it resorts to hand written code at some
>places.
>
>Is it that Lex/Yacc is an overkill or is that Lex/Yacc are not the
>right tools? I'm new to compiler and assembler design, and would be
>helpful if anyone can guide.
There are several reasons for this, none of them completely compelling.
In my view, lex and yacc were designed to solve a different class of
problem. Most assembly languages are not context-free LALR grammars. They
are leftovers from the days when we keypunched lines of assembler into
fixed fields. Things like that tend to be awkward in yacc.
Now, it would certainly be possible to define an assembly language that
looked more like the things usually handled by yacc. Randall's HLA is one
such example; I suspect its grammar is quite yaccable.
On another level, most assemblers have a rather simple format. It is often
easier to visualize how to parse and translate it by hand than it is to
visualize how to express it to lex and yacc.
I do want to address one specific item in your message:
>Is it that code generated by Lex/Yacc is not as efficient?
This represents an interesting misconception. The efficiency of the
generated code is not a concern. Unlike a compiled language, there are not
multiple ways of translating an assembler instruction[*]. "mov eax, dword
ptr [ebx+7]" must generate one machine language instruction (8B 43 07). You
don't get to generate intermediate results and resolve temporaries; you
must translate one assembler instruction into one machine instruction.
[*] Pedant is will note that there ARE multiple ways of encoding some x86
instructions. This is not important here.
--
- Tim Roberts, timr@xxxxxxxxx
Providenza & Boekelheide, Inc.
.
- References:
- Assembler in Lex/Yacc
- From: Sanky
- Assembler in Lex/Yacc
- Prev by Date: Re: Chicago - Did you take MASM615 Assembly Language
- Next by Date: Re: sin,cos math functions in assembly
- Previous by thread: Re: Assembler in Lex/Yacc
- Next by thread: Re: Assembler in Lex/Yacc
- Index(es):
Relevant Pages
|