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 8404831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:42:01+00:00 2026-06-09T22:42:01+00:00

I have several questions so I’ll put numbers in comments so that the questioned

  • 0

I have several questions so I’ll put numbers in comments so that the questioned line is easier to find.

[1] How can char *p be assigned to token variable which in fact doesn’t exist?

[2] Why we don’t put ‘\0’ here, what is done in every other if condition?

[3] Why we copy () into token string only? And we don’t do that in the case of [] and alphanumeric chars ?

[4] Those return commands are weird IMO -> first: why does it not look just like this return PARENS, and second: when it returns tokentype = ‘(‘ it is a char so why the function gettoken is declared as returning integers ?

[5] SUPPOSING part: let input be ( a b c ) then: ( causes function to return tokentype ‘(‘ a b c enter if condition (isalpha(C)) and the last ) exits that condition causing ungetch. Does it go along main else condition then? Is my walkthrough correct?

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define MAXTOKEN 100
enum { NAME, PARENS, BRACKETS };
void dcl(void);
void dirdcl(void);
int gettoken(void);
int tokentype; /*type of last token  ALSO [4] !!! */
char token[MAXTOKEN]; /*last token string */
char name[MAXTOKEN]; /*identifier name */
char datatype[MAXTOKEN]; /*data type = char, int, etc. */
char out[1000];

main() /* convert declaration to words */
{
    while (gettoken() != EOF) {    /* 1st token on line */
        strcpy(datatype, token);   /* is the datatype */
        out[0] = '\0';
        dcl();            /* parse rest of line */
        if (tokentype != '\n')
            printf("syntax error\n");
        printf("%s: %s %s\n", name, out, datatype);
    }
    return 0;
}

int gettoken(void) /* return next token */
{
    int c, getch(void);
    void ungetch(int);
    char *p = token;        /* [1] */
    while ((c = getch()) == ' ' || c == '\t')
        ;
    if (c == '(') {
        if ((c = getch()) == ')') {
            strcpy(token, "()");            /* [2][3] */
            return tokentype = PARENS;           /* [4] */
        } else {
            ungetch(c);
            return tokentype = '(';
        }
    } else if (c == '[') {
        for (*p++ = c; (*p++ = getch()) != ']'; )
            ;
        *p = '\0';
        return tokentype = BRACKETS;
    } else if (isalpha(c)) {
        for (*p++ = c; isalnum(c = getch()); ) /* SUPPOSING [5] */
            *p++ = c;
        *p = '\0';
        ungetch(c);
        return tokentype = NAME;
    } else
        return tokentype = c;
}

/* dcl: parse a declarator */
void dcl(void)
{
    int ns;
    for (ns = 0; gettoken() == '*'; ) /* count *'s */
        ns++;
    dirdcl();
    while (ns-- > 0)
        strcat(out, " pointer to");
}

/* dirdcl: parse a direct declarator */
void dirdcl(void)
{
    int type;
    if (tokentype == '(') {
        dcl();
        if (tokentype != ')')
            printf("error: missing )\n");
    } else if (tokentype == NAME) /* variable name */
        strcpy(name, token);
    else
        printf("error: expected name or (dcl)\n");
    while ((type=gettoken()) == PARENS || type == BRACKETS)
        if (type == PARENS)
            strcat(out, " function returning");
        else {
            strcat(out, " array");
            strcat(out, token);
            strcat(out, " of");
        }
}

THANKS IN ADVANCE!

  • 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-09T22:42:02+00:00Added an answer on June 9, 2026 at 10:42 pm

    1) token does exist, but it’s a global variable defined as char token[MAXTOKEN];

    2) strcpy() copies the terminating 0 byte from the source, so we don’t need to do it manually

    3) that appears to be special case handling for the literal string () – some parentheses with nothing in between, as opposed to handling the case where we have ( some stuff )

    4) in accordance with (3), PARENS looks like the token type for an empty set of parentheses, while returning ( and ) separately as specific tokentypes is the case for when we have something between them

    5) not sure I follow what you’re asking, but, since there doesn’t appear to be a special case for the closing parenthesis, it appears that it takes the final else branch, returning tokentype = c

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

Sidebar

Related Questions

I have several questions concerning crawlers. Can I create a crawler that works purely
I have several questions regarding filenames and the iPod Library. I understand I can
I have several questions about properties displayed in propertyGrid i cant seem to find
I have several questions regarding forms and PHP but if I should put them
i have several questions about the blue dot that appears when i launch the
I have several questions to ask that pertains to data position and alignment in
In fact, I have several questions, which I hope, can be answered objectively. Which
I have several questions about the Android in-app billing, as I cannot find what
I have several questions: 1. What's the difference between isoMDS and cmdscale? 2. May
I have several questions concerning the controls like a button, if You could answer

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.