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

  • Home
  • SEARCH
  • 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 8641065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:25:52+00:00 2026-06-12T11:25:52+00:00

Basically this is a program which I take a text file with some code

  • 0

Basically this is a program which I take a text file with some code and take each char and make it a token or make the other chars that are included in it become a token like a variable. That part works I know because I have used this code for another project and I’m just reusing. The problem is that when I am trying to get the token the scanner.c create and return it to another file it is saying I have an error “error: expected identifier or ‘(’ before ‘TOKEN’”. I cant figure out where the error is. Here is my scanner.c file and I also posted the .h file where the token is defined.

#include <stdio.h>
#include <string.h>
#include "parser.h"


*TOKEN parseString(char *token);
*TOKEN parseChar(char token);

*TOKEN scan(FILE *input_file)
{    
   int stateTable[3][122];
   int i = 0;
   int j = 0;
   for( i=0; i < 3; i++)//init to 0
   {
      for ( j=0; j < 122; j++)
      {
         stateTable[i][j] = 0;
      }
   }

   for( i=48; i < 57; i++)//all numbers [0-9]
   {
      stateTable[1][i] = 3;
      stateTable[3][i] = 3;
   }

   for( i=97; i < 122; i++)//all alpha [a-z]
   {
      stateTable[1][i] = 2;
      stateTable[2][i] = 2;
   }

   stateTable[1][10] = 1;// \n
   stateTable[1][32] = 1;// space
   stateTable[1][40] = 1;// (
   stateTable[1][41] = 1;// )
   stateTable[1][42] = 1;// *
   stateTable[1][43] = 1;// +
   stateTable[1][45] = 1;// -
   stateTable[1][47] = 1;// /
   stateTable[1][59] = 1;// ;
   stateTable[1][61] = 1;// =

   int state = 0;
   int index = 0;
   char temp[20];
   char token;


      token = fgetc(input_file);
      state = stateTable[1][(int) token];

      if (state == 2 || state == 3)//num or alpha
      {
         temp[index] = token;
         index++;
          scan(input_file);
      }
      else if (state = 1)
      { 
            if (index >= 1)//digit or identifier
            {
                temp[index] = '\0';
                return parseString(&temp[0]);
                temp[0] = '\0';
            }   
            else
               return parseChar(token);

            if(token == ';' ||token == ')')
                return parseChar(token);

            index = 0;
      }

}

*TOKEN parseString(char *token)
{
    TOKEN *temp = malloc(sizeof(TOKEN));
    if(strcmp("repeat",token) == 0)
        &temp.type = 4;
    else if(strcmp("print",token) == 0)
        &temp.type = 5;
    else if(isdigit(token[0]))
    {
        &temp.type = 12;
        &temp.attribute = token[0];
    }
    else if(strcmp(token, "") != 0)
    {
        &temp.type = 10;
        &temp.attribute = token;
    }

    return temp;
}

*TOKEN parseChar(char token)
{   
    TOKEN *temp = malloc(sizeof(TOKEN));
    if(token == '+' || token == '-')
    {
        &temp.type = 14;
        &temp.attribute = token;

    }
    else if(token == '/' || token == '*' || token == '%')
    {
        &temp.type = 13;
        &temp.attribute = token;
    }
    else if(token == '=')
        &temp.type = 3;
    else if(token == ';')
        &temp.type = 17;
    else if(token == '(')
        &temp.type = 15;
    else if(token ==')')
        &temp.type = 16;

    return temp;

}

Here’s the parser.h file that has the TOKEN in it described.

#ifndef _parser_h
#define _parser_h


typedef enum token_type
{
    Id,
    keyword,
    num,
    addOp,
    multOp,
    assignment,
    semicolon,
    lparen,
    rparen

}TOKEN_TYPE;

typedef struct token{
    TOKEN_TYPE type;
    char* attribute;
}TOKEN;

typedef enum node_type
{
    PROGRAM,
    statement,
    assignStmt,
    repeatStmt,
    printStmt,
    exp,
    term,
    factor
}NODE_TYPE;

#endif

It just keeps saying where ever I declare the function name that I am missing a ‘(‘ before the TOKEN.

Any help would be great.

  • 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-12T11:25:53+00:00Added an answer on June 12, 2026 at 11:25 am

    should be
    TOKEN* parseChar(char token)
    instead of
    *TOKEN parseChar(char token)

    and
    temp->type = 4;
    instead of
    &temp.type = 4;

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

Sidebar

Related Questions

So basically this code was working fine before. I had some computer issues and
I have (basically) this code - <script type=text/javascript language=javascript> $(document).ready(function() { $(#loadDiv).load(mypage.html, function(){ alert($(#someText).text())
Basically this is my code: bay=$(prog -some flags) while [ $bay = Another instance
Basically I've written this program to check for strings. I've used socket method for
Basically i have a problem with this timer program I am trying to put
So basically this code: class A { }; class B { B (const B&
Basically what I'm trying to achieve is a program which allow users to connect
I have a third party program which basically allows users to send email and
I wrote a short C++ program to do XOR encryption on a file, which
Here's the thing... I have 2 GUI programs. A Menu Program,which is basically a

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.