simple programs -> one file with gps 2008 (gpl)?

This is a discussion on simple programs -> one file with gps 2008 (gpl)? within the ADA forums in Programming Languages category; Hi, I'm new to Ada and therefore I'm digging through the book "Programming in Ada 2005". In Chapter 4 on Page 57 the autor states: "Complete simple Programms might be presented in a single file." Furthermore he outlines the structure of how such a simple program might look. package x is -- spec and body of Objects with x; use x; package xx is -- with xx; use xx; .... procedure Main is... I typed a program with similar structure into GPS 2008 (GPL) and while trying to compile the GPS compiler aborted with the following message "end of file ...

Go Back   Application Development Forum > Programming Languages > ADA

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-08-2008, 03:12 PM
Marcus Lauster
Guest
 
Default simple programs -> one file with gps 2008 (gpl)?

Hi,

I'm new to Ada and therefore I'm digging through the book "Programming
in Ada 2005". In Chapter 4 on Page 57 the autor states: "Complete simple
Programms might be presented in a single file." Furthermore he outlines
the structure of how such a simple program might look.

package x is -- spec and body of Objects
with x; use x;
package xx is --
with xx; use xx;
....
procedure Main is...

I typed a program with similar structure into GPS 2008 (GPL) and while
trying to compile the GPS compiler aborted with the following message

"end of file expected, file can have only one compilation unit"

So my question is how to convince the underlying compiler of GPS that my
program is a simple program.

Regards

Reply With Quote
  #2  
Old 08-08-2008, 04:25 PM
Jeffrey R. Carter
Guest
 
Default Re: simple programs -> one file with gps 2008 (gpl)?

Marcus Lauster wrote:
>
> I'm new to Ada and therefore I'm digging through the book "Programming
> in Ada 2005". In Chapter 4 on Page 57 the autor states: "Complete simple
> Programms might be presented in a single file." Furthermore he outlines
> the structure of how such a simple program might look.


The operative word here is "might". There's not much in the ARM about source
files or the relationship of compilation units to source files. There's nothing
in the ARM to prevent a compiler from accepting multiple compilation units in a
single file, but there's also nothing to require it.

GNAT, the compiler you're using, does not accept multiple compilation units in a
single file. To ease migration of code from other compilers that do, it provides
the gnatchop program that will break a file containing multiple compilation
units into multiple files, each containing a single unit.

> I typed a program with similar structure into GPS 2008 (GPL) and while
> trying to compile the GPS compiler aborted with the following message


GPS is an IDE, not a compiler. By default it uses the GNAT compiler, so no doubt
you're using GNAT 2008.

> So my question is how to convince the underlying compiler of GPS that my
> program is a simple program.


I'm not aware of any way to get GNAT to accept multiple compilation units in a
single file.

--
Jeff Carter
"We call your door-opening request a silly thing."
Monty Python & the Holy Grail
17
Reply With Quote
  #3  
Old 08-08-2008, 04:54 PM
Marcus Lauster
Guest
 
Default [Solved] Re: simple programs -> one file with gps 2008 (gpl)?

Jeffrey R. Carter schrieb:
> Marcus Lauster wrote:
>>
>> [...] Furthermore he
>> outlines the structure of how such a simple program might look.

>
> The operative word here is "might". [...]


In my youthful enthusiasm I didn't process this word correctly.

>> I typed a program with similar structure into GPS 2008 (GPL) and while
>> trying to compile the GPS compiler aborted with the following message

>
> GPS is an IDE, not a compiler.[...]


I know.

>> So my question is how to convince the underlying compiler of GPS that
>> my program is a simple program.

>
> I'm not aware of any way to get GNAT to accept multiple compilation
> units in a single file.


Good to know and thanks for your time and the appropriate information.

Regards
Reply With Quote
  #4  
Old 08-08-2008, 05:29 PM
Ed Falis
Guest
 
Default Re: simple programs -> one file with gps 2008 (gpl)?

On Fri, 08 Aug 2008 16:25:44 -0400, Jeffrey R. Carter
<spam.jrcarter.not@spam.acm.org> wrote:

> I'm not aware of any way to get GNAT to accept multiple compilation
> units in a single file.


There's a description somewhere in the GNAT User Guide of how to do this.
More trouble than it's worth unless you have a compelling CM/process need
for it.
Reply With Quote
  #5  
Old 08-08-2008, 06:44 PM
amado.alves@gmail.com
Guest
 
Default Re: simple programs -> one file with gps 2008 (gpl)?

> I'm new to Ada and therefore I'm digging through the book "Programming
> in Ada 2005".


Welcome!

> "Complete simple programms might be presented in a single file."


Probably this was just to stress that the language is not file-
oriented like C or Java.

However, for better and for worse, GNAT is a file-oriented compiler.

Like others have said (and yet others seem to ignore) a tool Gnatchop
exists that generates the files from an Ada text (usually from an .ada
file) Eventually you use this tool to start development from an Ada
text. But normally you only do this once at the start of development,
because compiler messages will point to the 'new' files, so it's more
convenient to edit them instead of the old, and there is no tool to
keep the new and the old in sync automatically.

If you use GPS then probably you will use the respective "project"
tools and the "visual" programming style to "manage" the files. Beware
of visual spaggetti...
Reply With Quote
  #6  
Old 08-10-2008, 06:25 PM
Robert A Duff
Guest
 
Default Re: simple programs -> one file with gps 2008 (gpl)?

amado.alves@gmail.com writes:

> Like others have said (and yet others seem to ignore) a tool Gnatchop
> exists that generates the files from an Ada text (usually from an .ada
> file) Eventually you use this tool to start development from an Ada
> text. But normally you only do this once at the start of development,
> because compiler messages will point to the 'new' files, so it's more
> convenient to edit them instead of the old,...


The -r switch to gnatchop causes error messages to refer to the original
pre-chopped file. The -w and -p switches are also quite useful -- look
at the docs.

I agree that GNAT's bias toward one-comp-unit-per-file is an annoying
feature. A minor annoyance at most, since that's usually what you want
anyway.

- Bob
Reply With Quote
  #7  
Old 08-11-2008, 04:44 AM
Lucretia
Guest
 
Default Re: simple programs -> one file with gps 2008 (gpl)?

On Aug 8, 9:25*pm, "Jeffrey R. Carter"
<spam.jrcarter....@spam.acm.org> wrote:
> Marcus Lauster wrote:
>
> > I'm new to Ada and therefore I'm digging through the book "Programming
> > in Ada 2005". In Chapter 4 on Page 57 the autor states: "Complete simple
> > Programms might be presented in a single file." Furthermore he outlines
> > the structure of how such a simple program might look.

>
> The operative word here is "might". There's not much in the ARM about source
> files or the relationship of compilation units to source files. There's nothing
> in the ARM to prevent a compiler from accepting multiple compilation units in a
> single file, but there's also nothing to require it.


While the AARM does not state anything about how a compilation unit
and a file relate to each other, it does state that a compiler should
take a number of compilation units (see 10.1), this is even specified
in the EBNF (appendix P):

10.1.1:
compilation::= {compilation_unit}

GNAT provides this using gnatchop, there are messages from Robert
Dewar on this group about this.

Thanks,
Luke.
Reply With Quote
  #8  
Old 08-12-2008, 06:21 AM
amado.alves@gmail.com
Guest
 
Default Re: simple programs -> one file with gps 2008 (gpl)?

> > file) Eventually you use this tool to start development from an Ada
> > text. But normally you only do this once at the start of development,
> > because compiler messages will point to the 'new' files, so it's more
> > convenient to edit them instead of the old,...

>
> The -r switch to gnatchop causes error messages to refer to the original
> pre-chopped file.


Indeed! I stand corrected. This is wonderful. You can work based
on .ada files :-)
Thanks for pointing this out.
Reply With Quote
  #9  
Old 08-12-2008, 01:03 PM
Simon Wright
Guest
 
Default Re: simple programs -> one file with gps 2008 (gpl)?

amado.alves@gmail.com writes:

>> > file) Eventually you use this tool to start development from an Ada
>> > text. But normally you only do this once at the start of development,
>> > because compiler messages will point to the 'new' files, so it's more
>> > convenient to edit them instead of the old,...

>>
>> The -r switch to gnatchop causes error messages to refer to the original
>> pre-chopped file.

>
> Indeed! I stand corrected. This is wonderful. You can work based
> on .ada files :-)
> Thanks for pointing this out.


If you are an Emacs user, I have written a minor mode (gnatchop-mode) so
that every time you save the big source file gnatchop (-r) is run on it.

Um, I guess I should offer it to ada-mode -- tried that when AdaCore
were running it, it wasn't general enough for them (but works for me!)

;; gnatchop.el
;; Copyright (C) 2001 Simon Wright <simon@pushface.org>.
;; $Id: gnatchop.el,v 1.1 2001/12/01 06:58:43 simon Exp $

;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation; either version 2 of the License, or
;; (at your option) any later version.

;; This program is distributed in the hope that it will be useful, but
;; WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
;; General Public License for more details.

;; Minor mode for use in Ada buffers that don't have the correct file name
;; for use with GNAT, and which therefore need to be "gnatchop"'d before
;; compilation.

;; Reference: Writing GNU Emacs Extensions by Bob Glickstein (O'Reilly
;; & Associates, Inc, 1997).

(defvar gnatchop-mode nil
"Mode variable for gnatchop minor mode.")

(defun gnatchop-mode (&optional arg)
"Gnatchop minor mode."
(interactive "P")
(make-variable-buffer-local 'gnatchop-mode)
(make-local-hook 'after-save-hook)
(setq gnatchop-mode
(if (null arg)
(not gnatchop-mode)
(> (prefix-numeric-value arg) 0)))
(if gnatchop-mode
(add-hook 'after-save-hook 'gnatchop-file)
(remove-hook 'after-save-hook 'gnatchop-file))
)

(defun gnatchop-file ()
"Run gnatchop on current buffer's file after save."
(if gnatchop-mode
(progn
(message (concat "chopping " (buffer-file-name)))
(let (compilation-read-command
(compilation-buffer-name-function
(lambda (mode) "*Gnatchop*")))
(compile (concat "gnatchop -w -r " (buffer-file-name)))
(bury-buffer (get-buffer "*Gnatchop*")))))
)

(if (not (assq 'gnatchop-mode minor-mode-alist))
(setq minor-mode-alist
(cons '(gnatchop-mode " Chop")
minor-mode-alist)))
Reply With Quote
  #10  
Old 08-13-2008, 08:45 AM
Stephen Leake
Guest
 
Default Re: simple programs -> one file with gps 2008 (gpl)?

Simon Wright <simon.j.wright@mac.com> writes:

> If you are an Emacs user, I have written a minor mode (gnatchop-mode) so
> that every time you save the big source file gnatchop (-r) is run on it.
>
> Um, I guess I should offer it to ada-mode -- tried that when AdaCore
> were running it, it wasn't general enough for them (but works for
> me!)


As the maintainer of Ada mode, I think this is more properly done in a
Makefile.

But it is possible to use Emacs Ada mode for pure Ada projects without
a Makefile, so I suppose it would make sense to include it as an
option.

> ;; gnatchop.el
> ;; Copyright (C) 2001 Simon Wright <simon@pushface.org>.
> ;; $Id: gnatchop.el,v 1.1 2001/12/01 06:58:43 simon Exp $


Since Ada mode is part of Emacs, you would need to assign copyright to
the Free Software Foundation; email me off list about this.

> ;; Minor mode for use in Ada buffers that don't have the correct file name
> ;; for use with GNAT, and which therefore need to be "gnatchop"'d before
> ;; compilation.


"wrong file name" does not require gnatchop (you can specify other
names in the GNAT project file), only "multiple compilation units".

We should move other discussion about this to the Emacs Ada mode
mailing list hosted at
http://stephe-leake.org/mailman/list...ephe-leake.org

--
-- Stephe
Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 09:25 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.