WhaleSpunk

Untitled

May 4th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 112.80 KB | None | 0 0
  1. %{
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5.  
  6. #define DEBUG 0
  7.  
  8. typedef struct AST_Tree{
  9. char *type;
  10. struct AST_Tree* child;
  11. struct AST_Tree* brother;
  12. char *value;
  13. char *notacao;
  14. struct AST_Tree* next;
  15. }AST_Tree_node;
  16.  
  17. typedef struct Table{
  18. char *name;
  19. char *type;
  20. char *paramsType;
  21. char *flag;
  22. struct Table* brother;
  23. struct Table* child;
  24. }Table_node;
  25.  
  26. typedef struct argumentos{
  27. char *paramsType;
  28. struct argumentos* next;
  29.  
  30. }argumentos_node;
  31.  
  32. argumentos_node *head_params=NULL;
  33. argumentos_node *head_func_table=NULL;
  34.  
  35.  
  36.  
  37. Table_node *head_table = NULL;
  38.  
  39.  
  40. AST_Tree_node *head = NULL;
  41.  
  42. AST_Tree_node* insertNode(char* node);
  43. AST_Tree_node* insert_value_node(char* node, char* value);
  44. void insert_child(AST_Tree_node* father, AST_Tree_node* child);
  45. void insert_brother(AST_Tree_node* brother, AST_Tree_node* node);
  46. void printTree(AST_Tree_node* aux, int level);
  47. void printTerminal(AST_Tree_node *node);
  48. void printPoints(int n);
  49.  
  50.  
  51. int tolower(int c);
  52.  
  53.  
  54. void printTable(Table_node *node);
  55. Table_node* insertNode_Table(char* node);
  56. Table_node* insert_value_node_Table(char* name, char* type, char* paramsType, char* flag);
  57. void insert_child_Table(Table_node* father, Table_node* child);
  58. void insert_brother_Table(Table_node* brother, Table_node* node);
  59. Table_node* find_symbol(char* name);
  60. Table_node* find_symbol_Method(char *name, char *params);
  61. Table_node *check_later_func(char *name, char *type);
  62. Table_node *check_later_vars_func(char *name);
  63. void insert_next(AST_Tree_node* first, AST_Tree_node *node);
  64.  
  65. int parse = 0;
  66. int flag=0;
  67. int aux2 = 0;
  68. int imprimir=0;
  69. int imprimir3=0;
  70. int yylex(void);
  71. void yyerror(const char *s);
  72.  
  73. extern int n_linha;
  74. extern int n_coluna;
  75. extern char * yytext;
  76. extern int yyleng;
  77.  
  78. Table_node *aux_node_table;
  79.  
  80. AST_Tree_node *nodeAux;
  81. AST_Tree_node *nodeAux2;
  82. AST_Tree_node *nodeAux3;
  83. AST_Tree_node *nodeAux4;
  84. AST_Tree_node *nodeAux5;
  85. Table_node *nodeAux_Table;
  86. Table_node *nodeAux_Table2;
  87. Table_node *nodeAux_Table3;
  88. Table_node *nodeAux_Table4;
  89.  
  90.  
  91.  
  92. Table_node *varDecl;
  93.  
  94. Table_node *current_Method;
  95.  
  96. AST_Tree_node *check_later;
  97. AST_Tree_node *check_later_vars;
  98.  
  99.  
  100.  
  101. %}
  102.  
  103. %union{
  104. char *str;
  105. struct AST_Tree *node_struct;
  106. }
  107.  
  108. %token <str> ID STRLIT BOOLLIT DECLIT REALLIT
  109.  
  110. %token PUBLIC BOOL INT DOUBLE SEMI COMMA PARSEINT OCURV OSQUARE CSQUARE CCURV ASSIGN AND OR EQ GEQ GT LEQ LT NEQ PLUS MINUS STAR DIV MOD NOT DOTLENGTH STATIC STRING VOID CLASS OBRACE CBRACE IF ELSE WHILE DO PRINT RETURN RESERVED
  111.  
  112. %type <node_struct> Program FieldDecl_MethodDecl_SEMI FieldDecl CommaID MethodDecl MethodHeader FormalParams CommaTypeID MethodBody VarDecl_Statement VarDecl Type Statement Statement_aux Expr ExprNew Assignment MethodInvocation CommaExpr ParseArgs
  113.  
  114.  
  115.  
  116. %left COMMA
  117. %right ASSIGN
  118. %left OR
  119. %left AND
  120. %left EQ NEQ
  121. %left LT GT LEQ GEQ
  122. %left MINUS PLUS
  123. %left STAR DIV MOD
  124. %right NOT
  125. %left OCURV OBRACE OSQUARE CCURV CBRACE CSQUARE
  126.  
  127. %nonassoc ELSE
  128.  
  129. %%
  130.  
  131.  
  132.  
  133.  
  134. Program: CLASS ID OBRACE FieldDecl_MethodDecl_SEMI CBRACE {if(flag == 0)
  135. {$$ = head = insertNode("Program");nodeAux = insert_value_node("Id", $2); insert_child($$, nodeAux);
  136. //head_table = insert_value_node_Table($2, "Class", "", "");
  137. //printf("\nHEAD TABLE TYPE: %s\n", head_table->type);
  138. head_table->name = $2;
  139. head_table->type = "Class";
  140.  
  141.  
  142.  
  143.  
  144. if($4!= NULL){
  145. insert_child($$, $4);
  146.  
  147. }
  148. if(imprimir3==1){
  149. char s[5] = " - ";
  150. char *token;
  151. while(check_later_vars !=NULL){
  152.  
  153.  
  154. if(strcmp(check_later_vars->type, "Assign") == 0){ //FALTA FAZER PARA TODAS AS OUTRAS EXPRESSIONS (MINUS, STAR, DIV, MOD)...
  155. Table_node *var = check_later_vars_func(check_later_vars->child->value);
  156. //printf("\nCHECK LATER VAR VALUE: %s; VAR VALUE: %s\n", check_later_vars->child->value, var->type);
  157. if(strcmp(var->type, "") == 0){
  158. //printf("\n-------ERRO!-----\n");
  159. check_later_vars->notacao = (char *)malloc(sizeof(" - undef"));
  160. strcpy(check_later_vars->notacao, " - undef");
  161. check_later_vars->child->notacao = (char *)malloc(sizeof(" - undef"));
  162. strcpy(check_later_vars->child->notacao, " - undef");
  163. }else{
  164. char var_type[100];
  165.  
  166. strcpy(var_type, " - ");
  167.  
  168. strcat(var_type, var->type);
  169. check_later_vars->notacao = (char *)malloc(sizeof(var_type));
  170.  
  171. strcpy(check_later_vars->notacao, var_type);
  172.  
  173. check_later_vars->child->notacao = (char *)malloc(sizeof(var_type));
  174. strcpy(check_later_vars->child->notacao, var_type);
  175.  
  176. }
  177. }else if (strcmp(check_later_vars->type, "Id") == 0){
  178. Table_node *var = check_later_vars_func(check_later_vars->value);
  179. if(strcmp(var->type, "") == 0){
  180. check_later_vars->notacao = (char *)malloc(sizeof(" - undef"));
  181. strcpy(check_later_vars->notacao, " - undef");
  182. }else{
  183.  
  184. char var_type[100];
  185.  
  186. strcpy(var_type, " - ");
  187.  
  188. strcat(var_type, var->type);
  189. check_later_vars->notacao = (char *)malloc(sizeof(var_type));
  190.  
  191. strcpy(check_later_vars->notacao, var_type);
  192.  
  193. }
  194.  
  195. }
  196.  
  197.  
  198.  
  199. check_later_vars = check_later_vars->next;
  200.  
  201. }
  202.  
  203.  
  204.  
  205.  
  206. while(check_later != NULL){
  207. char type[100];
  208. char name[100];
  209.  
  210. strcpy(name, check_later->child->value);
  211.  
  212. strcpy(type, "(");
  213.  
  214. AST_Tree_node *aux = check_later->child->brother;
  215. while(aux != NULL){
  216.  
  217. token = strtok(aux->notacao, s);
  218. if(token != NULL){
  219. strcat(type, token);
  220.  
  221. if(aux->brother !=NULL){
  222. strcat(type, ",");
  223. }
  224. }
  225. aux = aux->brother;
  226.  
  227.  
  228. }
  229. strcat(type, ")");
  230. Table_node *method = find_symbol_Method(name, type);
  231. //printf("\nname: %s; type: %s; method->type: %s;\n", name, type, method->type);
  232. if(strcmp(method->type, "") == 0){
  233. //printf("\n-------ERRO!-----\n");
  234. check_later->notacao = (char *)malloc(sizeof(" - undef"));
  235. strcpy(check_later->notacao, " - undef");
  236. check_later->child->notacao = (char *)malloc(sizeof(" - undef"));
  237. strcpy(check_later->child->notacao, " - undef");
  238.  
  239.  
  240. }else{
  241. char call_type[100];
  242.  
  243. strcpy(call_type, " - ");
  244.  
  245. strcat(call_type, method->type);
  246. check_later->notacao = (char *)malloc(sizeof(call_type));
  247.  
  248. strcpy(check_later->notacao, call_type);
  249.  
  250.  
  251. char methodID_type[100];
  252.  
  253. strcpy(methodID_type, " - ");
  254. /*if(strcmp(method->paramsType, "") == 0){
  255. strcat(methodID_type, "()");
  256. check_later->child->notacao = (char *)malloc(sizeof(methodID_type));
  257. }else{
  258. strcat(methodID_type, method->paramsType);
  259. check_later->child->notacao = (char *)malloc(sizeof(methodID_type));
  260.  
  261. }*/
  262. strcat(methodID_type, method->paramsType);
  263. check_later->child->notacao = (char *)malloc(sizeof(methodID_type));
  264.  
  265. strcpy(check_later->child->notacao, methodID_type);
  266.  
  267.  
  268. }
  269.  
  270. check_later = check_later->next;
  271. }
  272.  
  273.  
  274.  
  275.  
  276.  
  277. }
  278. }
  279.  
  280. }
  281. | CLASS ID OBRACE CBRACE {if(flag==0){
  282. $$ = head = insertNode("Program");
  283. nodeAux = insert_value_node("Id", $2);
  284. insert_child($$, nodeAux);head_table= insertNode_Table($2);
  285. aux_node_table=insertNode_Table($2);
  286. //head_table= insert_value_node_Table($2, "Class", "", "");
  287. head_table->name = $2;
  288. head_table->type = "Class";
  289. }
  290. }
  291. ;
  292.  
  293. FieldDecl_MethodDecl_SEMI: FieldDecl_MethodDecl_SEMI FieldDecl {if(flag ==0){if($1 != NULL){$$ =$1;insert_brother($$, $2);}else{$$ = $2;}}}
  294. | FieldDecl_MethodDecl_SEMI MethodDecl {if(flag == 0){if($1 != NULL){$$=$1; insert_brother($$, $2);}else{$$ = $2;}}}
  295. | FieldDecl_MethodDecl_SEMI SEMI {if(flag == 0){if($1 != NULL){$$ = $1;}else{$$ = NULL;}}}
  296. | FieldDecl {if(flag ==0 ){$$ = $1;}}
  297. | MethodDecl {if(flag == 0){$$ = $1 ;}}
  298. | SEMI {if(flag == 0){$$ = NULL;}}
  299. ;
  300.  
  301.  
  302.  
  303.  
  304.  
  305. FieldDecl: PUBLIC STATIC Type ID CommaID SEMI {if(flag ==0){
  306. int i=0;
  307. int length4 = strlen($3->type);
  308. char* lower4 = ( char* )malloc( length4 + 1 );
  309. Table_node *check = check_later_vars_func($4);
  310. if(strcmp(check->type, "" )== 0){
  311. if(strcmp($3->type, "Bool")==0){
  312. nodeAux_Table = insert_value_node_Table($4, "boolean", "", "");
  313. }else{
  314.  
  315. lower4[length4] = 0;
  316. for(i = 0; i < length4; i++ )
  317. {
  318. lower4[i] = tolower( $3->type[i]);
  319. }
  320.  
  321.  
  322. nodeAux_Table = insert_value_node_Table($4, lower4, "", "");
  323.  
  324.  
  325. }
  326.  
  327. insert_child_Table(head_table, nodeAux_Table);
  328. }
  329. $$ = insertNode("FieldDecl");
  330. insert_child($$, $3);
  331. AST_Tree_node *nodeAuxaux = insert_value_node("Id", $4);
  332. insert_child($$, nodeAuxaux);
  333. nodeAux2 = $5;
  334. AST_Tree_node *node = nodeAux2;
  335. AST_Tree_node *copy;
  336. AST_Tree_node *copy2;
  337.  
  338. while(node != NULL){
  339.  
  340.  
  341. check = check_later_vars_func(node->value);
  342. if(strcmp(check->type, "")==0){
  343. if(strcmp($3->type, "Bool")==0){
  344. insert_child_Table(head_table, insert_value_node_Table(node->value, "boolean", "", ""));
  345. }else{
  346.  
  347. insert_child_Table(head_table, insert_value_node_Table(node->value, lower4, "", ""));
  348. }
  349. }
  350.  
  351.  
  352.  
  353. copy = insertNode($3->type);
  354. copy2 = insert_value_node("Id", node->value);
  355. nodeAux3 = insertNode("FieldDecl");
  356. insert_brother($$, nodeAux3);
  357. insert_child(nodeAux3, copy);
  358. insert_child(nodeAux3, copy2);
  359. node = nodeAux2->brother;
  360. nodeAux2 = nodeAux2->brother;
  361. }
  362.  
  363. }
  364.  
  365. }
  366.  
  367. | PUBLIC STATIC Type ID SEMI {if(flag == 0){
  368.  
  369. int i=0;
  370. int length7 = strlen($3->type);
  371. char* lower7 = ( char* )malloc( length7 + 1 );
  372. $$ = insertNode("FieldDecl");
  373. insert_child($$, $3);
  374. nodeAux = insert_value_node("Id", $4);
  375. insert_child($$, nodeAux);
  376.  
  377.  
  378.  
  379. Table_node *check = check_later_vars_func($4);
  380. if(strcmp(check->type, "" )== 0){
  381. if(strcmp($3->type, "Bool")==0){
  382.  
  383. nodeAux_Table = insert_value_node_Table($4, "boolean", "", "");
  384. }else{
  385.  
  386. lower7[length7] = 0;
  387. for(i = 0; i < length7; i++ )
  388. {
  389. lower7[i] = tolower( $3->type[i] );
  390. }
  391.  
  392.  
  393. nodeAux_Table = insert_value_node_Table($4, lower7, "", "");
  394.  
  395.  
  396. }
  397.  
  398.  
  399.  
  400.  
  401.  
  402.  
  403.  
  404.  
  405. insert_child_Table(head_table, nodeAux_Table);
  406. }
  407.  
  408.  
  409.  
  410. }
  411. }
  412. | error SEMI {flag = 1;$$=NULL;}
  413. ;
  414.  
  415. CommaID: CommaID COMMA ID {if(flag == 0){$$ = $1 ; nodeAux = insert_value_node("Id", $3); insert_brother($$, nodeAux);}}
  416. | COMMA ID {if(flag == 0){$$ = insert_value_node("Id", $2);}}
  417. ;
  418.  
  419. MethodDecl: PUBLIC STATIC MethodHeader MethodBody {if(flag ==0 ){
  420.  
  421. $$ = insertNode("MethodDecl");
  422. insert_child($$, $3);
  423. insert_child($$, $4);
  424.  
  425.  
  426. if(strcmp(current_Method->type, "") != 0){
  427. insert_child_Table(head_table, current_Method);
  428. current_Method= insert_value_node_Table("", "", "", "");
  429. }
  430.  
  431.  
  432.  
  433.  
  434.  
  435.  
  436. }
  437. }
  438. ;
  439.  
  440. MethodHeader: Type ID OCURV FormalParams CCURV {if(flag == 0){
  441. int i;
  442. $$ = insertNode("MethodHeader");
  443. insert_child($$, $1);
  444. nodeAux = insert_value_node("Id", $2);
  445. insert_child($$, nodeAux);
  446. insert_child($$, $4);
  447.  
  448.  
  449.  
  450.  
  451.  
  452.  
  453. nodeAux_Table = insertNode_Table($2);
  454.  
  455.  
  456.  
  457. nodeAux_Table->type = $1->type;
  458.  
  459.  
  460.  
  461. if(strcmp(nodeAux_Table->type, "Bool")==0){
  462. nodeAux_Table->type = "boolean";
  463. insert_child_Table(nodeAux_Table, insert_value_node_Table("return", "boolean", "", ""));
  464. }else{
  465. int length2 = strlen(nodeAux_Table->type);
  466. char* lower2 = ( char* )malloc( length2 + 1 );
  467. lower2[length2] = 0;
  468. for(i = 0; i < length2; i++ )
  469. {
  470. lower2[i] = tolower( nodeAux_Table->type[i] );
  471. }
  472. nodeAux_Table->type = lower2;
  473.  
  474. insert_child_Table(nodeAux_Table, insert_value_node_Table("return", lower2,"",""));
  475. }
  476.  
  477.  
  478.  
  479.  
  480.  
  481. nodeAux4 = $4;
  482.  
  483. char param[100];
  484. strcpy(param, "(");
  485. AST_Tree_node *node = nodeAux4->child;
  486. while(node!=NULL){
  487.  
  488. if(strcmp(node->child->type, "Bool")==0){
  489. strcat(param, "boolean");
  490. insert_child_Table(nodeAux_Table, insert_value_node_Table(node->child->brother->value, "boolean", "", "param"));
  491. }else if(strcmp(node->child->type, "StringArray")==0){
  492. strcat(param, "String[]");
  493. insert_child_Table(nodeAux_Table, insert_value_node_Table(node->child->brother->value, "String[]", "", "param"));
  494.  
  495. }else{
  496.  
  497. int length = strlen(node->child->type);
  498. char* lower = ( char* )malloc( length + 1 );
  499. lower[length] = 0;
  500. for(i = 0; i < length; i++ )
  501. {
  502. lower[i] = tolower( node->child->type[i] );
  503. }
  504.  
  505.  
  506. strcat(param, lower);
  507. insert_child_Table(nodeAux_Table, insert_value_node_Table(node->child->brother->value, lower, "", "param"));
  508.  
  509. }
  510.  
  511. if( node->brother != NULL){
  512. strcat(param, ",");
  513. }
  514.  
  515.  
  516.  
  517. node = node->brother;
  518.  
  519.  
  520. }
  521. strcat(param, ")\0");
  522. nodeAux_Table->paramsType =(char *)malloc(sizeof(param)+1);
  523. strcpy(nodeAux_Table->paramsType, param);
  524. nodeAux_Table->flag = "";
  525.  
  526.  
  527.  
  528. //insert_child_Table(head_table, nodeAux_Table);
  529.  
  530.  
  531. current_Method = nodeAux_Table;
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.  
  544.  
  545.  
  546. }
  547. }
  548. | Type ID OCURV CCURV {if(flag == 0){
  549. int i=0;
  550. $$ = insertNode("MethodHeader");
  551. insert_child($$, $1);
  552. nodeAux = insert_value_node("Id", $2);
  553. insert_child($$, nodeAux);
  554. nodeAux3=insertNode("MethodParams");
  555. insert_child($$,nodeAux3);
  556.  
  557. nodeAux_Table = insertNode_Table($2);
  558.  
  559. nodeAux_Table->type = $1->type;
  560.  
  561. if(strcmp(nodeAux_Table->type, "Bool")==0){
  562. nodeAux_Table->type = "boolean";
  563. insert_child_Table(nodeAux_Table, insert_value_node_Table("return", "boolean", "", ""));
  564. }else{
  565. int length2 = strlen(nodeAux_Table->type);
  566. char* lower2 = ( char* )malloc( length2 + 1 );
  567. lower2[length2] = 0;
  568. for(i = 0; i < length2; i++ )
  569. {
  570. lower2[i] = tolower( nodeAux_Table->type[i] );
  571. }
  572. nodeAux_Table->type = lower2;
  573.  
  574. insert_child_Table(nodeAux_Table, insert_value_node_Table("return", lower2,"",""));
  575. }
  576.  
  577. char param[100];
  578. strcpy(param, "()");
  579.  
  580. nodeAux_Table->paramsType =(char *)malloc(sizeof(param)+1);
  581. strcpy(nodeAux_Table->paramsType, param);
  582. nodeAux_Table->flag = "";
  583.  
  584.  
  585.  
  586. //insert_child_Table(head_table, nodeAux_Table);
  587.  
  588.  
  589. current_Method = nodeAux_Table;
  590.  
  591. }
  592.  
  593. }
  594. | VOID ID OCURV FormalParams CCURV {if(flag == 0){
  595. int i=0;
  596. $$ = insertNode("MethodHeader");
  597. nodeAux = insertNode("Void");
  598. insert_child($$, nodeAux);
  599. nodeAux2 = insert_value_node("Id", $2);
  600. insert_child($$, nodeAux2);
  601. insert_child($$, $4);
  602.  
  603. nodeAux_Table = insertNode_Table($2);
  604.  
  605. nodeAux_Table->type = "void";
  606. insert_child_Table(nodeAux_Table, insert_value_node_Table("return", "void","",""));
  607.  
  608.  
  609.  
  610.  
  611. nodeAux4 = $4;
  612.  
  613. char param[100];
  614. strcpy(param, "(");
  615. AST_Tree_node *node = nodeAux4->child;
  616. while(node!=NULL){
  617.  
  618. if(strcmp(node->child->type, "Bool")==0){
  619. strcat(param, "boolean");
  620. insert_child_Table(nodeAux_Table, insert_value_node_Table(node->child->brother->value, "boolean", "", "param"));
  621. }else if(strcmp(node->child->type, "StringArray")==0){
  622. strcat(param, "String[]");
  623. insert_child_Table(nodeAux_Table, insert_value_node_Table(node->child->brother->value, "String[]", "", "param"));
  624.  
  625. }else{
  626.  
  627. int length = strlen(node->child->type);
  628. char* lower = ( char* )malloc( length + 1 );
  629. lower[length] = 0;
  630. for(i = 0; i < length; i++ )
  631. {
  632. lower[i] = tolower( node->child->type[i] );
  633. }
  634.  
  635.  
  636. strcat(param, lower);
  637. insert_child_Table(nodeAux_Table, insert_value_node_Table(node->child->brother->value, lower, "", "param"));
  638.  
  639. }
  640.  
  641. if( node->brother != NULL){
  642. strcat(param, ",");
  643. }
  644.  
  645.  
  646.  
  647. node = node->brother;
  648.  
  649.  
  650. }
  651. strcat(param, ")\0");
  652. nodeAux_Table->paramsType =(char *)malloc(sizeof(param)+1);
  653. strcpy(nodeAux_Table->paramsType, param);
  654. nodeAux_Table->flag = "";
  655.  
  656. current_Method = nodeAux_Table;
  657.  
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664. }
  665. }
  666. | VOID ID OCURV CCURV {if(flag == 0){
  667. $$ = insertNode("MethodHeader");
  668. nodeAux = insertNode("Void");
  669. insert_child($$, nodeAux);
  670. nodeAux2 = insert_value_node("Id", $2);
  671. insert_child($$, nodeAux2);
  672. nodeAux3=insertNode("MethodParams");
  673. insert_child($$,nodeAux3);
  674.  
  675.  
  676. nodeAux_Table = insertNode_Table($2);
  677.  
  678. nodeAux_Table->type = "void";
  679. insert_child_Table(nodeAux_Table, insert_value_node_Table("return", "void","",""));
  680.  
  681. char param[100];
  682. strcpy(param, "(");
  683. strcat(param, ")\0");
  684. nodeAux_Table->paramsType =(char *)malloc(sizeof(param)+1);
  685. strcpy(nodeAux_Table->paramsType, param);
  686. nodeAux_Table->flag = "";
  687.  
  688.  
  689.  
  690. //insert_child_Table(head_table, nodeAux_Table);
  691.  
  692.  
  693. current_Method = nodeAux_Table;
  694.  
  695.  
  696.  
  697.  
  698.  
  699. }
  700.  
  701. }
  702. ;
  703.  
  704.  
  705.  
  706.  
  707.  
  708. FormalParams: Type ID CommaTypeID {if(flag == 0){
  709. $$ = insertNode("MethodParams");
  710. nodeAux2 = insertNode("ParamDecl");
  711. insert_child($$, nodeAux2);
  712. insert_child(nodeAux2, $1);
  713. nodeAux = insert_value_node("Id", $2);
  714. insert_child(nodeAux2, nodeAux);
  715. nodeAux2 = $3;
  716. AST_Tree_node *node = nodeAux2;
  717. AST_Tree_node *copy;
  718. AST_Tree_node *copy2;
  719. while(node!=NULL){
  720.  
  721. copy = insertNode(node->type);
  722. copy2 = insert_value_node("Id", node->brother->value);
  723. nodeAux3 = insertNode("ParamDecl");
  724. insert_child($$, nodeAux3);
  725. insert_child(nodeAux3, copy);
  726. insert_child(nodeAux3, copy2);
  727. node = node->brother->brother;
  728.  
  729. }
  730.  
  731. }}
  732. | Type ID {if(flag == 0){$$ = insertNode("MethodParams"); nodeAux2 = insertNode("ParamDecl"); insert_child($$, nodeAux2); insert_child(nodeAux2, $1); nodeAux = insert_value_node("Id", $2); insert_child(nodeAux2, nodeAux);}}
  733. | STRING OSQUARE CSQUARE ID {if(flag == 0){$$ = insertNode("MethodParams"); nodeAux2 = insertNode("ParamDecl"); insert_child($$, nodeAux2); nodeAux = insertNode("StringArray"); insert_child(nodeAux2, nodeAux); nodeAux3 = insert_value_node("Id", $4); insert_child(nodeAux2, nodeAux3);}}
  734. ;
  735.  
  736.  
  737. CommaTypeID: COMMA Type ID {if(flag == 0){$$ = $2; nodeAux = insert_value_node("Id", $3); insert_brother($$, nodeAux);}}
  738. | CommaTypeID COMMA Type ID {if(flag ==0){$$ = $1; insert_brother($$, $3); nodeAux2 = insert_value_node("Id", $4); insert_brother($$, nodeAux2);}}
  739. ;
  740.  
  741.  
  742. MethodBody: OBRACE VarDecl_Statement CBRACE {if(flag == 0){$$ = insertNode("MethodBody"); if($2!=NULL){insert_child($$, $2);}}}
  743. | OBRACE CBRACE {if(flag == 0){$$ = insertNode("MethodBody");}}
  744. ;
  745.  
  746.  
  747. VarDecl_Statement: VarDecl {if(flag == 0){$$ = $1;}}
  748. | Statement {if(flag == 0){$$ = $1;}}
  749. | VarDecl_Statement VarDecl {if(flag == 0){if($1!=NULL){$$=$1;insert_brother($1,$2);}else{$$=$2;}}}
  750. | VarDecl_Statement Statement {if(flag == 0){if($1!=NULL){$$ = $1;if($2!=NULL){insert_brother($1,$2);}}else{$$=$2;}}}
  751.  
  752.  
  753. VarDecl: Type ID CommaID SEMI {if(flag == 0){
  754.  
  755. int i = 0;
  756. int length5 = strlen($1->type);
  757. char* lower5 = ( char* )malloc( length5 + 1 );
  758. $$ = insertNode("VarDecl");
  759. insert_child($$,$1);
  760.  
  761. nodeAux = insert_value_node("Id", $2);
  762. insert_child($$, nodeAux);
  763. nodeAux2 = $3;
  764. AST_Tree_node *node = nodeAux2;
  765. AST_Tree_node *copy;
  766. AST_Tree_node *copy2;
  767.  
  768.  
  769.  
  770. Table_node *check_var = check_later_vars_func($2);
  771. //Table_node *check_var2 = check_varDecl($2);
  772. if(strcmp(check_var->type, "") ==0){
  773. if(strcmp($1->type, "Bool") == 0){
  774.  
  775. if(strcmp(varDecl->type, "")==0){
  776. varDecl = insert_value_node_Table($2, "boolean", "", "");
  777. }else{
  778. insert_brother_Table(varDecl, insert_value_node_Table($2, "boolean", "", ""));
  779.  
  780. }
  781.  
  782.  
  783.  
  784.  
  785. }else{
  786.  
  787. lower5[length5] = 0;
  788. for(i = 0; i < length5; i++ )
  789. {
  790. lower5[i] = tolower( $1->type[i] );
  791. }
  792.  
  793.  
  794.  
  795. if(strcmp(varDecl->type, "") == 0){
  796. varDecl = insert_value_node_Table($2, lower5, "", "");
  797. }else{
  798. insert_brother_Table(varDecl, insert_value_node_Table($2, lower5, "", ""));
  799.  
  800. }
  801.  
  802. }
  803. }
  804.  
  805. while(node != NULL){
  806. check_var = check_later_vars_func(node->value);
  807. if(strcmp(check_var->type, "") ==0){
  808. if(strcmp($1->type, "Bool") == 0){
  809.  
  810. insert_brother_Table(varDecl, insert_value_node_Table(node->value, "boolean", "", ""));
  811.  
  812. }else{
  813. insert_brother_Table(varDecl, insert_value_node_Table(node->value, lower5, "", ""));
  814.  
  815. }
  816. }
  817.  
  818.  
  819. copy = insertNode($1->type);
  820. copy2 = insert_value_node("Id", node->value);
  821. nodeAux3 = insertNode("VarDecl");
  822. insert_brother($$, nodeAux3);
  823. insert_child(nodeAux3, copy);
  824. insert_child(nodeAux3, copy2);
  825. node = nodeAux2->brother;
  826. nodeAux2 = nodeAux2->brother;
  827. }
  828.  
  829.  
  830.  
  831.  
  832. if(strcmp(varDecl->type, "")!=0){
  833. insert_child_Table(current_Method, varDecl);
  834. varDecl = insert_value_node_Table("", "", "", "");
  835. }
  836.  
  837.  
  838. }}
  839.  
  840. | Type ID SEMI {if(flag == 0){
  841. int i = 0;
  842. int length6 = strlen($1->type);
  843. char* lower6 = ( char* )malloc( length6 + 1 );
  844.  
  845.  
  846. if(strcmp($1->type, "Bool") == 0){
  847.  
  848. if(strcmp(varDecl->type, "")== 0){
  849.  
  850. varDecl = insert_value_node_Table($2, "boolean", "", "");
  851. }else{
  852.  
  853. insert_brother_Table(varDecl, insert_value_node_Table($2, "boolean", "", ""));
  854.  
  855. }
  856.  
  857. }else{
  858.  
  859. lower6[length6] = 0;
  860. for(i = 0; i < length6; i++ )
  861. {
  862. lower6[i] = tolower( $1->type[i] );
  863. }
  864.  
  865.  
  866. if(strcmp(varDecl->type, "")==0){
  867. varDecl = insert_value_node_Table($2, lower6, "", "");
  868. }else{
  869. insert_brother_Table(varDecl, insert_value_node_Table($2, lower6, "", ""));
  870.  
  871. }
  872.  
  873.  
  874. }
  875.  
  876.  
  877. if(strcmp(varDecl->type, "")!=0){
  878. insert_child_Table(current_Method, varDecl);
  879. varDecl = insert_value_node_Table("", "", "", "");
  880. }
  881.  
  882.  
  883.  
  884. $$ = insertNode("VarDecl");
  885. insert_child($$, $1);
  886. nodeAux2 = insert_value_node("Id", $2);
  887. insert_child($$, nodeAux2);
  888.  
  889. }
  890. }
  891. ;
  892.  
  893. Type: BOOL {if(flag == 0){$$ = insertNode("Bool");}}
  894. | INT {if(flag == 0){$$ = insertNode("Int");}}
  895. | DOUBLE {if(flag == 0){$$ =insertNode("Double");}}
  896. ;
  897.  
  898. Statement: OBRACE Statement_aux CBRACE {if(flag ==0){
  899. if($2!=NULL){
  900. if($2->brother!=NULL){
  901. nodeAux=insertNode("Block");
  902. insert_child(nodeAux,$2);
  903. $$=nodeAux;
  904. }
  905. else{
  906. $$=$2;
  907. }
  908. }
  909. else{
  910. $$=NULL;
  911. }
  912. }}
  913. | OBRACE CBRACE {if(flag==0){$$ = NULL;}}
  914. | IF OCURV Expr CCURV Statement {
  915. if(flag==0){
  916. $$=insertNode("If");
  917. insert_child($$,$3);
  918. nodeAux = $5;
  919. int num=0;
  920. if(nodeAux != NULL){
  921. AST_Tree_node *node = nodeAux;
  922. while(node!= NULL){
  923. node = node->brother;
  924. num++;
  925. }
  926. if(num==1){
  927. insert_child($$,nodeAux);
  928. nodeAux2 = insertNode("Block");
  929. insert_child($$, nodeAux2);
  930. }
  931. if(num>1){
  932. nodeAux2 = insertNode("Block");
  933. nodeAux3 = insertNode("Block");
  934. insert_child(nodeAux2, nodeAux);
  935. insert_child($$,nodeAux2);
  936. insert_brother(nodeAux2,nodeAux3);
  937. }
  938. }
  939. if(nodeAux==NULL)
  940. {
  941. nodeAux2 = insertNode("Block");
  942. nodeAux3 = insertNode("Block");
  943. insert_child($$, nodeAux2);
  944. insert_child($$, nodeAux3);
  945. }
  946. }
  947. }
  948.  
  949. | IF OCURV Expr CCURV Statement ELSE Statement {
  950. if(flag==0){
  951. $$=insertNode("If");
  952. insert_child($$,$3);
  953. nodeAux = $5;
  954. int num=0, num2=0;
  955.  
  956. if(nodeAux != NULL){
  957. AST_Tree_node *node = nodeAux;
  958. while(node!= NULL){
  959. node = node->brother;
  960. num++;
  961. }
  962. if(num==1){
  963. insert_child($$,nodeAux);
  964.  
  965. }
  966. if(num>1){
  967. nodeAux2 = insertNode("Block");
  968. insert_child(nodeAux2, nodeAux);
  969. insert_child($$,nodeAux2);
  970.  
  971. }
  972. }
  973. else if(nodeAux==NULL)
  974. {
  975. nodeAux2 = insertNode("Block");
  976. insert_child($$, nodeAux2);
  977.  
  978. }
  979.  
  980. if($7!=NULL)
  981. {
  982. AST_Tree_node *node2 = $7;
  983. while(node2!= NULL){
  984. node2 = node2->brother;
  985. num2++;
  986. }
  987. if(num2==1){
  988. insert_child($$,$7);
  989.  
  990. }
  991. if(num2>1){
  992. nodeAux2 = insertNode("Block");
  993. insert_child(nodeAux2, $7);
  994. insert_child($$,nodeAux2);
  995.  
  996. }
  997. }
  998.  
  999. else if($7==NULL)
  1000. {
  1001. nodeAux2 = insertNode("Block");
  1002. insert_child($$, nodeAux2);
  1003. }
  1004. }
  1005.  
  1006.  
  1007. }
  1008. | WHILE OCURV Expr CCURV Statement {
  1009. if(flag==0){
  1010. $$=insertNode("While");
  1011. insert_child($$,$3);
  1012. nodeAux = $5;
  1013. int num=0;
  1014. if(nodeAux != NULL){
  1015. AST_Tree_node *node = nodeAux;
  1016. while(node!= NULL){
  1017. node = node->brother;
  1018. num++;
  1019. }
  1020. if(num==1){
  1021. insert_child($$,nodeAux);
  1022.  
  1023. }
  1024. if(num>1){
  1025. nodeAux2 = insertNode("Block");
  1026. insert_child(nodeAux2, nodeAux);
  1027. insert_child($$,nodeAux2);
  1028.  
  1029. }
  1030. }
  1031. if(nodeAux==NULL)
  1032. {
  1033. nodeAux2 = insertNode("Block");
  1034. insert_child($$, nodeAux2);
  1035.  
  1036. }
  1037. }
  1038. }
  1039. | DO Statement WHILE OCURV Expr CCURV SEMI {
  1040. if(flag==0){
  1041. $$=insertNode("DoWhile");
  1042. if($2==NULL)
  1043. {
  1044. nodeAux2 = insertNode("Block");
  1045. insert_child($$, nodeAux2);
  1046.  
  1047. }else{
  1048. insert_child($$,$2);
  1049. }
  1050.  
  1051.  
  1052. nodeAux = $5;
  1053. int num=0;
  1054. if(nodeAux != NULL){
  1055. AST_Tree_node *node = nodeAux;
  1056. while(node!= NULL){
  1057. node = node->brother;
  1058. num++;
  1059. }
  1060. if(num==1){
  1061. insert_child($$,nodeAux);
  1062.  
  1063. }
  1064. if(num>1){
  1065. nodeAux2 = insertNode("Block");
  1066. insert_child(nodeAux2, nodeAux);
  1067. insert_child($$,nodeAux2);
  1068.  
  1069. }
  1070. }
  1071.  
  1072. }
  1073. }
  1074. | PRINT OCURV Expr CCURV SEMI {
  1075. if(flag==0){
  1076.  
  1077. $$=insertNode("Print");
  1078. insert_child($$,$3);
  1079. }
  1080. }
  1081. | PRINT OCURV STRLIT CCURV SEMI {
  1082. if(flag==0){
  1083.  
  1084.  
  1085. $$=insertNode("Print");
  1086. nodeAux = insert_value_node("StrLit", $3);
  1087. if(imprimir3==1){
  1088. nodeAux->notacao=" - String";
  1089. }
  1090. insert_child($$, nodeAux);
  1091. }
  1092. }
  1093. | SEMI {
  1094. if(flag==0){
  1095. $$=NULL;
  1096. }
  1097. }
  1098. | Assignment SEMI {
  1099. if(flag==0){
  1100. $$=$1;
  1101. }
  1102. }
  1103. | MethodInvocation SEMI {
  1104. if(flag==0){
  1105. $$=$1;
  1106. }
  1107. }
  1108. | ParseArgs SEMI {
  1109. if(flag==0){
  1110. $$=$1;
  1111. }
  1112. }
  1113. | RETURN SEMI {
  1114. if(flag==0){
  1115. $$ = insertNode("Return");
  1116. }
  1117. }
  1118. | RETURN Expr SEMI {
  1119. if(flag==0){
  1120. $$ = insertNode("Return");
  1121. insert_child($$,$2);
  1122.  
  1123. }
  1124. }
  1125. | error SEMI {flag = 1;$$=NULL;}
  1126. ;
  1127.  
  1128.  
  1129.  
  1130. Statement_aux: Statement {if(flag==0){$$=$1;}}
  1131. | Statement_aux Statement {if(flag==0){if($1!=NULL){$$ = $1; insert_brother($1,$2);}else{$$=$2;}}}
  1132. ;
  1133.  
  1134.  
  1135.  
  1136. Expr: ExprNew {if(flag == 0){$$ = $1;}}
  1137. | Assignment {if(flag == 0){$$ = $1;}}
  1138. ;
  1139.  
  1140. ExprNew: MethodInvocation {if(flag == 0){$$ = $1;}}
  1141. | ParseArgs {if(flag == 0){$$ = $1;}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - int"));strcpy($$->notacao, " - int");}}
  1142. | ExprNew AND ExprNew {if(flag == 0){$$ = insertNode("And"); insert_child($$, $1); insert_child($$, $3);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1143. | ExprNew OR ExprNew {if(flag == 0){$$ = insertNode("Or"); insert_child($$, $1); insert_child($$, $3);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1144. | ExprNew EQ ExprNew {if(flag == 0){$$ = insertNode("Eq"); insert_child($$, $1); insert_child($$, $3);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1145. | ExprNew GEQ ExprNew {if(flag == 0){$$ = insertNode("Geq"); insert_child($$, $1); insert_child($$, $3);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1146. | ExprNew GT ExprNew {if(flag == 0){$$ = insertNode("Gt"); insert_child($$, $1); insert_child($$, $3);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1147. | ExprNew LEQ ExprNew {if(flag == 0){$$ = insertNode("Leq"); insert_child($$, $1); insert_child($$, $3);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1148. | ExprNew LT ExprNew {if(flag == 0){$$ = insertNode("Lt"); insert_child($$, $1); insert_child($$, $3);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1149. | ExprNew NEQ ExprNew {if(flag == 0){$$ = insertNode("Neq"); insert_child($$, $1); insert_child($$, $3);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1150. | ExprNew PLUS ExprNew {if(flag == 0){$$ = insertNode("Add"); insert_child($$, $1); insert_child($$, $3);}
  1151. if(imprimir3==1){
  1152. int erro_aux = 0;
  1153. Table_node *aux;
  1154. Table_node *aux2;
  1155.  
  1156.  
  1157. char s[5] = " - ";
  1158. char *token;
  1159. if(strcmp($1->type, "Id") == 0){
  1160. aux = find_symbol($$->child->value);
  1161.  
  1162. }else{
  1163.  
  1164. aux = insert_value_node_Table("", "", "", "");
  1165. token = strtok($$->child->notacao, s);
  1166. char var2[100];
  1167. strcpy(var2, token);
  1168. aux->type = (char *)malloc(sizeof(var2)+1);;
  1169. strcpy(aux->type, var2);
  1170.  
  1171.  
  1172. }
  1173. if(strcmp($3->type, "Id") == 0){
  1174.  
  1175. aux2 = find_symbol($$->child->brother->value);
  1176. }
  1177. else{
  1178. aux2 = insert_value_node_Table("", "", "", "");
  1179. token = strtok($$->child->brother->notacao, s);
  1180. char var[100];
  1181. strcpy(var, token);
  1182. aux2->type = (char *)malloc(sizeof(var)+1);
  1183.  
  1184. strcpy(aux2->type, var);
  1185.  
  1186.  
  1187.  
  1188. }
  1189.  
  1190.  
  1191.  
  1192.  
  1193.  
  1194. if(strcmp(aux->type, "") == 0){
  1195. $1->notacao = (char *)malloc(sizeof(" - undef"));
  1196. strcpy($1->notacao, " - undef");
  1197. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1198. strcpy($$->notacao, " - undef");
  1199. //printf("\n-----ERRO!-----\n");
  1200. erro_aux = 1;
  1201.  
  1202. }
  1203. if(strcmp(aux2->type, "")==0){
  1204. $3->notacao = (char *)malloc(sizeof(" - undef"));
  1205. strcpy($3->notacao, " - undef");
  1206. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1207. strcpy($$->notacao, " - undef");
  1208. //printf("\n-----ERRO!-----\n");
  1209. erro_aux =1;
  1210. }
  1211.  
  1212. if(erro_aux ==0){
  1213. char aux_string[100];
  1214.  
  1215. if(strcmp(aux->type, "String") ==0 || strcmp(aux2->type, "String")==0){
  1216. strcpy(aux_string, " - ");
  1217. strcat(aux_string, "String");
  1218. strcat(aux_string, "\0");
  1219. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1220. strcpy($$->notacao, aux_string);
  1221.  
  1222. }else if((strcmp(aux->type, "double") ==0 || strcmp(aux2->type, "double")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1223.  
  1224.  
  1225.  
  1226. strcpy(aux_string, " - ");
  1227. strcat(aux_string, "double");
  1228. strcat(aux_string, "\0");
  1229. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1230. strcpy($$->notacao, aux_string);
  1231.  
  1232. }else if((strcmp(aux->type, "int") ==0 || strcmp(aux2->type, "int")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1233. strcpy(aux_string, " - ");
  1234. strcat(aux_string, "int");
  1235. strcat(aux_string, "\0");
  1236. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1237. strcpy($$->notacao, aux_string);
  1238.  
  1239.  
  1240. }else{
  1241. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1242. strcpy($$->notacao, " - undef");
  1243. //printf("\n-----ERRO!-----\n");
  1244.  
  1245.  
  1246. }
  1247.  
  1248.  
  1249. }
  1250.  
  1251.  
  1252.  
  1253. }}
  1254. | ExprNew MINUS ExprNew {if(flag == 0){$$ = insertNode("Sub"); insert_child($$, $1); insert_child($$, $3);}
  1255. if(imprimir3==1){
  1256.  
  1257.  
  1258. int erro_aux = 0;
  1259. Table_node *aux;
  1260. Table_node *aux2;
  1261.  
  1262.  
  1263. char s[5] = " - ";
  1264. char *token;
  1265. if(strcmp($1->type, "Id") == 0){
  1266.  
  1267. aux = find_symbol($$->child->value);
  1268.  
  1269. }else{
  1270.  
  1271. aux = insert_value_node_Table("", "", "", "");
  1272. token = strtok($$->child->notacao, s);
  1273. char var2[100];
  1274. strcpy(var2, token);
  1275. aux->type = (char *)malloc(sizeof(var2)+1);;
  1276.  
  1277. strcpy(aux->type, var2);
  1278.  
  1279.  
  1280. }
  1281. if(strcmp($3->type, "Id") == 0){
  1282.  
  1283. aux2 = find_symbol($$->child->brother->value);
  1284. }
  1285. else{
  1286. aux2 = insert_value_node_Table("", "", "", "");
  1287. token = strtok($$->child->brother->notacao, s);
  1288. char var[100];
  1289. strcpy(var, token);
  1290. aux2->type = (char *)malloc(sizeof(var)+1);
  1291.  
  1292. strcpy(aux2->type, var);
  1293.  
  1294.  
  1295.  
  1296. }
  1297.  
  1298.  
  1299. if(strcmp(aux->type, "") == 0){
  1300. $1->notacao = (char *)malloc(sizeof(" - undef"));
  1301. strcpy($1->notacao, " - undef");
  1302. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1303. strcpy($$->notacao, " - undef");
  1304. //printf("\n-----ERRO!-----\n");
  1305. erro_aux = 1;
  1306.  
  1307. }
  1308. if(strcmp(aux2->type, "")==0){
  1309. $3->notacao = (char *)malloc(sizeof(" - undef"));
  1310. strcpy($3->notacao, " - undef");
  1311. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1312. strcpy($$->notacao, " - undef");
  1313. //printf("\n-----ERRO!-----\n");
  1314. erro_aux =1;
  1315. }
  1316.  
  1317. if(erro_aux ==0){
  1318. char aux_string[100];
  1319.  
  1320. if(strcmp(aux->type, "String") ==0 || strcmp(aux2->type, "String")==0){
  1321. //printf("\n-----ERRO!-----\n");
  1322.  
  1323. }else if((strcmp(aux->type, "double") ==0 || strcmp(aux2->type, "double")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1324.  
  1325.  
  1326.  
  1327. strcpy(aux_string, " - ");
  1328. strcat(aux_string, "double");
  1329. strcat(aux_string, "\0");
  1330. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1331. strcpy($$->notacao, aux_string);
  1332.  
  1333. }else if((strcmp(aux->type, "int") ==0 || strcmp(aux2->type, "int")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1334. strcpy(aux_string, " - ");
  1335. strcat(aux_string, "int");
  1336. strcat(aux_string, "\0");
  1337. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1338. strcpy($$->notacao, aux_string);
  1339.  
  1340.  
  1341. }else{
  1342. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1343. strcpy($$->notacao, " - undef");
  1344. //printf("\n-----ERRO!-----\n");
  1345.  
  1346.  
  1347. }
  1348.  
  1349.  
  1350.  
  1351.  
  1352.  
  1353.  
  1354.  
  1355. }
  1356.  
  1357.  
  1358.  
  1359. }
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368. }
  1369. | ExprNew STAR ExprNew {if(flag == 0){$$ = insertNode("Mul"); insert_child($$, $1); insert_child($$, $3);}
  1370.  
  1371. if(imprimir3==1){
  1372.  
  1373. int erro_aux = 0;
  1374. Table_node *aux;
  1375. Table_node *aux2;
  1376.  
  1377.  
  1378. char s[5] = " - ";
  1379. char *token;
  1380. if(strcmp($1->type, "Id") == 0){
  1381. aux = find_symbol($$->child->value);
  1382.  
  1383. }else{
  1384.  
  1385. aux = insert_value_node_Table("", "", "", "");
  1386. token = strtok($$->child->notacao, s);
  1387. char var2[100];
  1388. strcpy(var2, token);
  1389. aux->type = (char *)malloc(sizeof(var2)+1);;
  1390. strcpy(aux->type, var2);
  1391.  
  1392.  
  1393. }
  1394. if(strcmp($3->type, "Id") == 0){
  1395.  
  1396. aux2 = find_symbol($$->child->brother->value);
  1397. }
  1398. else{
  1399. aux2 = insert_value_node_Table("", "", "", "");
  1400. token = strtok($$->child->brother->notacao, s);
  1401. char var[100];
  1402. strcpy(var, token);
  1403. aux2->type = (char *)malloc(sizeof(var)+1);
  1404.  
  1405. strcpy(aux2->type, var);
  1406.  
  1407.  
  1408.  
  1409. }
  1410.  
  1411. if(strcmp(aux->type, "") == 0){
  1412. $1->notacao = (char *)malloc(sizeof(" - undef"));
  1413. strcpy($1->notacao, " - undef");
  1414. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1415. strcpy($$->notacao, " - undef");
  1416. //printf("\n-----ERRO!-----\n");
  1417. erro_aux = 1;
  1418.  
  1419. }
  1420. if(strcmp(aux2->type, "")==0){
  1421. $3->notacao = (char *)malloc(sizeof(" - undef"));
  1422. strcpy($3->notacao, " - undef");
  1423. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1424. strcpy($$->notacao, " - undef");
  1425. //printf("\n-----ERRO!-----\n");
  1426. erro_aux =1;
  1427. }
  1428.  
  1429. if(erro_aux ==0){
  1430. char aux_string[100];
  1431.  
  1432. if(strcmp(aux->type, "String") ==0 || strcmp(aux2->type, "String")==0){
  1433. //printf("\n-----ERRO!-----\n");
  1434.  
  1435. }else if((strcmp(aux->type, "double") ==0 || strcmp(aux2->type, "double")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1436.  
  1437.  
  1438.  
  1439. strcpy(aux_string, " - ");
  1440. strcat(aux_string, "double");
  1441. strcat(aux_string, "\0");
  1442. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1443. strcpy($$->notacao, aux_string);
  1444.  
  1445. }else if((strcmp(aux->type, "int") ==0 || strcmp(aux2->type, "int")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1446. strcpy(aux_string, " - ");
  1447. strcat(aux_string, "int");
  1448. strcat(aux_string, "\0");
  1449. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1450. strcpy($$->notacao, aux_string);
  1451.  
  1452.  
  1453. }else{
  1454. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1455. strcpy($$->notacao, " - undef");
  1456. //printf("\n-----ERRO!-----\n");
  1457.  
  1458.  
  1459. }
  1460.  
  1461.  
  1462.  
  1463.  
  1464.  
  1465.  
  1466.  
  1467. }
  1468.  
  1469.  
  1470.  
  1471. }
  1472.  
  1473.  
  1474.  
  1475. }
  1476. | ExprNew DIV ExprNew {if(flag == 0){$$ = insertNode("Div"); insert_child($$, $1); insert_child($$, $3);}
  1477.  
  1478.  
  1479.  
  1480. if(imprimir3==1){
  1481.  
  1482. int erro_aux = 0;
  1483. Table_node *aux;
  1484. Table_node *aux2;
  1485.  
  1486.  
  1487. char s[5] = " - ";
  1488. char *token;
  1489. if(strcmp($1->type, "Id") == 0){
  1490. aux = find_symbol($$->child->value);
  1491.  
  1492. }else{
  1493.  
  1494. aux = insert_value_node_Table("", "", "", "");
  1495. token = strtok($$->child->notacao, s);
  1496. char var2[100];
  1497. strcpy(var2, token);
  1498. aux->type = (char *)malloc(sizeof(var2)+1);;
  1499. strcpy(aux->type, var2);
  1500.  
  1501.  
  1502. }
  1503. if(strcmp($3->type, "Id") == 0){
  1504.  
  1505. aux2 = find_symbol($$->child->brother->value);
  1506. }
  1507. else{
  1508. aux2 = insert_value_node_Table("", "", "", "");
  1509. token = strtok($$->child->brother->notacao, s);
  1510. char var[100];
  1511. strcpy(var, token);
  1512. aux2->type = (char *)malloc(sizeof(var)+1);
  1513.  
  1514. strcpy(aux2->type, var);
  1515.  
  1516.  
  1517.  
  1518. }
  1519. if(strcmp(aux->type, "") == 0){
  1520. $1->notacao = (char *)malloc(sizeof(" - undef"));
  1521. strcpy($1->notacao, " - undef");
  1522. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1523. strcpy($$->notacao, " - undef");
  1524. //printf("\n-----ERRO!-----\n");
  1525. erro_aux = 1;
  1526.  
  1527. }
  1528. if(strcmp(aux2->type, "")==0){
  1529. $3->notacao = (char *)malloc(sizeof(" - undef"));
  1530. strcpy($3->notacao, " - undef");
  1531. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1532. strcpy($$->notacao, " - undef");
  1533. //printf("\n-----ERRO!-----\n");
  1534. erro_aux =1;
  1535. }
  1536.  
  1537. if(erro_aux ==0){
  1538. char aux_string[100];
  1539.  
  1540. if(strcmp(aux->type, "String") ==0 || strcmp(aux2->type, "String")==0){
  1541. //printf("\n-----ERRO!-----\n");
  1542.  
  1543. }else if((strcmp(aux->type, "double") ==0 || strcmp(aux2->type, "double")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1544.  
  1545.  
  1546.  
  1547. strcpy(aux_string, " - ");
  1548. strcat(aux_string, "double");
  1549. strcat(aux_string, "\0");
  1550. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1551. strcpy($$->notacao, aux_string);
  1552.  
  1553. }else if((strcmp(aux->type, "int") ==0 || strcmp(aux2->type, "int")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1554. strcpy(aux_string, " - ");
  1555. strcat(aux_string, "int");
  1556. strcat(aux_string, "\0");
  1557. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1558. strcpy($$->notacao, aux_string);
  1559.  
  1560.  
  1561. }else{
  1562. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1563. strcpy($$->notacao, " - undef");
  1564. //printf("\n-----ERRO!-----\n");
  1565.  
  1566.  
  1567. }
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575. }
  1576.  
  1577.  
  1578.  
  1579. }
  1580.  
  1581.  
  1582.  
  1583. }
  1584. | ExprNew MOD ExprNew {if(flag == 0){$$ = insertNode("Mod"); insert_child($$, $1); insert_child($$, $3);}
  1585. if(imprimir3==1){
  1586.  
  1587. int erro_aux = 0;
  1588. Table_node *aux;
  1589. Table_node *aux2;
  1590.  
  1591.  
  1592. char s[5] = " - ";
  1593. char *token;
  1594. if(strcmp($1->type, "Id") == 0){
  1595. aux = find_symbol($$->child->value);
  1596.  
  1597. }else{
  1598.  
  1599. aux = insert_value_node_Table("", "", "", "");
  1600. token = strtok($$->child->notacao, s);
  1601. char var2[100];
  1602. strcpy(var2, token);
  1603. aux->type = (char *)malloc(sizeof(var2)+1);;
  1604. strcpy(aux->type, var2);
  1605.  
  1606.  
  1607. }
  1608. if(strcmp($3->type, "Id") == 0){
  1609.  
  1610. aux2 = find_symbol($$->child->brother->value);
  1611. }
  1612. else{
  1613. aux2 = insert_value_node_Table("", "", "", "");
  1614. token = strtok($$->child->brother->notacao, s);
  1615. char var[100];
  1616. strcpy(var, token);
  1617. aux2->type = (char *)malloc(sizeof(var)+1);
  1618.  
  1619. strcpy(aux2->type, var);
  1620.  
  1621.  
  1622.  
  1623. }
  1624. if(strcmp(aux->type, "") == 0){
  1625. $1->notacao = (char *)malloc(sizeof(" - undef"));
  1626. strcpy($1->notacao, " - undef");
  1627. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1628. strcpy($$->notacao, " - undef");
  1629. //printf("\n-----ERRO!-----\n");
  1630. erro_aux = 1;
  1631.  
  1632. }
  1633. if(strcmp(aux2->type, "")==0){
  1634. $3->notacao = (char *)malloc(sizeof(" - undef"));
  1635. strcpy($3->notacao, " - undef");
  1636. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1637. strcpy($$->notacao, " - undef");
  1638. //printf("\n-----ERRO!-----\n");
  1639. erro_aux =1;
  1640. }
  1641.  
  1642. if(erro_aux ==0){
  1643. char aux_string[100];
  1644.  
  1645. if(strcmp(aux->type, "String") ==0 || strcmp(aux2->type, "String")==0){
  1646. //printf("\n-----ERRO!-----\n");
  1647.  
  1648. }else if((strcmp(aux->type, "double") ==0 || strcmp(aux2->type, "double")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1649.  
  1650.  
  1651.  
  1652. strcpy(aux_string, " - ");
  1653. strcat(aux_string, "double");
  1654. strcat(aux_string, "\0");
  1655. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1656. strcpy($$->notacao, aux_string);
  1657.  
  1658. }else if((strcmp(aux->type, "int") ==0 || strcmp(aux2->type, "int")==0) && (strcmp(aux->type, "boolean") !=0 || strcmp(aux2->type, "boolean")!=0)){
  1659. strcpy(aux_string, " - ");
  1660. strcat(aux_string, "int");
  1661. strcat(aux_string, "\0");
  1662. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1663. strcpy($$->notacao, aux_string);
  1664.  
  1665.  
  1666. }else{
  1667. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1668. strcpy($$->notacao, " - undef");
  1669. //printf("\n-----ERRO!-----\n");
  1670.  
  1671.  
  1672. }
  1673.  
  1674.  
  1675.  
  1676.  
  1677.  
  1678.  
  1679.  
  1680. }
  1681.  
  1682.  
  1683.  
  1684. }
  1685.  
  1686.  
  1687.  
  1688. }
  1689. | PLUS ExprNew %prec NOT {if(flag == 0){$$ = insertNode("Plus"); insert_child($$, $2);}
  1690. if(imprimir3==1){
  1691.  
  1692. //int erro_aux = 0;
  1693. Table_node *aux;
  1694.  
  1695.  
  1696.  
  1697. char s[5] = " - ";
  1698. char *token;
  1699. if(strcmp($2->type, "Id") == 0){
  1700. aux = find_symbol($$->child->value);
  1701.  
  1702. }else{
  1703.  
  1704. aux = insert_value_node_Table("", "", "", "");
  1705. token = strtok($$->child->notacao, s);
  1706. char var[100];
  1707. strcpy(var, token);
  1708. aux->type = (char *)malloc(sizeof(var)+1);;
  1709. strcpy(aux->type,var);
  1710.  
  1711.  
  1712. }
  1713.  
  1714.  
  1715.  
  1716.  
  1717. if(strcmp(aux->type, "") == 0){
  1718. $2->notacao = (char *)malloc(sizeof(" - undef"));
  1719. strcpy($2->notacao, " - undef");
  1720. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1721. strcpy($$->notacao, " - undef");
  1722. //printf("\n-----ERRO!-----\n");
  1723.  
  1724.  
  1725. }else{
  1726.  
  1727. if(strcmp(aux->type, "boolean")==0 || strcmp(aux->type, "String")==0){
  1728. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1729. strcpy($$->notacao, " - undef");
  1730. //printf("\n-----ERRO!-----\n");
  1731. }else{
  1732. char aux_string[100];
  1733. strcpy(aux_string, " - ");
  1734. strcat(aux_string, aux->type);
  1735. strcat(aux_string, "\0");
  1736.  
  1737.  
  1738. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1739. strcpy($$->notacao, aux_string);
  1740. }
  1741.  
  1742. }
  1743.  
  1744.  
  1745. }
  1746.  
  1747.  
  1748. }
  1749. | MINUS ExprNew %prec NOT {if(flag == 0){$$ = insertNode("Minus"); insert_child($$, $2);}
  1750. if(imprimir3==1){
  1751.  
  1752. //int erro_aux = 0;
  1753. Table_node *aux;
  1754.  
  1755.  
  1756.  
  1757. char s[5] = " - ";
  1758. char *token;
  1759. if(strcmp($2->type, "Id") == 0){
  1760. aux = find_symbol($$->child->value);
  1761.  
  1762. }else{
  1763.  
  1764. aux = insert_value_node_Table("", "", "", "");
  1765. token = strtok($$->child->notacao, s);
  1766. char var[100];
  1767. strcpy(var, token);
  1768. aux->type = (char *)malloc(sizeof(var)+1);;
  1769. strcpy(aux->type, var);
  1770.  
  1771.  
  1772. }
  1773.  
  1774.  
  1775.  
  1776.  
  1777. if(strcmp(aux->type, "") == 0){
  1778. $2->notacao = (char *)malloc(sizeof(" - undef"));
  1779. strcpy($2->notacao, " - undef");
  1780. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1781. strcpy($$->notacao, " - undef");
  1782. //printf("\n-----ERRO!-----\n");
  1783.  
  1784.  
  1785. }else{
  1786. if(strcmp(aux->type, "boolean")==0 || strcmp(aux->type, "String")==0){
  1787. //printf("\n-----ERRO!-----\n");
  1788. $$->notacao = (char *)malloc(sizeof(" - undef"));
  1789. strcpy($$->notacao, " - undef");
  1790. }else{
  1791.  
  1792. char aux_string[100];
  1793. strcpy(aux_string, " - ");
  1794. strcat(aux_string, aux->type);
  1795. strcat(aux_string, "\0");
  1796.  
  1797.  
  1798. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1799. strcpy($$->notacao, aux_string);
  1800. }
  1801.  
  1802. }
  1803.  
  1804.  
  1805. }
  1806.  
  1807.  
  1808.  
  1809.  
  1810. }
  1811. | NOT ExprNew {if(flag == 0){$$ = insertNode("Not"); insert_child($$, $2);}
  1812. if(imprimir3==1){
  1813. //int erro_aux = 0;
  1814. Table_node *aux;
  1815.  
  1816.  
  1817.  
  1818. char s[5] = " - ";
  1819. char *token;
  1820. if(strcmp($2->type, "Id") == 0){
  1821. aux = find_symbol($$->child->value);
  1822.  
  1823. }else{
  1824.  
  1825. aux = insert_value_node_Table("", "", "", "");
  1826. token = strtok($$->child->notacao, s);
  1827. char var[100];
  1828. strcpy(var, token);
  1829. aux->type = (char *)malloc(sizeof(var)+1);
  1830. strcpy(aux->type, var);
  1831.  
  1832.  
  1833. }
  1834.  
  1835.  
  1836. if(strcmp(aux->type, "") == 0){
  1837. $2->notacao = (char *)malloc(sizeof(" - undef"));
  1838. strcpy($2->notacao, " - undef");
  1839.  
  1840. //printf("\n-----ERRO!-----\n");
  1841.  
  1842.  
  1843. }else{
  1844. if(strcmp(aux->type, "boolean")!=0){
  1845. //printf("\n-----ERRO!-----\n");
  1846. }else{
  1847.  
  1848. char aux_string[100];
  1849. strcpy(aux_string, " - ");
  1850. strcat(aux_string, aux->type);
  1851. strcat(aux_string, "\0");
  1852.  
  1853.  
  1854. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1855. strcpy($$->notacao, aux_string);
  1856. }
  1857.  
  1858. }
  1859.  
  1860. $$->notacao = (char *)malloc(sizeof(" - boolean"));
  1861. strcpy($$->notacao, " - boolean");
  1862.  
  1863.  
  1864.  
  1865. }
  1866. }
  1867. | ID DOTLENGTH {if(flag == 0){$$ = insertNode("Length"); nodeAux = insert_value_node("Id", $1); insert_child($$, nodeAux);}
  1868. if(imprimir3==1){
  1869. Table_node *aux = find_symbol($1);
  1870.  
  1871. if(strcmp(aux->type, "") == 0){
  1872. $$->child->notacao = (char *)malloc(sizeof(" - undef"));
  1873. strcpy($$->child->notacao, " - undef");
  1874. //printf("\n-----ERRO!-----\n");
  1875. if(strcmp(check_later_vars->type, "") == 0){
  1876.  
  1877. check_later_vars = $$;
  1878.  
  1879.  
  1880.  
  1881. }else{
  1882. insert_next(check_later_vars, $$);
  1883.  
  1884. }
  1885.  
  1886.  
  1887. }else{
  1888.  
  1889.  
  1890. char aux_string[100];
  1891. strcpy(aux_string, " - ");
  1892. strcat(aux_string, aux->type);
  1893. strcat(aux_string, "\0");
  1894.  
  1895.  
  1896. $$->child->notacao=(char *)malloc(sizeof(aux_string)+1);
  1897.  
  1898. strcpy($$->child->notacao, aux_string);
  1899.  
  1900.  
  1901.  
  1902.  
  1903.  
  1904. }
  1905.  
  1906.  
  1907. $$->notacao=(char *)malloc(sizeof(" - int"));strcpy($$->notacao, " - int");;}
  1908. }
  1909. | ID {if(flag == 0){$$ = insert_value_node("Id", $1);}
  1910. if(imprimir3==1){
  1911. Table_node *aux = find_symbol($1);
  1912.  
  1913. if(strcmp(aux->type, "") == 0){
  1914.  
  1915. //printf("\n-----ERRO!-----\n");
  1916. if(strcmp(check_later_vars->type, "") == 0){
  1917.  
  1918. check_later_vars = $$;
  1919.  
  1920.  
  1921.  
  1922. }else{
  1923. insert_next(check_later_vars, $$);
  1924.  
  1925.  
  1926. }
  1927.  
  1928. }else{
  1929.  
  1930.  
  1931. char aux_string[100];
  1932. strcpy(aux_string, " - ");
  1933. strcat(aux_string, aux->type);
  1934. strcat(aux_string, "\0");
  1935.  
  1936.  
  1937. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1938. strcpy($$->notacao, aux_string);
  1939.  
  1940.  
  1941. }
  1942.  
  1943.  
  1944. }
  1945. }
  1946. | OCURV Expr CCURV {if(flag == 0){$$ = $2;}}
  1947. | BOOLLIT {if(flag == 0){$$ = insert_value_node("BoolLit", $1);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - boolean"));strcpy($$->notacao, " - boolean");}}
  1948. | DECLIT {if(flag == 0){$$ = insert_value_node("DecLit", $1);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - int"));strcpy($$->notacao, " - int");}}
  1949. | REALLIT {if(flag == 0){$$ = insert_value_node("RealLit", $1);}if(imprimir3==1){$$->notacao=(char *)malloc(sizeof(" - double"));strcpy($$->notacao, " - double");}}
  1950. | OCURV error CCURV {if(flag == 0){$$ = NULL;}}
  1951. ;
  1952.  
  1953. Assignment: ID ASSIGN Expr {if(flag == 0){$$ = insertNode("Assign"); nodeAux = insert_value_node("Id", $1); insert_child($$, nodeAux); insert_child($$, $3);}
  1954. if(imprimir3==1){
  1955.  
  1956. Table_node *aux = find_symbol($1);
  1957.  
  1958. if(strcmp(aux->type, "") == 0){
  1959.  
  1960. //printf("\n-----ERRO!-----\n");
  1961. if(strcmp(check_later_vars->type, "") == 0){
  1962.  
  1963. check_later_vars = $$;
  1964.  
  1965.  
  1966.  
  1967. }else{
  1968. insert_next(check_later_vars, $$);
  1969.  
  1970.  
  1971. }
  1972.  
  1973.  
  1974.  
  1975. }else{
  1976.  
  1977.  
  1978. char aux_string[100];
  1979.  
  1980. strcpy(aux_string, " - ");
  1981.  
  1982. strcat(aux_string, aux->type);
  1983. strcat(aux_string, "\0");
  1984.  
  1985.  
  1986. $$->child->notacao=(char *)malloc(sizeof(aux_string)+1);
  1987.  
  1988. strcpy($$->child->notacao, aux_string);
  1989.  
  1990. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  1991. strcpy($$->notacao,aux_string);
  1992.  
  1993. }
  1994.  
  1995. }
  1996.  
  1997.  
  1998. }
  1999. ;
  2000.  
  2001.  
  2002. MethodInvocation: ID OCURV CCURV {if(flag == 0){$$ = insertNode("Call"); nodeAux = insert_value_node("Id", $1); insert_child($$, nodeAux);}
  2003. if(imprimir3==1){
  2004. Table_node *aux = find_symbol_Method($1, "()");
  2005.  
  2006. if(strcmp(aux->type, "") == 0){
  2007.  
  2008. //printf("\n-----ERRO!-----\n");
  2009. if(strcmp(check_later->type, "") == 0){
  2010. check_later = $$;
  2011.  
  2012. }else{
  2013. insert_next(check_later, $$);
  2014.  
  2015. }
  2016.  
  2017.  
  2018. }else{
  2019.  
  2020.  
  2021. char aux_string[100];
  2022. strcpy(aux_string, " - ");
  2023. strcat(aux_string, aux->type);
  2024. strcat(aux_string, "\0");
  2025.  
  2026.  
  2027.  
  2028.  
  2029.  
  2030. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  2031. strcpy($$->notacao, aux_string);
  2032.  
  2033.  
  2034. char aux_string2[100];
  2035. strcpy(aux_string2, " - ");
  2036. strcat(aux_string2, aux->paramsType);
  2037. strcat(aux_string2, "\0");
  2038.  
  2039.  
  2040.  
  2041. $$->child->notacao=(char *)malloc(sizeof(aux_string2)+1);
  2042. strcpy($$->child->notacao, aux_string2);
  2043.  
  2044. }
  2045.  
  2046.  
  2047. }
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053. }
  2054. | ID OCURV Expr CCURV {if(flag == 0){$$ = insertNode("Call"); nodeAux = insert_value_node("Id", $1); insert_child($$, nodeAux); insert_child($$, $3);}
  2055. if(imprimir3==1){
  2056. Table_node *aux;
  2057. if(strcmp($3->type, "Id") == 0){
  2058. Table_node *aux_type = find_symbol($3->value);
  2059. if(strcmp(aux_type->type, "") != 0){
  2060. char type[20];
  2061. strcpy(type, "(");
  2062. strcat(type, aux_type->type);
  2063. strcat(type, ")\0");
  2064. aux = find_symbol_Method($1, type);
  2065. }else{
  2066.  
  2067. aux =insert_value_node_Table("", "", "", "");
  2068. }
  2069.  
  2070.  
  2071.  
  2072.  
  2073. }else{
  2074. if(strcmp($3->notacao, "") != 0){
  2075. char s[5] = " - ";
  2076. char *token;
  2077. token = strtok($3->notacao, s);
  2078. char type[20];
  2079. strcpy(type, "(");
  2080. strcat(type, token);
  2081. strcat(type, ")\0");
  2082. aux = find_symbol_Method($1, type);
  2083.  
  2084. }else{
  2085.  
  2086. aux =insert_value_node_Table("", "", "", "");
  2087.  
  2088. }
  2089. }
  2090.  
  2091.  
  2092.  
  2093.  
  2094.  
  2095. if(strcmp(aux->type, "") == 0){
  2096.  
  2097. //printf("\n-----ERRO!-----\n");
  2098. if(strcmp(check_later->type, "") == 0){
  2099. check_later = $$;
  2100.  
  2101. }else{
  2102. insert_next(check_later, $$);
  2103.  
  2104. }
  2105.  
  2106. }else{
  2107.  
  2108.  
  2109. char aux_string[100];
  2110. strcpy(aux_string, " - ");
  2111. strcat(aux_string, aux->type);
  2112. strcat(aux_string, "\0");
  2113.  
  2114.  
  2115.  
  2116.  
  2117.  
  2118. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  2119. strcpy($$->notacao, aux_string);
  2120.  
  2121.  
  2122. char aux_string2[100];
  2123. strcpy(aux_string2, " - ");
  2124. strcat(aux_string2, aux->paramsType);
  2125. strcat(aux_string2, "\0");
  2126.  
  2127.  
  2128.  
  2129. $$->child->notacao=(char *)malloc(sizeof(aux_string2)+1);
  2130. strcpy($$->child->notacao, aux_string2);
  2131.  
  2132. }
  2133.  
  2134.  
  2135. }
  2136.  
  2137. }
  2138. | ID OCURV Expr CommaExpr CCURV {if(flag == 0){$$ = insertNode("Call"); nodeAux = insert_value_node("Id", $1); insert_child($$, nodeAux);insert_child($$, $3); insert_child($$, $4);}
  2139. if(imprimir3==1){
  2140. Table_node *aux ;
  2141. int flag=0;
  2142. if(strcmp($3->type, "Id") == 0){
  2143. Table_node *aux_type = find_symbol($3->value);
  2144. if(strcmp(aux_type->type, "") != 0){
  2145. char type[20];
  2146. strcpy(type, "(");
  2147. strcat(type, aux_type->type);
  2148.  
  2149. AST_Tree_node *commaexpr = $4;
  2150. while(commaexpr != NULL){
  2151.  
  2152. if(strcmp(commaexpr->type, "Id") == 0){
  2153. Table_node *aux_type2 = find_symbol(commaexpr->value);
  2154. if(strcmp(aux_type2->type, "")!= 0){
  2155.  
  2156. strcat(type,",");
  2157.  
  2158.  
  2159. strcat(type, aux_type2->type);
  2160.  
  2161. }else{
  2162. type[strlen(type)-1] = 0;
  2163. flag =1;
  2164. break;
  2165. }
  2166. }else{
  2167. if(strcmp(commaexpr->notacao, "") != 0){
  2168. char s[5] = " - ";
  2169. char *token;
  2170. token = strtok(commaexpr->notacao, s);
  2171.  
  2172. strcat(type,",");
  2173.  
  2174.  
  2175. strcat(type, token);
  2176.  
  2177. }else{
  2178. type[strlen(type)-1] = 0;
  2179. flag = 1;
  2180. break;
  2181. }
  2182. }
  2183.  
  2184. commaexpr = commaexpr->brother;
  2185. }
  2186.  
  2187.  
  2188. if(flag == 0){
  2189.  
  2190. strcat(type, ")\0");
  2191. aux = find_symbol_Method($1, type);
  2192. }else{
  2193. strcat(type, ")\0");
  2194. aux = insert_value_node_Table("", "", "", "");
  2195. }
  2196.  
  2197.  
  2198. }else{
  2199.  
  2200. aux =insert_value_node_Table("", "", "", "");
  2201. }
  2202.  
  2203.  
  2204.  
  2205.  
  2206. }else{
  2207. if(strcmp($3->notacao, "") != 0){
  2208. char s[5] = " - ";
  2209. char *token;
  2210. token = strtok($3->notacao, s);
  2211. char type[20];
  2212. strcpy(type, "(");
  2213. strcat(type, token);
  2214. AST_Tree_node *commaexpr = $4;
  2215. while(commaexpr != NULL){
  2216.  
  2217. if(strcmp(commaexpr->type, "Id") == 0){
  2218. Table_node *aux_type2 = find_symbol(commaexpr->value);
  2219. if(strcmp(aux_type2->type, "")!= 0){
  2220.  
  2221. strcat(type,",");
  2222.  
  2223.  
  2224. strcat(type, aux_type2->type);
  2225.  
  2226. }else{
  2227. type[strlen(type)-1] = 0;
  2228. flag =1;
  2229. break;
  2230. }
  2231. }else{
  2232. if(strcmp(commaexpr->notacao, "") != 0){
  2233. char s[5] = " - ";
  2234. char *token;
  2235. token = strtok(commaexpr->notacao, s);
  2236.  
  2237. strcat(type,",");
  2238.  
  2239.  
  2240. strcat(type, token);
  2241.  
  2242. }else{
  2243. type[strlen(type)-1] = 0;
  2244. flag = 1;
  2245. break;
  2246. }
  2247. }
  2248. commaexpr = commaexpr->brother;
  2249. }
  2250.  
  2251. if(flag == 0){
  2252.  
  2253. strcat(type, ")\0");
  2254. aux = find_symbol_Method($1, type);
  2255. }else{
  2256. strcat(type, ")\0");
  2257. aux = insert_value_node_Table("", "", "", "");
  2258. }
  2259.  
  2260.  
  2261. }else{
  2262.  
  2263. aux =insert_value_node_Table("", "", "", "");
  2264.  
  2265. }
  2266. }
  2267.  
  2268. if(strcmp(aux->type, "") == 0){
  2269.  
  2270. //printf("\n-----ERRO!-----\n");
  2271.  
  2272.  
  2273. if(strcmp(check_later->type, "") == 0){
  2274. check_later = $$;
  2275.  
  2276. }else{
  2277. insert_next(check_later, $$);
  2278.  
  2279. }
  2280. }else{
  2281.  
  2282.  
  2283. char aux_string[100];
  2284. strcpy(aux_string, " - ");
  2285. strcat(aux_string, aux->type);
  2286. strcat(aux_string, "\0");
  2287.  
  2288.  
  2289.  
  2290.  
  2291.  
  2292. $$->notacao=(char *)malloc(sizeof(aux_string)+1);
  2293. strcpy($$->notacao, aux_string);
  2294.  
  2295.  
  2296. char aux_string2[100];
  2297. strcpy(aux_string2, " - ");
  2298. strcat(aux_string2, aux->paramsType);
  2299. strcat(aux_string2, "\0");
  2300.  
  2301.  
  2302.  
  2303. $$->child->notacao=(char *)malloc(sizeof(aux_string2)+1);
  2304. strcpy($$->child->notacao, aux_string2);
  2305.  
  2306. }
  2307.  
  2308.  
  2309. }
  2310.  
  2311.  
  2312.  
  2313. }
  2314. | ID OCURV error CCURV {flag = 1;$$=NULL;}
  2315. ;
  2316.  
  2317. CommaExpr: COMMA Expr {if(flag == 0){$$ = $2;}}
  2318. | CommaExpr COMMA Expr {if(flag == 0){$$ = $1; insert_brother($$, $3);}}
  2319. ;
  2320.  
  2321. ParseArgs: PARSEINT OCURV ID OSQUARE Expr CSQUARE CCURV {if(flag == 0){$$ = insertNode("ParseArgs"); nodeAux = insert_value_node("Id", $3); insert_child($$, nodeAux); insert_child($$, $5);}
  2322. if(imprimir3==1){
  2323.  
  2324. Table_node *aux = find_symbol($3);
  2325.  
  2326. if(strcmp(aux->type, "") == 0){
  2327. $$->child->notacao=(char *)malloc(sizeof(" - undef"));
  2328. strcpy($$->child->notacao, " - undef");
  2329. //printf("\n-----ERRO!-----\n");
  2330.  
  2331.  
  2332. }else{
  2333.  
  2334.  
  2335. char aux_string[100];
  2336.  
  2337. strcpy(aux_string, " - ");
  2338. strcat(aux_string, aux->type);
  2339. strcat(aux_string, "\0");
  2340.  
  2341.  
  2342. $$->child->notacao=(char *)malloc(sizeof(aux_string)+1);
  2343. strcpy($$->child->notacao, aux_string);
  2344.  
  2345.  
  2346. }
  2347.  
  2348.  
  2349. }
  2350.  
  2351.  
  2352.  
  2353. }
  2354. | PARSEINT OCURV error CCURV {flag =1;$$=NULL;}
  2355. ;
  2356.  
  2357.  
  2358.  
  2359. %%
  2360.  
  2361. void yyerror(const char* s){
  2362. if(flag ==0){
  2363. flag = 1;
  2364. }
  2365. printf("Line %d, col %d: %s: %s\n",n_linha,(int)(n_coluna - strlen(yytext)),s,yytext);
  2366. }
  2367.  
  2368. void insert_next(AST_Tree_node* first, AST_Tree_node *node){
  2369.  
  2370. AST_Tree_node* aux = first;
  2371.  
  2372. if(aux!=NULL && node!=NULL)
  2373. {
  2374. while(aux->next != NULL)
  2375. {
  2376. aux = aux->next;
  2377. }
  2378. aux->next = node;
  2379. }
  2380.  
  2381.  
  2382. }
  2383.  
  2384. void insert_brother(AST_Tree_node* brother, AST_Tree_node* node)
  2385. {
  2386.  
  2387.  
  2388. AST_Tree_node* aux = brother;
  2389.  
  2390. if(aux!=NULL && node!=NULL)
  2391. {
  2392. while(aux->brother != NULL)
  2393. {
  2394. aux = aux->brother;
  2395. }
  2396. aux->brother = node;
  2397. }
  2398. }
  2399.  
  2400. void insert_brother_Table(Table_node* brother, Table_node* node)
  2401. {
  2402.  
  2403.  
  2404. Table_node* aux = brother;
  2405.  
  2406. if(aux!=NULL && node!=NULL)
  2407. {
  2408. while(aux->brother != NULL)
  2409. {
  2410. aux = aux->brother;
  2411. }
  2412. aux->brother = node;
  2413. }
  2414. }
  2415.  
  2416.  
  2417. void insert_child(AST_Tree_node* father, AST_Tree_node* child)
  2418. {
  2419.  
  2420. AST_Tree_node* temp = father->child;
  2421.  
  2422. if(temp==NULL)
  2423. {
  2424. father->child = child;
  2425. }
  2426. else
  2427. {
  2428.  
  2429. insert_brother(father->child, child);
  2430. }
  2431.  
  2432. }
  2433.  
  2434. void insert_child_Table(Table_node* father, Table_node* child)
  2435. {
  2436.  
  2437. Table_node* temp = father->child;
  2438.  
  2439. if(temp==NULL)
  2440. {
  2441. father->child = child;
  2442. }
  2443. else
  2444. {
  2445.  
  2446. insert_brother_Table(father->child, child);
  2447. }
  2448.  
  2449. }
  2450.  
  2451.  
  2452. AST_Tree_node* insert_value_node(char* node, char* value){
  2453.  
  2454. AST_Tree_node* new_node = insertNode(node);
  2455. new_node->value = value;
  2456. return new_node;
  2457.  
  2458. }
  2459.  
  2460. Table_node* insert_value_node_Table(char* name, char* type, char* paramsType, char* flag){
  2461.  
  2462. Table_node* new_node = insertNode_Table(name);
  2463. new_node->type = type;
  2464. new_node->paramsType = paramsType;
  2465. new_node->flag=flag;
  2466. return new_node;
  2467.  
  2468. }
  2469.  
  2470.  
  2471.  
  2472. AST_Tree_node* insertNode(char* node){
  2473. AST_Tree_node* new_node;
  2474. new_node = (AST_Tree_node *)(malloc(sizeof(AST_Tree_node)));
  2475. if(new_node != NULL){
  2476. new_node->child = NULL;
  2477. new_node->brother = NULL;
  2478. new_node->value = NULL;
  2479. new_node->type = node;
  2480. new_node->notacao=NULL;
  2481. new_node->next = NULL;
  2482. }
  2483. return new_node;
  2484. }
  2485.  
  2486. Table_node* insertNode_Table(char* node){
  2487. Table_node* new_node;
  2488. new_node = (Table_node *)(malloc(sizeof(Table_node)));
  2489. if(new_node != NULL){
  2490.  
  2491. new_node->child = NULL;
  2492. new_node->brother = NULL;
  2493. new_node->name=node;
  2494. new_node->type=NULL;
  2495. new_node->paramsType=NULL;
  2496. new_node->flag=NULL;
  2497.  
  2498. }
  2499. return new_node;
  2500. }
  2501.  
  2502.  
  2503. /*AST_Tree_node *check_varDecl(char *name);
  2504. {
  2505. AST_Tree_node *top = varDecl
  2506. while(top!=NULL){
  2507. if(strcmp(top->value
  2508.  
  2509.  
  2510. }
  2511.  
  2512.  
  2513.  
  2514. }*/
  2515.  
  2516.  
  2517.  
  2518. void printTree(AST_Tree_node *node, int level){
  2519. printPoints(level);
  2520.  
  2521. if(strcmp(node->type, "Id") == 0 || strcmp(node->type, "BoolLit") == 0 || strcmp(node->type, "DecLit") == 0 || strcmp(node->type, "RealLit") == 0 || strcmp(node->type, "StrLit") == 0 ){
  2522. printTerminal(node);
  2523. }
  2524. else{
  2525. if(imprimir3==1 && node->notacao!=NULL){
  2526. if(strcmp(node->notacao,"")!=0){
  2527.  
  2528.  
  2529. printf("%s%s\n", node->type,node->notacao);
  2530. }
  2531. }else{
  2532.  
  2533. printf("%s\n", node->type);
  2534. }
  2535.  
  2536.  
  2537. }
  2538.  
  2539. AST_Tree_node *child = node->child;
  2540.  
  2541. if(child != NULL){
  2542. printTree(child, level+1);
  2543.  
  2544. while(child->brother != NULL){
  2545. child = child->brother;
  2546. printTree(child, level+1);
  2547. }
  2548.  
  2549. }
  2550.  
  2551. }
  2552.  
  2553.  
  2554. void printTerminal(AST_Tree_node *node){
  2555. if(imprimir3==1 && node->notacao!=NULL){
  2556.  
  2557. printf("%s(%s)%s\n", node->type, node->value, node->notacao);
  2558.  
  2559. }else{
  2560.  
  2561. printf("%s(%s)\n", node->type, node->value);
  2562. }
  2563. }
  2564. void printPoints(int n){
  2565. while(n > 0){
  2566. printf("..");
  2567. n--;
  2568. }
  2569. }
  2570.  
  2571.  
  2572. void printTable(Table_node *node){
  2573.  
  2574. int count =0;
  2575. int flag2 = 0;
  2576.  
  2577. printf("===== %s %s Symbol Table =====\n", node->type, node->name);
  2578. if(node->child !=NULL){
  2579. Table_node *aux = node->child;
  2580. while(flag2 !=1){
  2581.  
  2582.  
  2583.  
  2584. printf("%s\t%s\t%s\n", aux->name, aux->paramsType, aux->type);
  2585.  
  2586.  
  2587. if(aux->child != NULL){
  2588. count++;
  2589. }
  2590. if(aux->brother != NULL)
  2591. {
  2592. aux = aux->brother;
  2593. }else{
  2594. flag2 =1 ;
  2595.  
  2596. }
  2597. }
  2598. }
  2599. printf("\n");
  2600. if( count != 0){
  2601. Table_node *aux2 = node->child;
  2602.  
  2603. while(count != 0){
  2604.  
  2605. if(aux2->child != NULL){
  2606.  
  2607. count--;
  2608. Table_node *aux3 = aux2->child;
  2609. printf("===== Method %s%s Symbol Table =====\n", aux2->name, aux2->paramsType);
  2610. while(aux3 != NULL){
  2611.  
  2612.  
  2613. if(strcmp(aux3->flag, "") == 0){
  2614.  
  2615. printf("%s\t%s\t%s\n", aux3->name, aux3->paramsType, aux3->type);
  2616.  
  2617. }else{
  2618.  
  2619. printf("%s\t%s\t%s\t%s\n", aux3->name, aux3->paramsType, aux3->type, aux3->flag);
  2620. }
  2621.  
  2622. aux3 = aux3->brother;
  2623. if(aux3==NULL){
  2624. printf("\n");
  2625.  
  2626. }
  2627. }
  2628.  
  2629.  
  2630.  
  2631. }
  2632.  
  2633. aux2 = aux2->brother;
  2634.  
  2635. }
  2636. }
  2637.  
  2638.  
  2639. }
  2640.  
  2641.  
  2642.  
  2643. Table_node *check_later_vars_func(char *name){
  2644.  
  2645.  
  2646. if(head_table->child != NULL){
  2647.  
  2648. Table_node* child_class = head_table->child;
  2649. while(child_class !=NULL){
  2650. //printf("\nfuncao: %s ; paramsType:%s; type:%s\n", child_class->name, child_class->paramsType, child_class->type);
  2651.  
  2652. if(strcmp(child_class->paramsType, "") == 0){
  2653. //printf("\n CLASS NAME:%s ; TARGET name:%s \n", child_class->name, name);
  2654. if(strcmp(child_class->name, name) == 0){
  2655. //printf("\n RETURNS CLASS NAME:%s ; TARGET name:%s \n", child_class->name, name);
  2656. return child_class;
  2657.  
  2658. }
  2659.  
  2660. }
  2661.  
  2662. child_class = child_class->brother;
  2663.  
  2664. }
  2665.  
  2666. }
  2667.  
  2668. Table_node *cannot_find_var = insert_value_node_Table("", "", "", "");
  2669. return cannot_find_var;
  2670.  
  2671.  
  2672.  
  2673.  
  2674. }
  2675.  
  2676.  
  2677.  
  2678. Table_node *check_later_func(char *name, char *type){
  2679.  
  2680.  
  2681. if(head_table->child != NULL){
  2682.  
  2683. Table_node* child_class = head_table->child;
  2684. while(child_class !=NULL){
  2685. //printf("\nfuncao: %s ; paramsType:%s; type:%s\n", child_class->name, child_class->paramsType, child_class->type);
  2686.  
  2687. if(strcmp(child_class->paramsType, type) == 0){
  2688.  
  2689. if(strcmp(child_class->name, name) == 0){
  2690. return child_class;
  2691.  
  2692. }
  2693.  
  2694. }
  2695.  
  2696. child_class = child_class->brother;
  2697.  
  2698. }
  2699.  
  2700. }
  2701.  
  2702. Table_node *cannot_find_method = insert_value_node_Table("", "", "", "");
  2703. return cannot_find_method;
  2704.  
  2705.  
  2706.  
  2707.  
  2708. }
  2709. int parse_args_func(char *paramsType, char* params){
  2710.  
  2711.  
  2712. const char s[] = "),(";
  2713. char *token_paramsType;
  2714. char *token_params;
  2715.  
  2716. token_paramsType = strtok(paramsType,s);
  2717. token_params = strtok(params, s);
  2718. while( token_paramsType != NULL && token_params != NULL)
  2719. {
  2720. token_paramsType = strtok(NULL, s);
  2721. token_params = strtok(NULL,s);
  2722.  
  2723.  
  2724.  
  2725. }
  2726. return 0;
  2727.  
  2728. }
  2729. Table_node* find_symbol_Method(char *name, char *params){
  2730. printf("params: %s\n",params);
  2731. char str[4]="(,)";
  2732. char *token;
  2733. int errado=0;
  2734. int num_params_func_table=0, num_params=0;
  2735. char aux_child[200];
  2736. char aux_child2[200];
  2737.  
  2738. Table_node *cannot_find_method = insert_value_node_Table("", "", "", "");
  2739.  
  2740.  
  2741. argumentos_node* new_node_params;
  2742. argumentos_node* aux_node;
  2743. argumentos_node* new_node_table;
  2744. printf("\n-------NAME: %s ; params: %s ------\n", name, params);
  2745. if(head_table->child != NULL){
  2746.  
  2747. Table_node* child_class = head_table->child;
  2748. while(child_class !=NULL){
  2749. //printf("\nfuncao: %s ; paramsType:%s; type:%s\n", child_class->name, child_class->paramsType, child_class->type);
  2750. printf("child:%s params:%s\n",child_class->paramsType,params);
  2751. if(strcmp(child_class->name, name) == 0){
  2752.  
  2753. if(strcmp(child_class->paramsType, params) == 0){
  2754. return child_class;
  2755.  
  2756.  
  2757.  
  2758. }
  2759.  
  2760. }
  2761. child_class = child_class->brother;
  2762.  
  2763. }
  2764.  
  2765. child_class = head_table->child;
  2766. while(child_class !=NULL){
  2767. //printf("\nfuncao: %s ; paramsType:%s; type:%s\n", child_class->name, child_class->paramsType, child_class->type);
  2768. //printf("22222-child:%s params:%s\n",child_class->paramsType,params);
  2769. if(strcmp(child_class->name, name) == 0){
  2770.  
  2771. if(strcmp(child_class->paramsType, params) == 0){
  2772. return child_class;
  2773.  
  2774. }else{
  2775.  
  2776.  
  2777. head_params = (argumentos_node *)(malloc(sizeof(argumentos_node)));
  2778. head_params->paramsType=NULL;
  2779. new_node_params=head_params;
  2780. strcpy(aux_child2, params);
  2781. token=strtok(aux_child2,str);
  2782. while(token!=NULL){
  2783. new_node_params->paramsType=token;
  2784.  
  2785. token=strtok(NULL,str);
  2786. //printf("%s %d\n",new_node_params->paramsType,num_params);
  2787. aux_node=(argumentos_node *)(malloc(sizeof(argumentos_node)));
  2788. aux_node->paramsType=NULL;
  2789. new_node_params->next=aux_node;
  2790. new_node_params=aux_node;
  2791. num_params++;
  2792.  
  2793. }
  2794.  
  2795.  
  2796. new_node_table = (argumentos_node *)(malloc(sizeof(argumentos_node)));
  2797. head_func_table=new_node_table;
  2798. strcpy(aux_child,child_class->paramsType);
  2799. token=strtok(aux_child,str);
  2800. while(token!=NULL){
  2801. new_node_table->paramsType=token;
  2802.  
  2803. token=strtok(NULL,str);
  2804. //printf("%s %d\n",new_node_table->paramsType, num_params_func_table);
  2805. aux_node=(argumentos_node *)(malloc(sizeof(argumentos_node)));
  2806. aux_node->paramsType=NULL;
  2807. new_node_table->next=aux_node;
  2808. new_node_table=aux_node;
  2809.  
  2810. num_params_func_table++;
  2811.  
  2812. }
  2813.  
  2814. if(num_params==num_params_func_table){
  2815.  
  2816. while(head_params->paramsType!=NULL){
  2817.  
  2818. if(strcmp(head_params->paramsType,head_func_table->paramsType)!=0){
  2819. if((strcmp(head_params->paramsType,"double")==0 && strcmp(head_func_table->paramsType,"int")==0)||(strcmp(head_params->paramsType,"int")==0 && strcmp(head_func_table->paramsType,"double")==0)){
  2820.  
  2821. }else{
  2822. errado=1;
  2823. }
  2824. }
  2825.  
  2826.  
  2827.  
  2828. head_params=head_params->next;
  2829. head_func_table=head_func_table->next;
  2830. }
  2831. if(errado==0){
  2832. //printf("-----print final------ %s\n",child_class->paramsType);
  2833. return child_class;
  2834. }
  2835.  
  2836. }
  2837.  
  2838.  
  2839. }
  2840.  
  2841. }
  2842. child_class = child_class->brother;
  2843.  
  2844. }
  2845.  
  2846.  
  2847. }
  2848.  
  2849.  
  2850. return cannot_find_method;
  2851.  
  2852.  
  2853. }
  2854.  
  2855. Table_node* find_symbol(char* name){
  2856.  
  2857. if(head_table->child != NULL){
  2858. Table_node* child_class = head_table->child;
  2859. while(child_class !=NULL){
  2860. if(strcmp(child_class->name, name) == 0){
  2861.  
  2862. return child_class;
  2863.  
  2864.  
  2865. }
  2866.  
  2867.  
  2868.  
  2869. child_class = child_class->brother;
  2870. }
  2871. }
  2872.  
  2873. if(current_Method->child !=NULL){
  2874.  
  2875. Table_node* child_Method = current_Method->child;
  2876. while(child_Method !=NULL){
  2877.  
  2878. if(strcmp(child_Method->name, name)==0){
  2879.  
  2880. return child_Method;
  2881.  
  2882.  
  2883. }
  2884.  
  2885.  
  2886.  
  2887. child_Method = child_Method->brother;
  2888.  
  2889. }
  2890.  
  2891.  
  2892. }
  2893.  
  2894.  
  2895. Table_node *cannot_find_symbol = insert_value_node_Table("", "", "", "");
  2896. return cannot_find_symbol;
  2897.  
  2898.  
  2899.  
  2900. }
  2901.  
  2902.  
  2903.  
  2904.  
  2905.  
  2906.  
  2907.  
  2908. int main(int argc, char *argv[])
  2909. {
  2910. int imprimir2 =0;
  2911.  
  2912. head_table= insert_value_node_Table("", "Class", "", "");
  2913. varDecl= insert_value_node_Table("", "", "", "");
  2914. current_Method= insert_value_node_Table("", "", "", "");
  2915. check_later= insert_value_node("", "");
  2916. check_later->next = NULL;
  2917. check_later_vars= insert_value_node("", "");
  2918. check_later_vars->next = NULL;
  2919.  
  2920. if(argc>1){
  2921. if(strcmp(argv[1],"-l")==0){
  2922. imprimir=1;
  2923. yylex();
  2924. }
  2925. else if(strcmp(argv[1],"-1")==0){
  2926. yylex();
  2927. }
  2928. else if(strcmp(argv[1],"-2")==0){
  2929. parse=1;
  2930. yyparse();
  2931.  
  2932.  
  2933. }else if(flag ==0 && strcmp(argv[1],"-t")==0){
  2934. parse = 1;
  2935. imprimir2 = 1;
  2936. yyparse();
  2937.  
  2938. }else if(strcmp(argv[1],"-s")==0){
  2939. parse=1;
  2940. imprimir3=1;
  2941.  
  2942. yyparse();
  2943.  
  2944. }
  2945. }else{
  2946. parse = 1;
  2947. yyparse();
  2948.  
  2949.  
  2950. }
  2951. if(imprimir2 == 1 && flag == 0){
  2952.  
  2953. printTree(head, 0);
  2954.  
  2955.  
  2956. }
  2957. if(imprimir3==1 && flag==0){
  2958.  
  2959. printTable(head_table);
  2960. printTree(head,0);
  2961. }
  2962.  
  2963. return 0;
  2964. }
Add Comment
Please, Sign In to add comment