Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.compilers > #1122

Re: Best tools for writing an assembler?

From noitalmost <noitalmost@cox.net>
Newsgroups comp.compilers
Subject Re: Best tools for writing an assembler?
Date 2014-02-27 18:11 -0500
Organization Compilers Central
Message-ID <14-02-043@comp.compilers> (permalink)
References <14-02-018@comp.compilers> <14-02-030@comp.compilers>

Show all headers | View raw


On Monday, February 24, 2014 01:32:37 AM Sibastien Fricker wrote:
> Sorry, but even if Flex/Bison are difficult to setup, writing a parser
> by hand is not a good way to work.
> Tools like Flex/Bison give several advantages that you cannot cover by
> writing a parser by hand:
>  1) They are able to manage complex rules which would need many lines of
> code. For example, parsing an integer consists only of matching the
> regular expression pattern "[0-9]+". It is simple and more readable than
> writing directly its C++ code.

But you have to understand the grammar of those rules as expressed in
the scanner/parser tools. Until you've learned those tools, the C++
code will be more understandable to you, even if it's expressed more
verbosely. Readability is somewhat subjective and depends a lot on
what you're familiar with. You can do some pretty cool stuff in Latin
with only a word or two, but if you don't know Latin, the 15-word,
2-sentence English translation is much more readable.  (I'm assuming,
of course, that you understand English, and aren't one of those crazy
monkeys with the typewriter that can generate Shakespearean sonnets.
:)

>  2) The generated code is optimized at a level different to what the
> compiler does. For example, if in your keyword you have "visual" and
> "virtual", the generated code will first match "vi" and then "rtual" or
> "sual". Of course writing such optimization by hand is practically not
> possible.

But this is the OP's first attempt at a relatively robust assembler.
Have you forgotten your first significant project? When the magical
feelings were "It works!" and "I know how it works!" rather than "I
saved a microsecond in assembly time!"

>  3) Flex/Bison are performing some error analysis which permits detect
> unused rules, unreachable states, ... All this checks are not existing
> for hand written parser. That's mean that your test suite need to handle
> such kind of non detected errors.

Very true, but we are talking about assembler syntax here.

>  4) Inserting a new keyword/extending a syntax of an existing parser is
> more safe. In fact, due to all checks make by the parser generator, if
> the code compiles without bison/flex warnings you can be sure that your
> new syntax extension does not collide with the existing one. In other
> words, you did not program a regression my extending your syntax.
>
> In other words, saying that writing parser by hand is better is the same
> as saying "why using object oriented programming? I can do the same in C
> with struct!" Yes, but the result is less readable, the compiler does
> does less verifications.

I don't think that's a valid comparison. To the new user, it's more
the reverse than anything. Until you've used a parser tool for quite a
while, it's like a giant black box. The scanner tool is a smaller
black box. But rather than a nice OOP class, it's more like the
structs of Win95 MFC. You have to understand a lot about the global
organization, plus a lot of implementation details, and you have 2
extra grammars to learn. In other words, you have to understand a lot
of stuff before you understand anything at all. I just don't think
it's worth it for assembler syntax. There's a good chance the OP will
just give up, frustrated and completely mystified. If we were talking
about parsing Perl syntax, that would be different. Or if the OP were
writing 10 assemblers, that would be different too.

I'm obviously not an expert in this field, and my experience in
compiler writing is rather slim. It consists of 3 not overly
sophisticated assemblers and 2 toy HLL compilers. My experience with
the frustration of "shift/reduce conflict" however, is of some value
here, I think.

And I don't mean to denegrate the value of any of the parser tools.
But they're only easy to use and integrate into your compiler once
you've learned how to use them, which isn't trivial.

Back to comp.compilers | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Best tools for writing an assembler? tpphysik@gmail.com - 2014-02-18 16:04 -0800
  Re: Best tools for writing an assembler? "C. Bergström" <cbergstrom@pathscale.com> - 2014-02-19 11:14 +0700
  Re: Best tools for writing an assembler? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-02-19 04:25 +0000
  Re: Best tools for writing an assembler? Ivan Godard <ivan@ootbcomp.com> - 2014-02-18 23:23 -0800
    Re: Best tools for writing an assembler? Robert A Duff <bobduff@TheWorld.com> - 2014-02-19 18:20 -0500
      Re: Best tools for writing an assembler? Sébastien Fricker <sebastien.fricker@gmail.com> - 2014-02-21 12:00 +0100
      Re: Best tools for writing an assembler? "BartC" <bc@freeuk.com> - 2014-02-22 00:28 +0000
      Re: Best tools for writing an assembler? noitalmost <noitalmost@cox.net> - 2014-02-23 11:22 -0500
        Re: Best tools for writing an assembler? Sébastien Fricker <sebastien.fricker@gmail.com> - 2014-02-24 07:32 +0100
          Re: Best tools for writing an assembler? Louis Krupp <lkrupp@pssw.com> - 2014-02-24 15:39 -0700
          Re: Best tools for writing an assembler? Ivan Godard <ivan@ootbcomp.com> - 2014-02-24 15:04 -0800
            Re: Best tools for writing an assembler? rpw3@rpw3.org (Rob Warnock) - 2014-02-25 13:00 +0000
          Re: Best tools for writing an assembler? Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-02-25 04:09 +0100
        Re: Best tools for writing an assembler? "James Harris" <james.harris.1@gmail.com> - 2014-02-24 23:18 +0000
        Re: Best tools for writing an assembler? noitalmost <noitalmost@cox.net> - 2014-02-27 18:11 -0500
          Re: Best tools for writing an assembler? George Neuner <gneuner2@comcast.net> - 2014-03-01 13:09 -0500
            Re: Best tools for writing an assembler? federation2005@netzero.com - 2014-03-26 17:57 -0700
              Re: Best tools for writing an assembler? federation2005@netzero.com - 2014-04-13 12:24 -0700
  Re: Best tools for writing an assembler? Sébastien Fricker <sebastien.fricker@gmail.com> - 2014-02-19 09:59 +0100
    Re: Best tools for writing an assembler? Robert A Duff <bobduff@shell01.TheWorld.com> - 2014-02-19 18:27 -0500
  Re: Best tools for writing an assembler? Patrik Túri <tpphysik@gmail.com> - 2014-02-20 17:15 -0800
    Re: Best tools for writing an assembler? Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-02-21 12:09 +0100
      Re: Best tools for writing an assembler? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-02-24 20:42 +0000
        Re: Best tools for writing an assembler? Ivan Godard <ivan@ootbcomp.com> - 2014-02-24 15:13 -0800
        Re: Best tools for writing an assembler? hu47121@usenet.kitty.sub.org (Hannah) - 2014-02-25 00:43 +0000
          Re: Best tools for writing an assembler? Walter Banks <walter@bytecraft.com> - 2014-02-27 14:14 -0500
        Re: Best tools for writing an assembler? Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2014-02-25 04:23 +0100
    Re: Best tools for writing an assembler? glen herrmannsfeldt <gah@ugcs.caltech.edu> - 2014-02-24 20:35 +0000

csiph-web