-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from JackCloudman/dev
Add Symbol table like hoc 3
- Loading branch information
Showing
6 changed files
with
95 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#include "Symbol.h" | ||
static Symbol *symlist=0; /* tabla de simbolos: lista ligada */ | ||
|
||
Symbol *lookup(char *s) /* encontrar s en la tabla de símbolos */ | ||
{ | ||
Symbol *sp; | ||
for (sp = symlist; sp != (Symbol *)0; sp = sp->next){ | ||
if (strcmp(sp->name, s)== 0) | ||
return sp; | ||
} | ||
return 0; /* 0 ==> no se encontró */ | ||
} | ||
/*La funcion install crea la variable en la tabla | ||
de simbolos si esta que esta no existe*/ | ||
Symbol *install(char *s,int t,LLObject* o) | ||
{ | ||
Symbol *sp; | ||
char *emalloc(); | ||
|
||
sp = (Symbol *) emalloc(sizeof(Symbol)); | ||
|
||
sp->name = emalloc(strlen(s)+ 1) ; /* +1 para '\0' */ | ||
strcpy(sp->name, s); | ||
|
||
sp->type = t; | ||
sp->u.val = o; | ||
sp->next = symlist; /* poner al frente de la lista */ | ||
symlist = sp; | ||
return sp; | ||
} | ||
|
||
/* revisar el regreso desde malloc */ | ||
char *emalloc(unsigned n){ | ||
char *p; | ||
p =(char*) malloc(n); | ||
if(p == 0) | ||
perror("out of memory"); | ||
return p; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,5 +17,4 @@ | |
LLObject_HEAD | ||
}LLObject; | ||
typedef LLObject *APLLObject; | ||
#define YYSTYPE APLLObject | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef __SYMBOL_H__ | ||
#define __SYMBOL_H__ | ||
#include "Lala.h" | ||
#include <string.h> | ||
/*entrada a tabla de simbolos, | ||
es una lista simplemente ligada*/ | ||
typedef struct Symbol { | ||
char *name; | ||
short type; /* VAR, BLTIN, UNDEF */ | ||
|
||
union { | ||
LLObject* val; /* si es VAR */ | ||
LLObject* (*ptr)(); /* sí es BLTIN */ | ||
} u; | ||
|
||
struct Symbol *next; /* para ligarse a otro */ | ||
} Symbol; | ||
|
||
Symbol *install(char *s,int t, LLObject*), *lookup(char *s); | ||
#endif |