Commit 0113353c authored by Seblu's avatar Seblu
Browse files

avancement du parser

avancement des printer de l'ast
parent 00f2ed90
Loading
Loading
Loading
Loading
+92 −4
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
** Login   <seblu@epita.fr>
**
** Started on  Sun Jul 30 04:40:03 2006 Seblu
** Last update Fri Sep  1 00:30:34 2006 Seblu
** Last update Tue Sep 26 17:49:18 2006 Seblu
*/

#ifndef AST_H_
@@ -189,6 +189,7 @@ void ast_print(s_ast_node *ast, const char *filename);
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_print_node(s_ast_node *ast, FILE *fs, unsigned int *node_id);

@@ -279,6 +280,15 @@ void ast_case_destruct(s_ast_node *node);
*/
s_ast_node	*ast_while_create(s_ast_node *cond, s_ast_node *exec);

/*!
** Print an ast while (while) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_while_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct a while ast node
**
@@ -296,6 +306,15 @@ void ast_while_destruct(s_ast_node *node);
*/
s_ast_node	*ast_until_create(s_ast_node *cond, s_ast_node *exec);

/*!
** Print an ast until (until) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_until_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct a until ast node
**
@@ -339,7 +358,13 @@ void ast_cmd_add_argv(s_ast_node *node, char *argv);
*/
void		ast_cmd_add_prefix(s_ast_node *node, char *assignment_word);


/*!
** Print an ast cmd node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
@@ -359,6 +384,15 @@ void ast_cmd_destruct(s_ast_node *node);
*/
s_ast_node	*ast_and_create(s_ast_node *lhs, s_ast_node *rhs);

/*!
** Print an ast and (&&) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_and_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct an and (&&) node
**
@@ -376,6 +410,15 @@ void ast_and_destruct(s_ast_node *node);
*/
s_ast_node	*ast_or_create(s_ast_node *lhs, s_ast_node *rhs);

/*!
** Print an ast or (||) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_or_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct an or (||) node
**
@@ -384,7 +427,7 @@ s_ast_node *ast_or_create(s_ast_node *lhs, s_ast_node *rhs);
void		ast_or_destruct(s_ast_node *node);

/*!
** Create a subshell ($()) ast node
** Create a subshell (()) ast node
**
** @param child subshell tree
**
@@ -393,7 +436,16 @@ void ast_or_destruct(s_ast_node *node);
s_ast_node	*ast_subshell_create(s_ast_node *child);

/*!
** Destruct a subshell ($()) node
** Print an ast subshell (()) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_subshell_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct a subshell (()) node
**
** @param node node to destroy
*/
@@ -425,6 +477,15 @@ void ast_funcdec_destruct(s_ast_node *node);
*/
s_ast_node	*ast_bang_create(s_ast_node *child);

/*!
** Print an ast bang (!) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_bang_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct a bang (!) node
**
@@ -442,6 +503,15 @@ void ast_bang_destruct(s_ast_node *node);
*/
s_ast_node	*ast_pipe_create(s_ast_node *lhs, s_ast_node *rhs);

/*!
** Print an ast pipe (|) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_pipe_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct a pipe (|) node
**
@@ -459,6 +529,15 @@ void ast_pipe_destruct(s_ast_node *node);
*/
s_ast_node	*ast_sep_create(s_ast_node *lhs, s_ast_node *rhs);

/*!
** Print an ast sep (;) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_sep_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct a sep (;) node
**
@@ -476,6 +555,15 @@ void ast_sep_destruct(s_ast_node *node);
*/
s_ast_node	*ast_sepand_create(s_ast_node *lhs, s_ast_node *rhs);

/*!
** Print an ast sepand (&) node
**
** @param ast ast node to add to file
** @param fs file stream where print ast
** @param node_id first free node id
*/
void		ast_sepand_print(s_ast_node *node, FILE *fs, unsigned int *node_id);

/*!
** Destruct a sepand (&) node
**
+16 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
** Login   <seblu@epita.fr>
**
** Started on  Thu Aug  3 02:41:37 2006 Seblu
** Last update Mon Aug 28 23:57:05 2006 Seblu
** Last update Tue Sep 26 17:45:16 2006 Seblu
*/

#include "ast.h"
@@ -21,6 +21,21 @@ s_ast_node *ast_and_create(s_ast_node *lhs, s_ast_node *rhs)
  return node;
}

void		ast_and_print(s_ast_node *node, FILE *fs, unsigned int *node_id)
{
  unsigned int	lhs_id, rhs_id, cur_id;

  if (node->type != T_AND)
    return;
  fprintf(fs, "%u [label = \"&&\"];\n", cur_id = *node_id);
  lhs_id = ++*node_id;
  ast_print_node(node->body.child_and.lhs, fs, node_id);
  fprintf(fs, "%u -> %u\n", cur_id, lhs_id);
  rhs_id = *node_id;
  ast_print_node(node->body.child_and.rhs, fs, node_id);
  fprintf(fs, "%u -> %u\n", cur_id, rhs_id);
}

void		ast_and_destruct(s_ast_node *node)
{
  if (node->type != T_AND)
+13 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
** Login   <seblu@epita.fr>
**
** Started on  Thu Aug  3 02:41:37 2006 Seblu
** Last update Mon Aug 28 23:57:20 2006 Seblu
** Last update Tue Sep 26 17:45:45 2006 Seblu
*/

#include "ast.h"
@@ -21,6 +21,18 @@ s_ast_node *ast_bang_create(s_ast_node *child)
  return node;
}

void		ast_bang_print(s_ast_node *node, FILE *fs, unsigned int *node_id)
{
  unsigned int	lhs_id, cur_id;

  if (node->type != T_BANG)
    return;
  fprintf(fs, "%u [label = \"!\"];\n", cur_id = *node_id);
  lhs_id = ++*node_id;
  ast_print_node(node->body.child_bang.lhs, fs, node_id);
  fprintf(fs, "%u -> %u\n", cur_id, lhs_id);
}

void		ast_bang_destruct(s_ast_node *node)
{
  if (node->type != T_BANG)
+6 −5
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
** Login   <seblu@epita.fr>
**
** Started on  Fri Aug 18 22:13:51 2006 Seblu
** Last update Mon Sep 25 04:19:18 2006 Seblu
** Last update Tue Sep 26 17:25:05 2006 Seblu
*/

#include "ast.h"
@@ -37,7 +37,7 @@ void ast_cmd_add_redir(s_ast_node *node,
  red->fd = fd;
  red->word = word;
  red->next = NULL;
  for (this = &node->body.child_cmd.redirs; *this; *this = (*this)->next)
  for (this = &node->body.child_cmd.redirs; (*this) != NULL; this = &(*this)->next)
    ; //do nothing
  *this = red;
}
@@ -77,10 +77,10 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id)
  if (node->type != T_CMD)
    return;
  fprintf(fs, "%u [label = \"Command\"];\n", *node_id);
  ++*node_id;
  //prefix
  char **prefix = node->body.child_cmd.prefix;
  if (prefix && prefix[0]) {
    ++*node_id;
    fprintf(fs, "%u [label = \"", *node_id);
    for (int i = 0; prefix && prefix[i]; ++i) {
      fprintf(fs, "prefix[%d]:", i);
@@ -93,11 +93,11 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id)
    }
    fprintf(fs, "\"];\n");
    fprintf(fs, "%u -> %u\n", cur_id, *node_id);
    ++*node_id;
  }
  //arguments
  char **argv = node->body.child_cmd.argv;
  if (argv && argv[0]) {
    ++*node_id;
    fprintf(fs, "%u [label = \"", *node_id);
    for (int i = 0; argv && argv[i]; ++i) {
      fprintf(fs, "argv[%d]:", i);
@@ -110,11 +110,11 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id)
    }
    fprintf(fs, "\"];\n");
    fprintf(fs, "%u -> %u\n", cur_id, *node_id);
    ++*node_id;
  }
  //redirs
  if (node->body.child_cmd.redirs) {
    int i = 0;
    ++*node_id;
    fprintf(fs, "%u [label = \"", *node_id);
    for (s_redir *this = node->body.child_cmd.redirs; this; this = this->next, ++i) {
      fprintf(fs, "redirs[%d]: fd=%d, type=%d, word=", i, this->fd, this->type);
@@ -124,6 +124,7 @@ void ast_cmd_print(s_ast_node *node, FILE *fs, unsigned int *node_id)
	  fprintf(fs, "%.*s\\", p - last, this->word + last), last = p;
      fprintf(fs, "%*s", p - last, this->word + last), last = p;
      fprintf(fs, "\\n");
      ++*node_id;
    }
    fprintf(fs, "\"];\n");
    fprintf(fs, "%u -> %u\n", cur_id, *node_id);
+16 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@
** Login   <seblu@epita.fr>
**
** Started on  Thu Aug  3 02:41:37 2006 Seblu
** Last update Mon Aug 28 23:59:55 2006 Seblu
** Last update Tue Sep 26 17:45:54 2006 Seblu
*/

#include "ast.h"
@@ -21,6 +21,21 @@ s_ast_node *ast_or_create(s_ast_node *lhs, s_ast_node *rhs)
  return node;
}

void		ast_or_print(s_ast_node *node, FILE *fs, unsigned int *node_id)
{
  unsigned int	lhs_id, rhs_id, cur_id;

  if (node->type != T_OR)
    return;
  fprintf(fs, "%u [label = \"||\"];\n", cur_id = *node_id);
  lhs_id = ++*node_id;
  ast_print_node(node->body.child_or.lhs, fs, node_id);
  fprintf(fs, "%u -> %u\n", cur_id, lhs_id);
  rhs_id = *node_id;
  ast_print_node(node->body.child_or.rhs, fs, node_id);
  fprintf(fs, "%u -> %u\n", cur_id, rhs_id);
}

void		ast_or_destruct(s_ast_node *node)
{
  if (node->type != T_OR)
Loading