[SparForte][Banner]
[Top Main Menu] Intro | Tutorials | Reference | Packages | Examples | Contributors   [Back Page]      [Next Page]  

GCC Tutorial: Compiling SparForte Scripts

Complete instructions for converting a SparForte AdaScript script into Ada and compiling it with GCC is beyond the scope of this manual. However, here's are some tips.

Getting GCC Ada/GNAT

GCC Ada is availble for most version of Linux. If you need to, you can compile GCC from sources and activate Ada support. AdaCore, the company responsible for GCC Ada, also as a standalone GPL version and commerical versions available from their web site. Likewise, there are other Ada compiler vendors for other operating systems.

Minimize the Differences

AdaScript is not completely compatible with Ada 2005 because Ada 2005 was never designed as a language for writing scripts.  Changes must be made to your script, but the changes should be minimal and easily made.

First, compile your script with the pragma ada_95 directive.  This will report most non-Ada features as an error.  pragma ada_95 disallows the following in scripts:

  • use of @ - use the full variable name instead
  • use of % - use an intermediate variable
  • mixed boolean operators - that is, mixing "and", "or" and "xor" without parentheses
  • universal types - convert to specific types and use type casting where necessary
  • command types - using constant strings
  • ? - use put_line
  • pipelines - separate into individual commands and use I/O redirection
  • use of return to return status codes - use the command_line package
  • Bourne shell parameters on external commands - use AdaScript syntax instead

Use a Main Procedure

Second, make sure your script is contained in a procedure block (see "script structure" below).

Deal with External Commands

Third, external commands will have to be rewritten as Ada procedures or calls to GNAT.OS_Lib.Spawn or the POSIX system() call.  You will have to import system() to use it.

Final Steps

There are still differences you may encounter such as the package names for certain functions, incompatibility with string types, use of with/use statements, or Ada attributes.

To test your script, compile the script.  To generate Java byte code to run on a Java Virtual Machine, use the JGNAT compiler instead of GNAT. Or use A# to generate .NET code.

To learn more about GCC Ada, read The Big Online Book of Linux Ada Programming.

Study Questions

  1. Name non-Ada 95 features that "pragma ada_95" doesn't disable.
 
[Right Submenu]

 Command Prompt Tutorial 1: SparForte as a Calculator

 Command Prompt Tutorial 2: Basic Shell Commands

 Command Prompt Tutorial 3: Working with Databases

 Script Tutorial 1: Basic Commands Scripts

 Script Tutorial 2: Intermediate Program Scripts

 Script Tutorial 3: Data Types

 Template Tutorial 1: Basic Templates

 Template Tutorial 2: Intermediate Templates

 GCC Tutorial: Compiling SparForte Scripts

 Debugging Tutorial - Using the SparForte Debugger

 Creating a Profile Script

 Calling SparForte from C: A Tutorial

 SparForte For PHP Developers

 SparForte Best Practices

[Back to Top] Back To Top [Small Forte Symbol]