Skip to content
Snippets Groups Projects
Commit c8f0597f authored by marruiz's avatar marruiz :space_invader:
Browse files

while e if-else

parent bf9f5d02
Branches
No related tags found
No related merge requests found
...@@ -46,6 +46,7 @@ static ast_t ast = NULL; ...@@ -46,6 +46,7 @@ static ast_t ast = NULL;
%token <S> FLOAT %token <S> FLOAT
%token <s> STR %token <s> STR
%term WHILE
%type <s> PROGRAM PROGRAM_ELEMENT SENTENCE EXPR %type <s> PROGRAM PROGRAM_ELEMENT SENTENCE EXPR
%% %%
...@@ -114,8 +115,20 @@ SENTENCE ...@@ -114,8 +115,20 @@ 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 EXPR DEL_BL '\n'
{
$$.type = AST_NODE;
$$.u.node = newNode(WHILE, $2.u.node, $4.u.node);
}
| IF EXPR DEL_BL EXPR DEL_BL ELSE DEL_BL EXPR DEL_BL '\n'
{
$$.type = AST_NODE;
$$.u.node = newNode(IF, $2.u.node, $4.u.node);
$$.u.node = newNode(ELSE, $2.u.node, $8.u.node);
}; };
EXPR EXPR
: EXPR EQ EXPR : EXPR EQ EXPR
{ {
...@@ -214,7 +227,10 @@ EXPR ...@@ -214,7 +227,10 @@ EXPR
{ {
$$.type = AST_NODE_id; $$.type = AST_NODE_id;
$$.u.node = newNode(LN, $3.u.node, NULL); $$.u.node = newNode(LN, $3.u.node, NULL);
}; }
;
%% %%
...@@ -264,21 +280,6 @@ int main(int argc, char *argv[]) ...@@ -264,21 +280,6 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
/*
______
< \
<. .\ O
| \______
<\O____/
/ \
> <
TODO
Donehre ASCII
*/
... ...
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment