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


Groups > comp.compilers > #1218

Re: Best tools for writing an assembler?

From federation2005@netzero.com
Newsgroups comp.compilers
Subject Re: Best tools for writing an assembler?
Date 2014-04-13 12:24 -0700
Organization Compilers Central
Message-ID <14-04-011@comp.compilers> (permalink)
References <14-02-018@comp.compilers> <14-02-030@comp.compilers> <14-02-043@comp.compilers> <14-03-002@comp.compilers> <14-03-066@comp.compilers>

Show all headers | View raw


On Wednesday, March 26, 2014 7:57:11 PM UTC-5, federat...@netzero.com wrote:
> First in terms of the syntax, the best advice is to *normalize* the
> syntax. At the assembly level, the most notorious example [of an
> unnormalized syntax] is MASM and the Intel syntax it is associated with.

> There are a half-dozen instances of the phrase category "Directive" in
> the phrase structure grammar whose only distinctions are semantic in
> nature: i.e.  there is an attempt to implement semantic constraints by
> cleaving this single category into a half-dozen shards.

In fact, based on the reference for MASM 6.1, one could "reintegrate" the
directive syntax by first classifying all their contexts:

Contexts:
(a) RunTimeLoop: inside a .WHILE/.REPEAT statement group

(b) MacroBody: inside a MACRO/REPT/REPEAT/WHILE/FOR/FORC/IRP/IRPC statement
group

(c) Statement: inside a .IF/.ELSEIF/.ELSE statement group, a statement group
headed by any of the IF*/ELSEIF*/ELSE keywords or at the TopLevel

(d) SegmentBody: inside a statement group (1) begun by a ".CODE", ".DATA",
".DATA?", ".CONST", ".FARDATA", ".FARDATA?", ".STACK" or "SEGMENT" directive
and ended by its matching "ENDS" directive; or (2) begun by a "PROC" directive
and ended by its matching "ENDP" directive.

(e) Inside a statement group headed by STRUC/STRUCT/UNION

Then it suffices to lay out one (large) set of phrase structure rules for the
directives ("Dir"), with the constraints then noted separately. It's much
easier for a parser to check for these constraints than to try and force-fit
it into the grammar. In addition, organizing things this way may lead to
simplifications that occur by recognizing that some of the constraints are
simply not needed and can be removed.

Notice, by the way, in the list below that the assembler does
"quasi-compilation" (that is, it compiles run-time statements for loops and
functional calls). I don't know if GAS is doing that much. But a decent
assembler might have to match this level of functionality.

For MASM syntax, the classification would lead to the following groups.

(1) Loop directives appear only in context (a) and include phrase structure
rules for:
Dir -> ".BREAK" ...
Dir -> ".CONTINUE" ...

(2) Macro Directives appear only in context (b) and include directives for the
prefix ":", "GOTO" and "EXITM".

(3) Segmentation Directives appear only in contexts (a), (b) or (c) and
involve all the ".CODE", ..., "SEGMENT" "segment body" directives

(4) In-Segment Directives appear only in context (d) and include the
mnemonics, along with the x86 specific prefixes (i.e. "REP", "REPE", ...,
"LOCK").

It also includes the quasi-compiled control-flow (yes, MASM is doing basic
compilation!):

".IF"...".ELSEIF"...".ELSE"...".ENDIF",
".WHILE"...".ENDW"
".REPEAT"...".UNTIL" (or ".UNTILCXZ")
"PROC"..."ENDP"

as well as ".STARTUP", ".EXIT", "LABEL" "INVOKE" (the "invoke" statement is
the quasi-compiled function call).

(5) Member Directives appear only in context (e): the "STRUC", "STRUCT" and
"UNION" statements.

(6) Type and Alignment Directives appear in contexts (d) and (e). Those are
the:
initializers ("DB", "DW", ...)
type declarations ("BYTE", "SBYTE", "WORD", ...)
type declarations involving "typedef"'ed types
declarations that include structure/union field components
declarations involving "record" typenames
alignment/location directives ("EVEN", "ORG", "ALIGN")

(7) General Directives may appear in all contexts.
(Basically, every other directive in the MASM 6.1 syntax).

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