Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8077009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:23:09+00:00 2026-06-05T15:23:09+00:00

I am New to Ada and I am attempting to convert the code in

  • 0

I am New to Ada and I am attempting to convert the code in a compiler tutorial on Recursive Decent Parser to Ada. Porting the tutorial, “Let’s Build a Compiler” by Jack W Crenshaw has been a favorite way for me to learn many languages. I had everything working up to Chapter three, using single character tokens. The move to multi-character tokens has been troublesome.

I have code something like this sudo code:

procedure GetName is
  token: Ada.Strings.Unbounded;
begin
  while IsAlNum(Look) loop
    Token := Token & Look;
    GetChar;
  end loop
end GetName;

Now I know Ada intended for strings to be static. But I need to be able to concatenate each new character taken from the input to the collection of characters in Token. Look is the global look-ahead value (the last character inputted).

Thanks for you help. Also, are there any good Ada tutorials or recipes sites on the net? I’ve read Lovelace and Ada for C programmers. The Ada RMs are a bit formal and only show specifications not use…

Thanks again!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T15:23:10+00:00Added an answer on June 5, 2026 at 3:23 pm

    At the end of this question, it looks like you are asking for help in Ada string processing.

    Yes, Ada strings are indeed best handled as static strings, rather than resizable buffers. There are three typcial ways to deal with this.

    The first is to make a really big String buffer, with a separate Natural variable to hold the logical length of the string. This is kind of a pain, and is somewhat error prone, but is at least faster than C’s method of constantly scanning for a null at the end of the buffer.

    The second is to just punt and use Ada.Strings.Unbounded.Unbounded_String. This is what most folks do, as it is easiest if you are used to thinking of things in a procedural way.

    The third, (which I prefer when possible) is to handle your strings functionally. The main insight you need here is that Ada Strings are indeed static, but you can control their lifetime, and you can dynamically make static strings whenever you want, if you program functionally.

    For instance, I can create a new Token string of whatever length I want (with theoretically infinite lookahead) by doing something like the following:

    function Matches_Token (Scanned : String) return boolean;  --// Returns true if the given string is a token
    function Could_Match_Longer (Scanned : String) return boolean; --// Returns true if the given string could be part of a larger token.
    function Get_Next_Char return Character;  --// Returns the next character from the stream
    procedure Unget; --// Puts the last character back onto the stream
    procedure Advance (Amount : Natural); --// Advance the stream pointer the given amount
    function Longest_Matching_Token (Scanned : String) return String is
        New_Token : constant String := Scanned & Get_Next_Char;
    begin
        --// Find the longest token a further scan can match
        if Could_Match_Longer(New_Token) then
            declare 
                LMT : constant String := Longest_Matching_Token (New_Token);
            begin
                if LMT /= "" then
                    unget;
                    return LMT;
                end if;
            end;
        end if;
    
        --// See if this string at least matches.
        if Matches_Token(New_Token) then
            unget;
            return New_Token;
        else
            unget;
            return "";
        end if;
    end Build_Token;
    
    function Get_Next_Token return String is
        Next_Token : constant String := Build_Token("");
    begin
        Advance (Next_Token'length);
        return Next_Token;
    end Get_Next_Token;
    

    This isn’t always the most efficient method of string handling (too much stack usage), but it is often the easiest.

    In practice, scanning and parsing is actually kind of a special-case application, where ugly things one typically avoids, like buffers (method 1) and gotos, are often advisable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm new to Ada, and I'm attempting to write a kernel in it,
I'm very new to Ada and one thing that I find hard to grasp
Being new to Ada, I'm exploring its syntax and rules and I would like
I'm very new to Ada and was trying to see if it offers double
I'm still new to the Ada programming world so forgive me if this question
I'm very new to Ada, and I'm trying to do some simple work with
I recently updated to a new version of the GNAT compiler.. I am trying
I am attempting to execute a stored proc in asp.net in the code behind.
conn = new SqlConnection(@Data Source=ASHISH-PC\SQLEXPRESS; initial catalog=bank; integrated security=true); ada = new SqlDataAdapter(select total_amount
I know this can be done in Ada but I'm new to Java and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.