m4 books, examples, info? 
Author Message
 m4 books, examples, info?

I've been taking a look at m4 and am interested in learning it. I was
wondering if anyone knows of some m4 books or any example code on the
net. Unfortunately there is no alt.lang.m4. What I'm looking for
is an easy way to write a intel to at&t assembler sytax converter. Is
m4 up to such a task or am I looking in the wrong place.

        Thanks in advance

- James

--
- James Klicman                           CCnet Communications (510)988-7140



Fri, 28 Feb 1997 09:44:59 GMT  
 m4 books, examples, info?

Quote:

>I've been taking a look at m4 and am interested in learning it. I was
>wondering if anyone knows of some m4 books or any example code on the net.

I proposed an M4 book to O'Reilly but they didn't seem to be interested.

The GNU automatic configuration stuff uses (GNU) M4.  GNU M4 comes with
an examples directory.  Here's an example of mine, it generated random
test data

define(RANDOM_MODULUS,233280)dnl
define(RANDOM_MULTIPLIER,9301)dnl
define(RANDOM_INCREMENT,49297)dnl
define(RANDOM_SEED,3321)dnl
define(NEXT_RANDOM,
   `define(`RANDOM_SEED', eval(
        ((RANDOM_SEED*'RANDOM_MULTIPLIER+RANDOM_INCREMENT`)%'
        RANDOM_MODULUS+RANDOM_MODULUS`)%'
        RANDOM_MODULUS`))')dnl
define(digit,`NEXT_RANDOM()eval(RANDOM_SEED%10)')dnl
define(digits,
    `ifelse($1,1,,`digits(decr($1))')digit()')dnl
define(letter,`NEXT_RANDOM()substr(ABCDEFGHIJKLMNOPQRSTUVWXYZ,
        eval(RANDOM_SEED%26), 1)')dnl
define(letters,
    `ifelse($1,1,,`letters(decr($1))')`'letter()')dnl
define(rpad, `substr(`$2',0,$1,`$3')')dnl
define(lpad, `substr(`$2',len(`$2')-$1,$1,`$3')')dnl
define(r_year,  `NEXT_RANDOM()eval(RANDOM_SEED%15+1976,10,4)')dnl
define(r_month, `NEXT_RANDOM()eval(RANDOM_SEED%12+1,10,2)')dnl
define(r_day,   `NEXT_RANDOM()eval(RANDOM_SEED%28+1,10,2)')dnl
define(r_date,  `r_year()/r_month()/r_day()')dnl
define(r_cust,  `digits(4)letter()')dnl
define(r_part,  `letters(2)-digits(5)-digits(2)')dnl
define(r_quant, `NEXT_RANDOM()lpad(3,eval(RANDOM_SEED%999+1))')dnl
define(r_price, `lpad(4,eval(digits(4)))')dnl
define(r_order, `r_date r_cust  r_part  r_quant')
define(r_catal, `r_part r_price')
define(repeat,
    `ifelse($1,0,,`$2($1)
repeat(decr($1),`$2')')')dnl
# 20 orders
repeat(20, `r_order')
# 20 catalogue entries
repeat(20, `r_catal')

I've used M4 heavily to make _generic_ reusable packages in C and Pascal.
(Examples available on request.)

Quote:
>What I'm looking for
>is an easy way to write a intel to at&t assembler sytax converter. Is
>m4 up to such a task or am I looking in the wrong place.

Yes and no.  The main point is that in 'straight' M4 a macro call has the
form
        <identifier>
or      <identifier>(<arg1>, ..., <argn>)

If you have a file with stuff like
        label(Fred)
            mov(AX, bar)
then you're in business.  If, in constrast, you have stuff like
        Fred:
            mov AX, bar
you are out of luck.  My version of Ozan Yigit's PD M4 has an extension
where   <identifier><special character>
calls a macro, passing <identifier> as the argument, so you can do
        defsuffix(`:', `label')
and then
        Fred:
calls
        label(Fred)
That gets you halfway there.  This is going to be extended to multi-
character suffixes, using a trie in the implementation.
The next thing you need is to add support for
        <identifier><layout><arg1>, ..., <argn> <newline>
as a macro call.  Planned but not there yet.  Certainly easy to add as a
special purpose hack.  Not in "standard" M4, not in GNU M4.

I have used M4 quite happily to port assembly code between several
dialects, but I _started_ from a base that was already in M4 syntax.
(For example, I have some stuff at the moment where M4 is generating
TASM output.  Trivial really, but it _starts_ from M4 syntax.)
You could use lex to pre-pre-process the files, adding parentheses
where necessary.

--
The party that took Australia into Vietnam wants to smash the inner-city
yacht school and put a Grand Prix in its place.  They don't change.



Sat, 01 Mar 1997 18:40:28 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Tcl tcl.m4 & Tk aclocal.m4

2. m4 book(s) wanted

3. looking for an archive of examples, or a book of examples

4. Examples Code for Accessing Class Info

5. Need example or info for using file mapping in LabView

6. Wanted: Info on Pro*Kappa language (grammar, manual, examples)

7. Wanted: Info on Pro*Kappa language (grammar, manual, examples)

8. Book on Pattern's with Smalltalk Examples?

9. Book: Object Rexx by Example, How useful?

10. Confused by example in Pickaxe book

11. TCPServer example in PP book

12. Problem with threading example from pickaxe book

 

 
Powered by phpBB® Forum Software