Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GLF Proyecto
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
marruiz
GLF Proyecto
Commits
bf9f5d02
Commit
bf9f5d02
authored
Jun 8, 2020
by
mandeca
Browse files
Options
Downloads
Patches
Plain Diff
Cabecera autils.h.
parent
0903fb27
No related branches found
No related tags found
No related merge requests found
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
a.l
+4
-4
4 additions, 4 deletions
a.l
a.y
+25
-25
25 additions, 25 deletions
a.y
ast.c
+3
-3
3 additions, 3 deletions
ast.c
autils.h
+27
-0
27 additions, 0 deletions
autils.h
exits.h
+0
-11
0 additions, 11 deletions
exits.h
symtab.c
+2
-2
2 additions, 2 deletions
symtab.c
with
61 additions
and
45 deletions
a.l
+
4
−
4
View file @
bf9f5d02
...
@@ -100,7 +100,7 @@ ID {
...
@@ -100,7 +100,7 @@ ID {
}
}
/*Si no es una palabra clave y lo devuelve como identificador*/
/*Si no es una palabra clave y lo devuelve como identificador*/
yystr(yylval) = sdup(yytext);
yystr(yylval) = sdup(yytext);
yyFlag(yylval) =
f
ID
ENT
;
yyFlag(yylval) = ID
_id
;
return ID;
return ID;
}
}
...
@@ -114,14 +114,14 @@ NUMBER { /*Se lee el numero entero y se castea a double*/
...
@@ -114,14 +114,14 @@ NUMBER { /*Se lee el numero entero y se castea a double*/
long int li;
long int li;
sscanf(yytext, "%d", &li);
sscanf(yytext, "%d", &li);
yyFloat(yylval) = (double)li;
yyFloat(yylval) = (double)li;
yyFlag(yylval) =
fFLOAT
;
yyFlag(yylval) =
REAL_id
;
return FLOAT;
return FLOAT;
}
}
FLOAT { /*Se lee el numero decimal*/
FLOAT { /*Se lee el numero decimal*/
sscanf(yytext, "%lf", &(yyFloat(yylval)));
sscanf(yytext, "%lf", &(yyFloat(yylval)));
yyFlag(yylval) =
fFLOAT
;
yyFlag(yylval) =
REAL_id
;
return FLOAT;
return FLOAT;
...
@@ -129,7 +129,7 @@ FLOAT { /*Se lee el numero decimal*/
...
@@ -129,7 +129,7 @@ FLOAT { /*Se lee el numero decimal*/
STR_START {
STR_START {
yyStr(yylval) = readStr();
yyStr(yylval) = readStr();
yyFlag(yylval) =
f
STR;
yyFlag(yylval) = STR
_id
;
return STR;
return STR;
}
}
...
...
This diff is collapsed.
Click to expand it.
a.y
+
25
−
25
View file @
bf9f5d02
...
@@ -73,7 +73,7 @@ PROGRAM_ELEMENT
...
@@ -73,7 +73,7 @@ PROGRAM_ELEMENT
/* Sentencia vacía */
/* Sentencia vacía */
| '\n'
| '\n'
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = NULL;
$$.u.node = NULL;
};
};
...
@@ -82,94 +82,94 @@ SENTENCE
...
@@ -82,94 +82,94 @@ SENTENCE
/* Asignación */
/* Asignación */
: ID '=' EXPR
: ID '=' EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(ASSIG, newLeafString(ID, $1.u.string), $3.u.node);
$$.u.node = newNode(ASSIG, newLeafString(ID, $1.u.string), $3.u.node);
}
}
/* Impresión de un valor */
/* Impresión de un valor */
| PRINT EXPR
| PRINT EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(PRINT, NULL, $2.u.node);
$$.u.node = newNode(PRINT, NULL, $2.u.node);
}
}
/* Impresión de una string */
/* Impresión de una string */
| PRINT STR
| PRINT STR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(PRINT, newLeafString(STR, $2.u.string), NULL);
$$.u.node = newNode(PRINT, newLeafString(STR, $2.u.string), NULL);
}
}
/* Impresión de una string y un valor */
/* Impresión de una string y un valor */
| PRINT STR EXPR
| PRINT STR EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(PRINT, newLeafString(STR, $2.u.string), $3.u.node);
$$.u.node = newNode(PRINT, newLeafString(STR, $2.u.string), $3.u.node);
}
}
/* Lectura de un valor */
/* Lectura de un valor */
| READ ID
| READ ID
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(READ, NULL, newLeafString(ID, $2.u.string));
$$.u.node = newNode(READ, NULL, newLeafString(ID, $2.u.string));
}
}
/* Lectura de un valor con mensaje de aviso */
/* Lectura de un valor con mensaje de aviso */
| READ STR ID
| READ STR ID
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(READ, newLeafString(STR, $2.u.string), newLeafString(ID, $3.u.string))
$$.u.node = newNode(READ, newLeafString(STR, $2.u.string), newLeafString(ID, $3.u.string))
};
};
EXPR
EXPR
: EXPR EQ EXPR
: EXPR EQ EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(EQ, $1.u.node, $3.u.node);
$$.u.node = newNode(EQ, $1.u.node, $3.u.node);
}
}
| EXPR NE EXPR
| EXPR NE EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(NE, $1.u.node, $3.u.node);
$$.u.node = newNode(NE, $1.u.node, $3.u.node);
}
}
| EXPR LT EXPR
| EXPR LT EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(LT, $1.u.node, $3.u.node);
$$.u.node = newNode(LT, $1.u.node, $3.u.node);
}
}
| EXPR GT EXPR
| EXPR GT EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(GT, $1.u.node, $3.u.node);
$$.u.node = newNode(GT, $1.u.node, $3.u.node);
}
}
| EXPR '+' EXPR
| EXPR '+' EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode('+', $1.u.node, $3.u.node);
$$.u.node = newNode('+', $1.u.node, $3.u.node);
}
}
| EXPR '-' EXPR
| EXPR '-' EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode('-', $1.u.node, $3.u.node);
$$.u.node = newNode('-', $1.u.node, $3.u.node);
}
}
| EXPR '*' EXPR
| EXPR '*' EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode('*', $1.u.node, $3.u.node);
$$.u.node = newNode('*', $1.u.node, $3.u.node);
}
}
| EXPR '/' EXPR
| EXPR '/' EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode('/', $1.u.node, $3.u.node);
$$.u.node = newNode('/', $1.u.node, $3.u.node);
}
}
| EXPR '%' EXPR
| EXPR '%' EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode('%', $1.u.node, $3.u.node);
$$.u.node = newNode('%', $1.u.node, $3.u.node);
}
}
| EXPR '^' EXPR
| EXPR '^' EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode('^', $1.u.node, $3.u.node);
$$.u.node = newNode('^', $1.u.node, $3.u.node);
}
}
| EXPR DIV EXPR
| EXPR DIV EXPR
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(DIV, $1.u.node, $3.u.node);
$$.u.node = newNode(DIV, $1.u.node, $3.u.node);
}
}
| '+' EXPR %prec UNARY
| '+' EXPR %prec UNARY
...
@@ -178,7 +178,7 @@ EXPR
...
@@ -178,7 +178,7 @@ EXPR
}
}
| '-' EXPR %prec UNARY
| '-' EXPR %prec UNARY
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode('-', NULL, $2.u.node);
$$.u.node = newNode('-', NULL, $2.u.node);
}
}
| '(' EXPR ')'
| '(' EXPR ')'
...
@@ -187,32 +187,32 @@ EXPR
...
@@ -187,32 +187,32 @@ EXPR
}
}
| FLOAT
| FLOAT
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newLeafNum(FLOAT,$1.u.real_value);
$$.u.node = newLeafNum(FLOAT,$1.u.real_value);
}
}
| ID
| ID
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newLeafString(ID,$1.u.string);
$$.u.node = newLeafString(ID,$1.u.string);
}
}
| SIN '(' EXPR ')'
| SIN '(' EXPR ')'
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(SIN, $3.u.node, NULL);
$$.u.node = newNode(SIN, $3.u.node, NULL);
}
}
| COS '(' EXPR ')'
| COS '(' EXPR ')'
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(COS, $3.u.node, NULL);
$$.u.node = newNode(COS, $3.u.node, NULL);
}
}
| TAN '(' EXPR ')'
| TAN '(' EXPR ')'
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(TAN, $3.u.node, NULL);
$$.u.node = newNode(TAN, $3.u.node, NULL);
}
}
| LN '(' EXPR ')'
| LN '(' EXPR ')'
{
{
$$.type = AST_NODE;
$$.type = AST_NODE
_id
;
$$.u.node = newNode(LN, $3.u.node, NULL);
$$.u.node = newNode(LN, $3.u.node, NULL);
};
};
...
...
This diff is collapsed.
Click to expand it.
ast.c
+
3
−
3
View file @
bf9f5d02
...
@@ -15,7 +15,7 @@ extern char programName[];
...
@@ -15,7 +15,7 @@ extern char programName[];
ast_t
*
newLeafString
(
unsigned
tag
,
char
*
str
)
ast_t
*
newLeafString
(
unsigned
tag
,
char
*
str
)
{
{
ast_t
*
res
=
(
ast_t
*
)
malloc
(
sizeof
(
ast_t
));
mallocCheck
(
ast_t
*
res
,
sizeof
(
ast_t
));
lnum
(
res
)
=
(
unsigned
)
lineNum
;
lnum
(
res
)
=
(
unsigned
)
lineNum
;
tag
(
res
)
=
tag
;
tag
(
res
)
=
tag
;
sv
(
res
)
=
str
;
sv
(
res
)
=
str
;
...
@@ -25,7 +25,7 @@ ast_t *newLeafString(unsigned tag, char *str)
...
@@ -25,7 +25,7 @@ ast_t *newLeafString(unsigned tag, char *str)
ast_t
*
newLeafNum
(
unsigned
tag
,
double
dval
)
ast_t
*
newLeafNum
(
unsigned
tag
,
double
dval
)
{
{
ast_t
*
res
=
(
ast_t
*
)
malloc
(
sizeof
(
ast_t
));
mallocCheck
(
ast_t
*
res
,
sizeof
(
ast_t
));
lnum
(
res
)
=
(
unsigned
)
lineNum
;
lnum
(
res
)
=
(
unsigned
)
lineNum
;
tag
(
res
)
=
tag
;
tag
(
res
)
=
tag
;
dv
(
res
)
=
dval
;
dv
(
res
)
=
dval
;
...
@@ -34,7 +34,7 @@ ast_t *newLeafNum(unsigned tag, double dval)
...
@@ -34,7 +34,7 @@ ast_t *newLeafNum(unsigned tag, double dval)
ast_t
*
newNode
(
unsigned
tag
,
ast_t
*
l
,
ast_t
*
r
)
ast_t
*
newNode
(
unsigned
tag
,
ast_t
*
l
,
ast_t
*
r
)
{
{
ast_t
*
res
=
(
ast_t
*
)
malloc
(
sizeof
(
ast_t
));
mallocCheck
(
ast_t
*
res
,
sizeof
(
ast_t
));
lnum
(
res
)
=
(
unsigned
)
lineNum
;
lnum
(
res
)
=
(
unsigned
)
lineNum
;
tag
(
res
)
=
tag
;
tag
(
res
)
=
tag
;
left
(
res
)
=
l
;
left
(
res
)
=
l
;
...
...
This diff is collapsed.
Click to expand it.
autils.h
0 → 100644
+
27
−
0
View file @
bf9f5d02
/*
* CÓDIGOS DE SALIDA PARA EL INTÉRPRETE.
*
*/
/* Identificadores de tokens */
#define ID_id 1
#define INT_id 2
#define REAL_id 3
#define STR_id 4
#define AST_NODE_id 5
/* Salidas del programa. */
#define PARSE_SUCCESS 0
#define LEXICAL_ERROR -1
#define SYNTAX_ERROR -2
#define FILE_ERROR -3
#define SYMTAB_NOT_FOUND -4
#define MEMORY_ERROR -5
#define mallocCheck(ptr, size) { \
if ((ptr = malloc(size)) == NULL) \
{ \
fprintf(stderr, "Fallo de alocación de memoria.\n"); \
exit(MEMORY_ERROR); \
} \
}
This diff is collapsed.
Click to expand it.
exits.h
deleted
100644 → 0
+
0
−
11
View file @
0903fb27
/*
* CÓDIGOS DE SALIDA PARA EL INTÉRPRETE.
*
*/
/* Salidas del programa. */
#define PARSE_SUCCESS 0
#define LEXICAL_ERROR -1
#define SYNTAX_ERROR -2
#define FILE_ERROR -3
#define SYMTAB_NOT_FOUND -4
\ No newline at end of file
This diff is collapsed.
Click to expand it.
symtab.c
+
2
−
2
View file @
bf9f5d02
...
@@ -8,7 +8,7 @@
...
@@ -8,7 +8,7 @@
*
*
*/
*/
#include
"symtab.h"
#include
"symtab.h"
#include
"
exit
s.h"
#include
"
autil
s.h"
#include
<stdio.h>
#include
<stdio.h>
#include
<stdlib.h>
#include
<stdlib.h>
...
@@ -33,7 +33,7 @@ static symbol *symTab = NULL;
...
@@ -33,7 +33,7 @@ static symbol *symTab = NULL;
/* Rellenar la tabla con entradas vacías */
/* Rellenar la tabla con entradas vacías */
static
void
init
()
static
void
init
()
{
{
symTab
=
(
symbol
*
)
malloc
(
sizeof
(
symbol
)
*
size
);
mallocCheck
(
symTab
,
sizeof
(
symbol
)
*
size
);
memset
(
symTab
,
0
,
sizeof
(
symbol
)
*
(
size_t
)
size
);
memset
(
symTab
,
0
,
sizeof
(
symbol
)
*
(
size_t
)
size
);
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment