Skip to content

Commit e73067e

Browse files
adding error.c and error.h
1 parent 17c7eeb commit e73067e

File tree

2 files changed

+107
-0
lines changed

2 files changed

+107
-0
lines changed

‎error.c

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#include "error.h"
2+
3+
#include <stdlib.h>
4+
5+
#include <string.h>
6+
7+
#include <stdio.h>
8+
9+
10+
11+
#define MAXSIZE 100
12+
13+
static int NODEr = 0; //NumberOfDeclarationErrors
14+
15+
static smerror * ARRAYDECL[MAXSIZE];
16+
17+
18+
19+
smerror *_create_sm_error(SemanticErrorType et, int line, char * name){
20+
21+
smerror *e = (smerror*) malloc (sizeof (smerror) );
22+
23+
e->type = et;
24+
25+
e->line = line;
26+
27+
e->name = (char *) malloc (strlen(name));
28+
29+
strcpy(e->name, name);
30+
31+
return e;
32+
33+
}
34+
35+
void _create_sm_error_declaration(SemanticErrorType et, int line, char* name){
36+
37+
ARRAYDECL[NODEr++]= _create_sm_error(et, line, name);
38+
39+
}
40+
41+
void _show_sm_error(SemanticErrorType et, int line, char* name){
42+
43+
printf("ligne %d : %s ", line, name);
44+
45+
switch (et){
46+
47+
case AlreadyDeclared: printf("AlreadyDeclared\n"); break;
48+
49+
case BadlyInitialized: printf("BadlyInitialized\n"); break;
50+
51+
}
52+
53+
}
54+
55+
void _show_sm_errors(){
56+
57+
for(int i=0;i<NODEr;i++){
58+
59+
_show_sm_error(ARRAYDECL[i]->type,ARRAYDECL[i]->line,ARRAYDECL[i]->name);
60+
61+
}
62+
63+
}
64+
65+
66+
int nombre_sm_errors(){
67+
68+
return NODEr;
69+
70+
}

‎error.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef error_H
2+
3+
#define error_H
4+
5+
6+
7+
typedef enum{
8+
9+
AlreadyDeclared,
10+
11+
BadlyInitialized,
12+
13+
}SemanticErrorType;
14+
15+
typedef struct {
16+
17+
char *name;
18+
19+
int line;
20+
21+
SemanticErrorType type;
22+
23+
} smerror;
24+
25+
smerror *_create_sm_error(SemanticErrorType et, int line, char * name);
26+
27+
void _create_sm_error_declaration(SemanticErrorType et, int line, char* name);
28+
29+
void _show_sm_error(SemanticErrorType et, int line, char* name);
30+
31+
void _show_sm_errors();
32+
33+
int nombre_sm_errors();
34+
35+
36+
37+
#endif

0 commit comments

Comments
 (0)