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
f3fd14fc
Commit
f3fd14fc
authored
Jun 10, 2020
by
mandeca
Browse files
Options
Downloads
Patches
Plain Diff
Bloques de sentencias.
parent
b52fc631
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
a.l
+7
-37
7 additions, 37 deletions
a.l
a.y
+86
-94
86 additions, 94 deletions
a.y
ast.c
+7
-11
7 additions, 11 deletions
ast.c
symtab.h
+1
-4
1 addition, 4 deletions
symtab.h
with
101 additions
and
146 deletions
a.l
+
7
−
37
View file @
f3fd14fc
...
@@ -48,33 +48,23 @@ LETTER ([_a-zA-Z])
...
@@ -48,33 +48,23 @@ LETTER ([_a-zA-Z])
DIGIT ([0-9])
DIGIT ([0-9])
NUMBER ({DIGIT}+)
NUMBER ({DIGIT}+)
/*Exponente de float*/
EXP ([eE][-+]?{NUMBER})
/*Distintas formas de representacion de constantes tipo float*/
FLOAT_DOT ({NUMBER}"."{NUMBER})
FLOAT_EXP ({NUMBER}{EXP})
FLOAT_DE ({NUMBER}"."{NUMBER}{EXP})
/*Representacion tipo float*/
/*Representacion tipo float*/
FLOAT (
{FLOAT_DOT}|{FLOAT_EXP}|{FLOAT_DE
})
FLOAT (
({NUMBER}"."{DIGIT}*)({DIGIT}*"."{NUMBER
})
/*Identificador*/
/*Identificador*/
ID ({LETTER}({LETTER}|{DIGIT})*)
ID ({LETTER}({LETTER}|{DIGIT})*)
/*Separador de sentencias*/
SEPAR ([\n])
/*Delimitador de bloques*/
/*Delimitador de bloques*/
DEL_BL_A ([{])
DEL_BL_A (["{"{WSPC}*"\n"])
DEL_BL_C ([}])
DEL_BL_C (["}"{WSPC}*"\n"])
/* DEL_BL_C_2????? */
/*Espacios en blanco*/
/*Espacios en blanco*/
WSPC ([ \t\f\r])
WSPC ([ \t\f\r])
WSCPS ({WSPC}+)
WSCPS ({WSPC}+)
/*Operadores aritmeticos*/
/*Operadores aritmeticos*/
OP_AR ([
-+/*
%=()^])
OP_AR ([
+*-/
%=()^])
/*Operadores logicos*/
/*Operadores logicos*/
OP_LOG ("=="|"!="|"<"|">")
OP_LOG ("=="|"!="|"<"|">")
...
@@ -211,23 +201,3 @@ static char *readStr(void)
...
@@ -211,23 +201,3 @@ static char *readStr(void)
} while(1);
} while(1);
return buff;
return buff;
}
}
/*
______
< \
<. .\ O
| \______
<\O____/
/ \
> <
TODO
Donehre ASCII
*/
This diff is collapsed.
Click to expand it.
a.y
+
86
−
94
View file @
f3fd14fc
...
@@ -45,39 +45,60 @@ static ast_t ast = NULL;
...
@@ -45,39 +45,60 @@ static ast_t ast = NULL;
%term PRINT READ SIN COS TAN LN
%term PRINT READ SIN COS TAN LN
%token <S> FLOAT
%token <S> FLOAT
%token <s> STR
%token <s> STR
%term WHILE IF ELSE
%term WHILE
%type <s> PROGRAM PROGRAM_ELEMENT SENTENCE EXPR BLOCK
%type <s> PROGRAM PROGRAM_ELEMENT SENTENCE EXPR
%type <s> BLOCK
%%
%%
/* Producciones de un programa */
/* Producciones de un programa */
PROGRAM
PROGRAM
/* Un único
elemento
de programa */
/* Un único
bloque
de programa */
:
PROGRAM_ELEMENT
:
BLOCK
{
{
ast = newRoot('
l
', ast, $1.u.node);
ast = newRoot('
r
', ast, $1.u.node);
}
}
/* Varios
elemento
s de programa */
/* Varios
bloque
s de programa */
| PROGRAM
PROGRAM_ELEMENT
| PROGRAM
BLOCK
{
{
ast = newRoot('
l
', ast, $2.u.node);
ast = newRoot('
r
', ast, $2.u.node);
};
};
/*
Elementos de un
programa */
/*
Bloque de
programa */
PROGRAM_ELEMENT
BLOCK
/*
S
entencia */
/*
Una s
entencia */
: SENTENCE '\n'
: SENTENCE '\n'
{
{
$$ = $1;
$$.type = AST_NODE_id;
$$.u.node = newNode('s', NULL, $1.u.node);
}
}
/* Sentencia vacía */
/* Sentencia vacía */
| '\n'
| '\n'
{
{
$$.type = AST_NODE_id;
$$.type = AST_NODE_id;
$$.u.node = NULL;
$$.u.node = NULL;
};
}
/* Grupo de sentencias entre corchetes */
| DEL_BL_A SENTENCE_GROUP DEL_BL_C
{
$$ = $2;
}
;
/* Grupo de sentencias */
SENTENCE_GROUP
/* Bloque de sentencias */
: BLOCK
{
$$ = $1;
}
/* Grupo de sentencias y una sentencia (recursivo) */
| SENTENCE_GROUP SENTECE '\n'
{
$$.type = AST_NODE_id;
$$.U.node = newNode('s', NULL, $2.u.node);
}
;
/* Sentencias */
/* Sentencias */
SENTENCE
SENTENCE
...
@@ -117,24 +138,23 @@ SENTENCE
...
@@ -117,24 +138,23 @@ SENTENCE
$$.type = AST_NODE_id;
$$.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))
}
}
| WHILE EXPR
DEL_BL_A BLOCK DEL_BL_C '\n'
| WHILE
'('
EXPR
')' BLOCK
{
{
$$.type = AST_NODE_id;
$$.type = AST_NODE_id;
$$.u.node = newNode(WHILE, $
2
.u.node, $
4
.u.node);
$$.u.node = newNode(WHILE, $
3
.u.node, $
5
.u.node);
}
}
| IF EXPR
DEL_BL_A BLOCK DEL_BL_C ELSE DEL_BL_A BLOCK DEL_BL_C '\n'
| IF
'('
EXPR
')' BLOCK ELSE BLOCK
{
{
$$.type = AST_NODE_id;
$$.type = AST_NODE_id;
$$.u.node = newNode(IF, $
2
.u.node, $
4
.u.node);
$$.u.node = newNode(IF, $
3
.u.node, $
5
.u.node);
$$.u.node = newNode(ELSE, $
2
.u.node, $
8
.u.node);
$$.u.node = newNode(ELSE, $
3
.u.node, $
7
.u.node);
}
}
| IF EXPR
DEL_BL_A BLOCK DEL_BL_C '\n'
| IF
'('
EXPR
')' BLOCK
{
{
$$.type = AST_NODE_id;
$$.type = AST_NODE_id;
$$.u.node = newNode(IF, $
2
.u.node, $
4
.u.node);
$$.u.node = newNode(IF, $
3
.u.node, $
5
.u.node);
};
};
EXPR
EXPR
: EXPR EQ EXPR
: EXPR EQ EXPR
{
{
...
@@ -235,29 +255,6 @@ EXPR
...
@@ -235,29 +255,6 @@ EXPR
$$.u.node = newNode(LN, $3.u.node, NULL);
$$.u.node = newNode(LN, $3.u.node, NULL);
}
}
;
;
BLOCK
: SENTENCE '\n'
{
$$.type = AST_NODE_id;
$$.u.node = newRoot(';', NULL, $1.u.ast);
}
| '\n'
{
$$.type = AST_NODE_id;
$$.u.node = NULL;
}
| BODY SENTENCE '\n'
{
$$.type = AST_NODE_id;
$$.u.node = newRoot(';', $1.u.ast, $2.u.ast);
}
| BODY '\n'
{
$$ = $1;
}
;
%%
%%
...
@@ -306,8 +303,3 @@ int main(int argc, char *argv[])
...
@@ -306,8 +303,3 @@ int main(int argc, char *argv[])
return 0;
return 0;
}
}
This diff is collapsed.
Click to expand it.
ast.c
+
7
−
11
View file @
f3fd14fc
...
@@ -228,25 +228,21 @@ static void proc(ast_t *root)
...
@@ -228,25 +228,21 @@ static void proc(ast_t *root)
break
;
break
;
case
IF
:
case
IF
:
if
(
expr
(
left
(
root
)))
if
(
expr
(
left
(
root
)))
{
{
evaluate
(
right
(
root
));
evaluate
(
right
(
root
));
}
}
break
;
break
;
case
ELSE
:
case
ELSE
:
if
(
!
(
expr
(
left
(
root
))))
if
(
!
(
expr
(
left
(
root
))))
{
{
evaluate
(
right
(
root
));
evaluate
(
right
(
root
));
}
}
break
;
break
;
default:
default:
fprintf
(
stderr
,
"%s(%d): error -- Etiqueta desconocida en expresión AST %u
\n
"
,
programName
,
lnum
(
root
),
tag
(
root
));
fprintf
(
stderr
,
"%s(%d): error - Etiqueta desconocida en expresión AST %u
\n
"
,
programName
,
lnum
(
root
),
tag
(
root
));
break
;
break
;
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
symtab.h
+
1
−
4
View file @
f3fd14fc
...
@@ -4,11 +4,8 @@
...
@@ -4,11 +4,8 @@
* Curso 2019-2020
* Curso 2019-2020
*/
*/
enum
symbolType
{
VOID
,
REAL
};
// TODO: tipos en función de los lexemas.
typedef
enum
symbolType
symbol_t
;
typedef
struct
symbol_s
{
typedef
struct
symbol_s
{
symbol_
t
type
;
in
t
type
;
union
{
union
{
double
real
;
double
real
;
}
value
;
}
value
;
...
...
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