[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[help-3dldf] Re: Macros in 3DLDF
From: |
Laurence Finston |
Subject: |
[help-3dldf] Re: Macros in 3DLDF |
Date: |
Mon, 3 Jan 2005 18:06:21 +0100 (MET) |
Hello Nobre et al,
I've now implemented macros, pretty much as I described them in
my last posting. However, typed parameters are delimited by (curly)
braces rather than (square) brackets. Brackets are used for numerical
subscripts, so when I tried to use them for typed arguments in macro
calls, the parser function `yyparse()' shifted the `LEFT_BRACKET' rather
than reducing `symbolic_token' to `variable'.
The following code is an excerpt from `sample0.ldf'. It contains
examples of how to define and use macros. It is followed by
the output produced by `3dldf' from this code.
I've uploaded the updated files to Savannah. I'm about to start
working on rules for defining macros that are elements of
`macro_vectors'.
Laurence
%% *** (3) Examples of using macros. LDF 2005.01.03.
beginfig(1);
macro a, b, d; %% Some are declared, others are not.
%% Macro with no arguments.
def a :=
message "This is `a'.";
enddef;
a;
%% Redefining a macro.
def a :=
message "This is `a' after being redefined.";
enddef;
a;
%% A macro with no untyped arguments and a single typed argument.
def b {point c} :=
message "In `b': `c' == ";
show c;
enddef;
b {(0, 1, 2)};
%% A macro with no typed arguments and a single untyped argument.
def d (e) :=
message "In`d': `e' == ";
show e;
enddef;
string f;
f := "fff";
d (f);
%% A macro with one typed argument and one untyped argument.
def g (h) {path i} :=
message "In `g': `h' == ";
show h;
message "In `g': `i' == ";
show i;
enddef;
point j;
j := (0, 1, 2);
g (j) {origin -- (3, 3, 3)};
%% A nested macro definition.
def k :=
def l :=
message "This is `l' in `k'.";
enddef;
message "This is `k'.";
l;
enddef;
k;
%% A macro with two typed arguments and two untyped arguments.
def m (n, o) {path p, transform q} :=
message "In `m': `n' == ";
show n;
message "In `m': `o' == ";
show o;
message "In `m': `p' == ";
show p;
message "In `m': `q' == ";
show q;
enddef;
point r;
string s;
r := (0, 1, 2);
s := "sss";
m (r, s) {origin -- (3, 3, 3), identity scaled (1, 2, 3)};
endfig;
end;
*** Output: ***********************
This is `a'.
This is `a' after being redefined.
In `b': `c' ==
>> (0.000000, 1.000000, 2.000000)
In`d': `e' ==
>> fff
In `g': `h' ==
>> (0.000000, 1.000000, 2.000000)
In `g': `i' ==
>> Path:
points.size() == 2
connectors.size() == 1
(0.000000, 0.000000, 0.000000) -- (3.000000, 3.000000, 3.000000);
fill_draw_value == 0
draw_color == 0
fill_color == 0
pen == 0
dash_pattern == 0
`arrow' == `Path::NO_ARROW'.
This is `k'.
This is `l' in `k'.
Exiting 3DLDF Version 1.2.0.0.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [help-3dldf] Re: Macros in 3DLDF,
Laurence Finston <=