caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Zhu Ping <zhuping@comp.nus.edu.sg>
To: Gerd Stolpmann <info@gerd-stolpmann.de>
Cc: matthieu.dubuget@laposte.net, caml-list@yquem.inria.fr,
	Anil Madhavapeddy <anil@recoil.org>
Subject: Re: [Caml-list] Using Frontc
Date: Thu, 24 Nov 2005 14:12:44 +0800	[thread overview]
Message-ID: <438559DC.5020906@comp.nus.edu.sg> (raw)
In-Reply-To: <4373.192.168.1.2.1132566896.squirrel@gps.dynxs.de>

Dear Gerd Stolpmann

Thank you very much for recommending GODI. I have successfully installed
GODI, compiled and linked my code with the FrontC library.

My main program *main.ml* is as following:
open Frontc
let parse_result = Frontc.parse_file "/home/dreamer/code/sample1.c" stdout;;

The sample C code sample1.c is:
int main(int base, int expon)
{
int accum = 1;
while (expon > 0) {
accum = base * accum;
expon = expon - 1;
}
return(accum);
}


I performed the compilation and linking by executing the following two
commands:
ocamlc -c -I /opt/godi/lib/ocaml/pkg-lib/FrontC main.ml
ocamlc -o main /opt/godi/lib/ocaml/std-lib/unix.cma -I
/opt/godi/lib/ocaml/pkg-lib/FrontC frontc.cma main.cmo

To display the parsing result explicitly I built my toplevel:
ocamlmktop -o mytoplevel /opt/godi/lib/ocaml/std-lib/unix.cma -I
/opt/godi/lib/ocaml/pkg-lib/FrontC frontc.cma
./mytoplevel
#directory "/home/dreamer/code/";;
#directory "/opt/godi/lib/ocaml/pkg-lib/FrontC/";;
#use "main.ml";;

The output is:

/home/dreamer/code/sample1.c[1] Invalid symbol: int main(int base, int
expon)
/home/dreamer/code/sample1.c[2] Invalid symbol: {
/home/dreamer/code/sample1.c[3] Invalid symbol: int accum = 1;
/home/dreamer/code/sample1.c[4] Invalid symbol: while (expon > 0) {
/home/dreamer/code/sample1.c[5] Invalid symbol: accum = base * accum;
/home/dreamer/code/sample1.c[6] Invalid symbol: expon = expon - 1;
/home/dreamer/code/sample1.c[7] Invalid symbol: }
/home/dreamer/code/sample1.c[8] Invalid symbol: return(accum);
/home/dreamer/code/sample1.c[9] Invalid symbol: }
val parse_result : Frontc.parsing_result =
PARSING_OK
[Cabs.FUNDEF
((Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
("main",
Cabs.PROTO
(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN),
[(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
("base", Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), [], Cabs.NOTHING));
(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
("expon", Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), [],
Cabs.NOTHING))],
false),
[], Cabs.NOTHING)),
([Cabs.DECDEF
(Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), Cabs.NO_STORAGE,
[("accum", Cabs.INT (Cabs.NO_SIZE, Cabs.NO_SIGN), [],
Cabs.CONSTANT (Cabs.CONST_INT "1"))])],
Cabs.SEQUENCE
(Cabs.WHILE
(Cabs.BINARY (Cabs.GT, Cabs.VARIABLE "expon",
Cabs.CONSTANT (Cabs.CONST_INT "0")),
Cabs.BLOCK
([],
Cabs.SEQUENCE
(Cabs.COMPUTATION
(Cabs.BINARY (Cabs.ASSIGN, Cabs.VARIABLE "accum",
Cabs.BINARY (Cabs.MUL, Cabs.VARIABLE "base",
Cabs.VARIABLE "accum"))),
Cabs.COMPUTATION
(Cabs.BINARY (Cabs.ASSIGN, Cabs.VARIABLE "expon",
Cabs.BINARY (Cabs.SUB, Cabs.VARIABLE "expon",
Cabs.CONSTANT (Cabs.CONST_INT "1"))))))),
Cabs.RETURN (Cabs.VARIABLE "accum"))))]


Why the parsing result is correct in the presence of lexing errors?

Thank you very much for your help:)



Gerd Stolpmann wrote:

>>The pity now is the CIL format seems too complicated for me. I like the data structure defined in an earlier version of FrontC
>>(http://casse.hugues.free.fr/projects/frontc.html) better:). However I still have problems in compiling FrontC sources downloaded from the site
>>http://casse.hugues.free.fr/projects/frontc.html. Did anyone successfullyinstall FrontC in Linux/Unix?
>>    
>>
>FrontC is available in GODI, http://godi.ocaml-programming.de. This is probably the simplest way to install it. Furthermore, this also simplifies
>using libraries, as GODI supports findlib for all libraries, i.e. you just say
>
>ocamlfind ocamlc -package frontc -c your_module.ml
>
>and get rid of the .cma nightmare.
>
>Gerd
>


  reply	other threads:[~2005-11-24  6:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-20  8:44 Zhu Ping
2005-11-20 12:37 ` Matthieu Dubuget
2005-11-21  8:41   ` Zhu Ping
2005-11-21  9:54     ` Gerd Stolpmann
2005-11-24  6:12       ` Zhu Ping [this message]
2005-11-24 10:25         ` skaller
  -- strict thread matches above, loose matches on Subject: below --
2005-11-18  9:22 Zhu Ping
2005-11-18  9:52 ` [Caml-list] " Anil Madhavapeddy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=438559DC.5020906@comp.nus.edu.sg \
    --to=zhuping@comp.nus.edu.sg \
    --cc=anil@recoil.org \
    --cc=caml-list@yquem.inria.fr \
    --cc=info@gerd-stolpmann.de \
    --cc=matthieu.dubuget@laposte.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).