Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
C-datadec
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Duncan White
C-datadec
Commits
69792c72
Commit
69792c72
authored
May 20, 2014
by
Duncan White
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed some traces of m2datadec, imported in a couple of bug fixes from c-tools datadec
parent
2e8e630e
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
64 additions
and
85 deletions
+64
-85
Makefile
Makefile
+19
-42
README
README
+0
-1
c-datadec.man
c-datadec.man
+22
-17
decs.c
decs.c
+18
-3
optimize.c
optimize.c
+0
-1
parser.c
parser.c
+1
-1
test/Makefile
test/Makefile
+4
-20
No files found.
Makefile
View file @
69792c72
CC
=
gcc
#CC = cc
CFLAGS
=
-g
-UDEBUGGING
LINTFLAGS
=
-UDEBUGGING
EXECS
=
datadec
#EXECS = datadec m2datadec
CC
=
gcc
#CC = cc
DEST
=
$(PREFIX)
/usr
BINDIR
=
$(DEST)
/bin
MANDIR
=
$(DEST)
/man/man1
CFLAGS
=
-g
-UDEBUGGING
-Wall
LDLIBS
=
EXECS
=
datadec
datadec_srcs
=
datadec.c parser.c lexer.c struct.c decs.c optimize.c
datadec_objs
=
datadec.o parser.o lexer.o struct.o decs.o optimize.o
m2datadec_srcs
=
datadec.c parser.c lexer.c struct.c m2decs.c optimize.c
m2datadec_objs
=
datadec.o parser.o lexer.o struct.o m2decs.o optimize.o
datadec_srcs
=
datadec.c parser.c lexer.c struct.c decs.c optimize.c
datadec_objs
=
datadec.o parser.o lexer.o struct.o decs.o optimize.o
all
:
$(EXECS)
install
:
install
-m
755 datadec
$(PREFIX)
/usr/local/bin/datadec
install
-m
644 c-datadec.man
$(PREFIX)
/usr/man/man1/datadec.1
arch
:
$(EXECS)
cp
-p
$(EXECS)
../../
$(ARCH)
cd
../../
$(ARCH)
;
chmod
a+rx,ug+w
$(EXECS)
install
:
$(EXECS)
install
-m
755
$(EXECS)
$(BINDIR)
install
-m
644 c-datadec.man
$(MANDIR)
/datadec.1
clean
:
/bin/rm
-f
*
.o a.out core
$(EXECS)
lint
:
lint_datadec lint_m2datadec
lint_datadec
:
$(datadec_srcs)
lint
$(LINTFLAGS)
$(datadec_srcs)
>
lint_datadec 2>&1
lint_m2datadec
:
$(m2datadec_srcs)
lint
$(LINTFLAGS)
$(m2datadec_srcs)
>
lint_m2datadec 2>&1
m2datadec
:
$(m2datadec_objs)
$(CC)
-g
-o
m2datadec
$(m2datadec_objs)
datadec
:
$(datadec_objs)
$(CC)
-g
-o
datadec
$(datadec_objs)
datadec.o
:
datadec.c struct.h lexer.h parser.h decs.h optimize.h
decs.o
:
decs.c struct.h decs.h
lexer.o
:
lexer.c struct.h lexer.h
m2decs.o
:
m2decs.c struct.h decs.h
optimize.o
:
optimize.h struct.h optimize.c
parser.o
:
parser.c struct.h lexer.h parser.h
struct.o
:
struct.c struct.h
datadec.o
:
struct.h lexer.h parser.h decs.h optimize.h
decs.o
:
struct.h decs.h
lexer.o
:
struct.h lexer.h
optimize.o
:
optimize.h struct.h
parser.o
:
struct.h lexer.h parser.h
struct.o
:
struct.h
README
View file @
69792c72
...
...
@@ -21,7 +21,6 @@ illist = nil
idtree = leaf( string id, illist l )
| node( idtree left, idtree right )
;
</pre>
What does this mean?
The first rule declares that an intlist can take two basic "shapes" -
...
...
c-datadec.man
View file @
69792c72
...
...
@@ -43,10 +43,10 @@ The simplest use is to prepare an input file, such as
which might (for example) contain:
.nf
TYPE {
IntList = Null or Cons( int first, IntL
ist next );
ILList = Null or Cons( IntList first, ILL
ist next );
IdTree = L
eaf( string id )
or Node( IdTree left, IdT
ree right );
intlist = nil or cons( int first, intl
ist next );
illist = nil or cons( intlist first, ill
ist next );
idtree = l
eaf( string id )
or node( idtree left, idt
ree right );
}
.fi
To generate C code implementing these types, invoke:
...
...
@@ -100,7 +100,7 @@ Similarly, the contents of the
.I "global"
section are placed in the C file,
again with `@@' being used to split the global section into "top of file" and
"bottom
at
file" pieces.
"bottom
of
file" pieces.
.PP
Similarly, the contents of the
...
...
@@ -149,7 +149,9 @@ Each type name is simply an identifier.
also generates routines to write each type to an open FILE *.
The method of printing each shape is governed by the presence or absence
of a print rule. If no print rule is given, the constructor name is printed,
and then each parameter is written out using the appropriate print routine.
then an open bracket,
then each parameter is written out using the appropriate print routine,
with commas separating the parameters, then a close bracket.
.PP
If a print rule is given, each print element
...
...
@@ -162,26 +164,24 @@ whereas a number (eg. 4) means that the
.PP
For example, we could augment the
.I "
IdT
ree"
.I "
idt
ree"
type from the example given above with print rules:
.nf
TYPE {
IdTree = Leaf( string id )
"leaf(" 1 ")"
or Node( IdTree left, IdTree right ) "node(" 1 ",\\n" 2 "
)";
idtree = leaf( string id )
"leaf(" 1 ")"
or node( idtree left, idtree right ) "node( l=" 1 ", r=" 2 "
)";
}
.fi
.PP
Now, an
IdT
ree constructed as
Now, an
idt
ree constructed as
.nf
Node( Leaf( "hello" ), Node( Leaf( "there
" ) ) )
node( leaf( "hello" ), node( leaf( "there" ), leaf( "how are you
" ) ) )
.fi
would print as:
.nf
node(leaf("hello"),
.br
node(leaf("there")))
node( l=leaf("hello"), r=node(l=leaf("there"),r=leaf("how are you")))
.fi
.SH SEE ALSO
...
...
@@ -189,14 +189,19 @@ node(leaf("there")))
LALR, REX, Miranda Language Definition.
.fi
.SH MISSING FEATURES
I must implement the missing free_TYPE functions sometime.
.PP
A cool extra would be a sprint_TYPE function to print into a string.
This should be a trivial modification on the code that prints to a file,
of course we don't know how long the generated string will need to be.
.SH BUGS
Some single letter typenames (eg. "f" or "p") could clash with internal
parameter names in the print routines, leading to syntax errors when you
compile the files generated by datadec.
.PP
Someday I'll get it to free up the types too!
.PP
And, finally, one day I'll have to write the C++ and Java versions :-)
.SH "AUTHOR"
Duncan C. White, D.White@
surrey
.ac.uk.
Duncan C. White, D.White@
imperial
.ac.uk.
decs.c
View file @
69792c72
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "struct.h"
#include "decs.h"
...
...
@@ -85,6 +86,16 @@ static void line( fmt, a, b, c, d ) char *fmt; long a, b, c, d;
}
static
void
literalline
(
mesg
)
char
*
mesg
;
{
int
i
;
for
(
i
=
numtabs
;
i
;
i
--
)
fputc
(
'\t'
,
outfile
);
fputs
(
mesg
,
outfile
);
nl
();
}
void
make_declns
(
exports
,
globals
,
begin
,
d
,
base
)
declnlist
d
;
char
*
exports
,
*
globals
,
*
begin
,
*
base
;
{
printf
(
"datadec: Making data declarations in %s.[ch]
\n
"
,
base
);
...
...
@@ -154,7 +165,7 @@ static void h_declns( base, exports, init, d ) char *base, *exports; BOOL init;
{
nl
();
line
(
"/* Remaining contents of EXPORT section */"
);
line
(
exportptr
);
li
teralli
ne
(
exportptr
);
nl
();
}
...
...
@@ -182,7 +193,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
line
(
" * Automatically Generated by DataDec"
);
line
(
" */
\n
"
);
line
(
"#include <stdio.h>"
);
line
(
"#include <
malloc
.h>"
);
line
(
"#include <
stdlib
.h>"
);
line
(
"#include
\"
%s.h
\"\n\n
"
,
base
);
globalptr
=
globals
;
...
...
@@ -213,7 +224,7 @@ static void c_declns( base, globals, begin, d ) char *base, *globals, *begin; de
nl
();
nl
();
line
(
"/* Remaining contents of GLOBAL section */"
);
line
(
globalptr
);
li
teralli
ne
(
globalptr
);
nl
();
}
...
...
@@ -868,6 +879,10 @@ static void print_all_params( d, s ) declnlist d; shapelist s;
for
(
p
=
s
->
params
;
p
!=
NULL
;
p
=
p
->
next
)
{
print_param
(
s
,
p
,
d
->
Union
);
if
(
p
->
next
!=
NULL
)
{
line
(
"fputc( ',', f );"
);
}
}
if
(
s
->
params
)
{
...
...
optimize.c
View file @
69792c72
...
...
@@ -140,7 +140,6 @@ static BOOL tail_optimize( d ) decln d;
shapelist
s
;
printlist
pl
;
param
p
;
int
n
;
for
(
s
=
d
->
shapes
;
s
!=
NULL
;
s
=
s
->
next
)
{
...
...
parser.c
View file @
69792c72
...
...
@@ -27,7 +27,7 @@
#include <stdio.h>
#include <string.h>
#include <
malloc
.h>
#include <
stdlib
.h>
#include "struct.h"
#include "lexer.h"
#include "parser.h"
...
...
test/Makefile
View file @
69792c72
#INC = /vol/lab/include
CFLAGS
=
-g
-UDEBUGGING
TESTEXECS
=
ctest
AUTOCRAP
=
mtest.
*
mx.
*
ctest.
*
cx.?
AUTOCRAP
=
ctest.
*
cx.[och]
all
:
$(TESTEXECS)
...
...
@@ -11,21 +10,6 @@ clean:
cx.c cx.h
:
cdata.in ../datadec
../datadec cx cdata.in
cx.o
:
cx.c cx.h
ctest.o
:
ctest.c cx.h
ctest
:
ctest.o cx.o
$(CC)
-o
ctest ctest.o cx.o
mx.def mx.mod
:
m2data.in ../src/m2datadec
../src/m2datadec mx m2data.in
mx.sym
:
mx.def
mx.o
:
mx.mod mx.sym
mtest.o
:
mtest.mod mx.sym
mtest
:
mtest.o mx.o
m2c
$(M2FLAGS)
$(M2LINKFLAGS)
-o
mtest
-e
mtest
ctest
:
ctest.o cx.o
cx.o
:
cx.h
ctest.o
:
cx.h
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment