Ошибка expected asm or attribute before token

I am working on a project that parses a text file thats suppose to be a simple coded program. The problem is that when I try to complile the program I get this error:

In file included from driver.c:10:
parser.c: In function ‘Statement’:
parser.c:24: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
parser.c:153: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
parser.c:159: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
parser.c:167: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
parser.c:176: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
parser.c:185: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
parser.c:194: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
parser.c:201: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
parser.c:209: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
driver.c:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘{’ token
driver.c:50: error: old-style parameter declarations in prototyped function definition
driver.c:50: error: expected ‘{’ at end of input

Im not familiar with this error and not sure how to fix it.

Here is my parser.c file which the error is happening in:

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

AST_NODE* Program(AST_NODE* node);
AST_NODE* Statement(AST_NODE* node)
AST_NODE* AssignStmt(AST_NODE* node);
AST_NODE* Print(AST_NODE *node);
AST_NODE* Repeat(AST_NODE* node);
AST_NODE* Exp(AST_NODE* node);
AST_NODE* Factor(AST_NODE* node);
AST_NODE* Term(AST_NODE* node);


AST_NODE* parser(TOKEN* token,AST_NODE* node, FILE* input_file)
{
    AST_NODE temp = malloc(sizeof(AST_NODE*));

    if(token->type == Id)
    {
        temp-> tok = token;
        node -> child1 = temp;
        return node
    }else
    if(token->type == keyword)
    {
        if(strcmp(node->attribute, "print") == 0)
        {
            temp -> type = print;
            node -> child1 = temp;
            return node;
        }
        else if(strcmp(node->attribute, "repeat") == 0)
        {
            temp -> type = repeat;
            node -> child1 = temp;
            return node;
        }
        return node->prev;
    }else
    if(token->type == num)
    {

        temp->type = factor;
        temp->tok = token;
        AST_NODE temp2 = Exp(Term(temp));
        node-> child3 = temp2

        return node;//back to ID->term->exp then to either print repeat or assignment
    }else
    if(token->type == addOp)
    {
        temp-> tok = token;
        node-> child2 = temp;
        return node;
    }else
    if(token->type == multOp)
    {
        temp-> tok = token;
        node-> child2 = temp;
        return node;
    }else
    if(token->type == assignment)
    {
        temp->type = assignStmt;
        temp->tok = token; 
        node->child2 = temp;
        return node;
    }else
    if(token->type == semicolon)
    {
        temp-> type = assignStmt;
        temp-> tok = token;
        if(node->type == keyword)
        {
            node->child3 = temp;
        }else
        {
            node->child4 = temp;
        }
        return node;
    }else
    if(token->type == lparen)
    {
        temp -> tok = token;
        if(node->type == repeat)
            node->child2 = temp;
        else
            node->child1 = temp;

        return node = node->prev;
    }else
    if(token->type == rparen)
    {
        temp -> tok = token;
        if(node->type == repeat)
            node->child4 = temp;
        else
            node->child3 = temp;

        return node;
    }else if(token->type == newLine)
    {
        while(node->type != program)
        {
            node = node->prev;
        }
        return node;
    }else{

        if(token->type == Id)
        {
            AST_NODE temp2 =  AssignStmt(Program(node));
            temp->type = Id;
            temp->tok = token
            temp->prev = temp2;
            temp2-> child1 = temp;
            return temp2;
        }else if(strcmp(token->attribute,"print"))
        {

            AST_NODE temp2 =  Print(Program(node));
            temp->type = print;
            temp->tok = token
            temp->prev = temp2;
            temp2-> child1 = temp;
            return temp2;
        }else if(strcmp(token->attribute,"repeat"))
        {

            AST_NODE temp2 =  Repeat(Program(node));
            temp->type = repeat;
            temp->tok = token
            temp->prev = temp2;
            temp2-> child1 = temp;
            return temp2;
        }
        printf("error");
        return NULL;
    }


}
AST_NODE* Program(AST_NODE* node)
{
    node->type = program;
    Statement(node);
    return node;
}
AST_NODE* Statement(AST_NODE* node)
{
    AST_NODE temp = malloc(sizeof(AST_NODE*));
    temp-> type = statement;
    temp-> prev = node;
    node->child1-> temp;
    return temp;
}
AST_NODE* AssignStmt(AST_NODE* node)
{
    AST_NODE temp = malloc(sizeof(AST_NODE*));
    temp->type = assignStmt;
    temp-> prev = node;
    node->child1-> temp;
    return temp;

}
AST_NODE* Print(AST_NODE* node)
{
    AST_NODE temp = malloc(sizeof(AST_NODE*));
    temp->type = print;
    temp-> prev = node;
    node->child1-> temp;
    return node;

}
AST_NODE* Repeat(AST_NODE* node)
{
    AST_NODE temp = malloc(sizeof(AST_NODE*));
    temp->type = repeat;
    temp-> prev = node;
    node->child1-> temp;
    return node;

}
AST_NODE* Exp(AST_NODE* node)
{
    AST_NODE temp = malloc(sizeof(AST_NODE*));
    temp->type = exp;
    temp->child1-> node;
    return temp;
}
AST_NODE* factor(AST_NODE* node)
{
    AST_NODE Temp = malloc(sizeof(AST_NODE*));
    temp->type = factor;
    node->child1-> temp;
    return temp;

}
AST_NODE* Term(AST_NODE* node)
{
    AST_NODE temp = malloc(sizeof(AST_NODE*));
    temp->type = term;
    temp->child1-> node;
    return temp;

}

Here is my driver.c file where I am also getting the error «old-style parameter declarations in prototyped function definition expected ‘{‘ at end of input». This also I am very unfamiliar with.

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




AST_NODE* parser(TOKEN* token,AST_NODE node, FILE *input_file);

int main(void)
{
    TREE *current = 0;
    FILE *input_file = fopen("test.txt", "r");
    TOKEN *token = (TOKEN*) malloc(sizeof(TOKEN));
    TOKEN *tok = (TOKEN*) malloc(sizeof(TOKEN));
    AST_NODE* node = malloc(sizeof(AST_NODE));

    while(!feof(input_file))
    {
    token = scan(input_file);

        if(token->type != null)
        {
            parser(token,node,input_file);
            printf("%s", token->attribute);
            if(token->checkR == ';')
            {

                tok->type = semicolon;
                tok->attribute = ";";
                parser(tok,node,input_file);            
            }if(token->checkR == ')')
            {
                tok->type = rparen;
                tok->attribute = ")";
                parser(tok,node,input_file);
            }
        }
    }
    fclose(input_file);
    return 0;
}

Here is my parser.h file where I declare my TOKEN and my AST_NODE to create my tree and form my tokens to fill the tree.

#ifndef _parser_h
#define _parser_h


typedef enum token_type
{
    null,
    Id,
    keyword,
    num,
    addOp,
    multOp,
    assignment,
    semicolon,
    lparen,
    rparen,
    newLine
}TOKEN_TYPE;

typedef struct token{
    int type;
    char *attribute;
    char checkR;
}TOKEN;

typedef enum node_type
{
    program,
    statement,
    assignStmt,
    print,
    repeat,
    exp,
    factor,
    term
}NODE_TYPE;

typedef struct ast_node{
    NODE_TYPE type;
    TOKEN *tok;
    struct AST_NODE *prev;
    struct AST_NODE *child1;
    struct AST_NODE *child2;
    struct AST_NODE *child3;
    struct AST_NODE *child4;
    struct AST_NODE *child5;


}AST_NODE;

#endif

There is one more file called scanner.c but I know its working perfectly because I have tested it in all the possible inputs and got no problems.

If anyone could help I would appreciate it very much.

enter image description hereCould not able to solve this..
I am implementing a queue. After writing the complete code I had the error listed below:

expected '=', ',', ';', 'asm' or '__attribute__' before '.' token

Then I wrote a simple program, but same problem persists. Couldn’t able to understand how to solve this. I have looked into solutions in stackoverflow.com and google.com a lot but still couldn’t able to solve this.Please help.

I would like to initialize globally Q.front = Q.rear = Any value

#include <stdio.h>
#include <stdlib.h>
struct Queue
{
    int front, rear;
    int queue[10] ;
};
struct Queue Q;
Q.front = 0;
Q.rear = 0;

int main()
{
    return 0;
}

I159's user avatar

I159

29.5k31 gold badges97 silver badges132 bronze badges

asked Apr 25, 2012 at 7:09

Rasmi Ranjan Nayak's user avatar

0

Q.front = 0; is not a simple initializer, it is executable code; it cannot occur outside of a function. Use a proper initializer for Q.

struct Queue Q = {0, 0};

or with named initializer syntax (not available in all compilers, and as yet only in C):

struct Queue Q = {.front = 0, .rear = 0};

answered Apr 25, 2012 at 7:14

geekosaur's user avatar

0

You can’t initialize variable using Q.front = 0; Q.rear = 0; in global scope. Those statements should be inside main in your case.

answered Apr 25, 2012 at 7:14

Naveen's user avatar

NaveenNaveen

74.3k47 gold badges175 silver badges233 bronze badges

As @Naveen said you can’t assign to a member of a struct that is in global scope. Depending on the version of C though you could do this:

struct Queue q = {0,0};

or

struct Queue q = {.front = 0, .rear = 0 };

answered Apr 25, 2012 at 7:17

Will's user avatar

WillWill

4,5751 gold badge26 silver badges48 bronze badges

Home »
C programs »
C common errors programs

Here, we will learn why an Error: expected ‘=’, ‘,’, ‘,’ ‘asm’ or ‘ _attribute_’ before ‘<‘ token is occurred and how to fix it in C programming language?

Submitted by IncludeHelp, on September 11, 2018

A very common error in C programming language, it occurs when # is not used before the include.

As we know that #include is a preprocessor directive and it is used to include a header file’s code to the program. But, include is nothing without #, it is not valid and it cannot be used to include a header file in the program.

Example:

include <stdio.h>

int main(void) {
	printf("Hello world!");
	return 0;
}

Output

prog.c:1:9: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘<’ token
 include <stdio.h>
         ^

How to fix?

To fix this error — use #include.

Correct code:

#include <stdio.h>

int main(void) {
	printf("Hello world!");
	return 0;
}

Output

Hello world!

C Common Errors Programs »



0

0

Пытаюсь перевести небольшую программу с с++ на читый с. С g++ все компилируется и работает, с gcc выдает ошибку:

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token

Код выглядит примерно так:

struct my_structure;
my_structure* get_my_structure(char* param);

Ошибка ругается на 2ю строку. Гугл ничего внятного не говорит. Не пойму, что здесь не так.

gcc (GCC) 4.2.1 (SUSE Linux)

  • Ссылка

Студворк — интернет-сервис помощи студентам

C
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <stdio.h>
 
main()
{
  FILE *in *out;
  long sym;
 
   if (!(in = fopen("text.txt", "r"))) { printf ("can't open the file for readingn"); return -1; }
if (!(out = fopen("zap.txt", "w"))) { printf ("can't open a file for writingn"); return -1; } 
 
  sym = 0;
  while (getchar() !=EOF)
   {
    ++sym;
  fputc(sym, out);
   }
 
  fclose(out);
  fclose(in);
    return 0;
}

Выдает ошибку на 5 строке

ошибка: expected «=», «,», «;», «asm» or «__attribute__» before «*» token

Вроде все нормально…

  • Ошибка exiting pxe rom при загрузке windows
  • Ошибка existing state of has been invalidated
  • Ошибка exim rejected rcpt
  • Ошибка exe не является приложением win32 что делать
  • Ошибка exe err not found configure mp csv