Hacker News new | past | comments | ask | show | jobs | submit login

This makes me think of a generic assembler I wrote at one point (in C++ I think, I should put it on github). The idea was that you could define the instruction set right in the assembly source. It included a backtracking BNF parser to support it with these pseudo ops:

   .rule name value pattern  ; Define a syntax rule

   .insn pattern    ; Define an instruction
       ...            ; Macro expanded on pattern match
   .end

   "pattern" contains literal characters, whitespace and
   references to other rules with "<rule-name>" or <expr>
   for a math expression.

   "value" is a comma separated list of expressions which
   can contain "argN" to reference the Nth value from the
   pattern (as returned by embedded rules).

    For example, this is how you could construct the
    instructions "lda <expr>", "lda #<expr>", "ldb <expr>",
    and "ldb #<expr>":

   .rule dual 0x01 lda
   .rule dual 0x02 ldb
   .rule mode 0xf8,arg1 <expr>
   .rule mode 0xfa,arg1 #<expr>

   .insn <dual> <mode>
      .byte arg1|arg2  ; Emit op-code
      .word arg3       ; Emit argument
   .end
SNOBOL4 itself is not an assembler, but I think you could make one like this from it.



This is a very interesting idea, and I have been finding inspiration in it. New machine architectures by way of #include files! Or cat! I've been thinking that maybe the right compile-time programming model is something like term-rewriting (more or less like C++ templates or Prolog or Aardappel) rather than textual substitution. I wrote some more thoughts on the matter at https://lobste.rs/s/kfpsou/what_is_everyone_working_on_this_... but I still haven't gotten very far on it.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: