WhaleSpunk

Untitled

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