<commit_before>/*
  Grupo MLC - <NAME>
*/
%{
#include <stdio.h>
#include "iks_ast.h"
#include "comp_tree.h"
%}

%union {
   void* symbol;
}

/* Declaração dos tokens da linguagem */
%token TK_PR_INT	"INT"
%token TK_PR_FLOAT	"FLOAT"
%token TK_PR_BOOL	"BOOL"
%token TK_PR_CHAR	"CHAR"
%token TK_PR_STRING	"STRING"
%token TK_PR_IF		"IF"
%token TK_PR_THEN	"THEN"
%token TK_PR_ELSE	"ELSE"
%token TK_PR_WHILE	"WHILE"
%token TK_PR_DO		"DO"
%token TK_PR_INPUT	"INPUT"
%token TK_PR_OUTPUT	"OUTPUT"
%token TK_PR_RETURN	"RETURN"
%token TK_OC_LE		"<="
%token TK_OC_GE		">="
%token TK_OC_EQ		"=="
%token TK_OC_NE		"!="
%token TK_OC_AND	"&&"
%token TK_OC_OR		"||"
%token TK_LIT_INT	"litInt"
%token TK_LIT_FLOAT	"litFloat"
%token TK_LIT_FALSE	"false"
%token TK_LIT_TRUE	"true"
%token TK_LIT_CHAR	"litChar"
%token TK_LIT_STRING	"litString"
%token TK_IDENTIFICADOR	"ID"
%token TOKEN_ERRO	"ERRO"
%left '+'
%left '-'
%left '!'
%left '*'
%left '/'
%left '>'
%left '<'
%left "<=" ">=" "==" "!=" "&&" "||"
%right "INT" "FLOAT" "BOOL" "CHAR" "STRING" "THEN" "ELSE"

%error-verbose

%type <symbol> AST Program SC Global ID Type Vector Function Header List ParaList Parameter Body Block Command
%type <symbol> Local Attribution Expression Literal Boolean Return FlowControl If While Input Output Call FunctionID ExpList
%type <symbol> TK_IDENTIFICADOR TK_LIT_STRING TK_LIT_CHAR TK_LIT_TRUE TK_LIT_FALSE TK_LIT_FLOAT TK_LIT_INT
%type <symbol> "INT" "FLOAT" "BOOL" "CHAR" "STRING" ';' '(' ')'


%%
/* Regras (e ações) da gramática */

AST:	Program {createAST($1);}

Program: 	{$$ = NULL;}
			|Global SC Program 
			|Function Program {$$ = createNodeAST(IKS_AST_FUNCAO, $2, yylval.symbol, $1); }	
//			|error SC {yyerrok; yyclearin;}//yyclearin; yyerrok;}

SC:	 	';'
//		|error {}//yyclearin; yyerrok;}

/*{yyerrok;
		 printf("Missing semicolon at line %d",getLineNumber());
		 yyclearin;}
		|*/

Global:	 	Type ID

ID:		"ID" {$$ = createNodeAST(IKS_AST_IDENTIFICADOR, NULL, yylval.symbol);}
		|"ID" Vector {nodeAST* id = createNodeAST(IKS_AST_IDENTIFICADOR, NULL, yylval.symbol); modify($2, 1, id); $$ = $2;}

Type:	"INT"
		|"FLOAT"
		|"BOOL"
		|"CHAR"
		|"STRING"

Vector: '[' Expression ']'	{$$ = createNodeAST(IKS_AST_VETOR_INDEXADO, NULL, NULL, $2);/*lembrando que esse filhote é o segundo e não o primeiro*/ }

Function:	Header Body {$$ = $2;}
		
Header:		Type "ID" List

List:	'(' ParaList ')'
		|'(' ')'

ParaList:	Parameter ',' ParaList
		| Parameter

Parameter: 	Local

Body:	 	'{' Block '}' {$$ = $2;}

Block:	{$$ = NULL;}	/*empty*/
		|Command	{$$ = $1; /*pq não tem next mesmo*/ }
		|Command SC Block	{modify($1, 4, $3); /*set $3 como next do comando*/ $$ = $1; }

Command: Local  
		| Attribution 
		| FlowControl
		| Input 
		| Output 
		| Return  
		| Call  
		| Body
		| SC

Local:		Type "ID"<commit_msg>Separated IDs from GlobalIds, used in Global declarations<commit_after>/*
  Grupo MLC - <NAME>
*/
%{
#include <stdio.h>
#include "iks_ast.h"
#include "comp_tree.h"
%}

%union {
   void* symbol;
}

/* Declaração dos tokens da linguagem */
%token TK_PR_INT	"INT"
%token TK_PR_FLOAT	"FLOAT"
%token TK_PR_BOOL	"BOOL"
%token TK_PR_CHAR	"CHAR"
%token TK_PR_STRING	"STRING"
%token TK_PR_IF		"IF"
%token TK_PR_THEN	"THEN"
%token TK_PR_ELSE	"ELSE"
%token TK_PR_WHILE	"WHILE"
%token TK_PR_DO		"DO"
%token TK_PR_INPUT	"INPUT"
%token TK_PR_OUTPUT	"OUTPUT"
%token TK_PR_RETURN	"RETURN"
%token TK_OC_LE		"<="
%token TK_OC_GE		">="
%token TK_OC_EQ		"=="
%token TK_OC_NE		"!="
%token TK_OC_AND	"&&"
%token TK_OC_OR		"||"
%token TK_LIT_INT	"litInt"
%token TK_LIT_FLOAT	"litFloat"
%token TK_LIT_FALSE	"false"
%token TK_LIT_TRUE	"true"
%token TK_LIT_CHAR	"litChar"
%token TK_LIT_STRING	"litString"
%token TK_IDENTIFICADOR	"ID"
%token TOKEN_ERRO	"ERRO"
%left '+'
%left '-'
%left '!'
%left '*'
%left '/'
%left '>'
%left '<'
%left "<=" ">=" "==" "!=" "&&" "||"
%right "INT" "FLOAT" "BOOL" "CHAR" "STRING" "THEN" "ELSE"

%error-verbose

%type <symbol> AST Program SC Global ID Type Vector Function Header List ParaList Parameter Body Block Command
%type <symbol> Local Attribution Expression Literal Boolean Return FlowControl If While Input Output Call FunctionID ExpList
%type <symbol> TK_IDENTIFICADOR TK_LIT_STRING TK_LIT_CHAR TK_LIT_TRUE TK_LIT_FALSE TK_LIT_FLOAT TK_LIT_INT
%type <symbol> "INT" "FLOAT" "BOOL" "CHAR" "STRING" ';' '(' ')'


%%
/* Regras (e ações) da gramática */

AST:	Program {createAST($1);}

Program: 	{$$ = NULL;}
			|Global SC Program 
			|Function Program {$$ = createNodeAST(IKS_AST_FUNCAO, $2, yylval.symbol, $1); }	
//			|error SC {yyerrok; yyclearin;}//yyclearin; yyerrok;}

SC:	 	';'
//		|error {}//yyclearin; yyerrok;}

/*{yyerrok;
		 printf("Missing semicolon at line %d",getLineNumber());
		 yyclearin;}
		|*/

Global:	 	Type GlobalID

GlobalID:	"ID" 
			| "ID" '[' Expression ']'

ID:		"ID" {$$ = createNodeAST(IKS_AST_IDENTIFICADOR, NULL, yylval.symbol);}
		|"ID" Vector {nodeAST* id = createNodeAST(IKS_AST_IDENTIFICADOR, NULL, yylval.symbol); modify($2, 1, id); $$ = $2;}

Type:	"INT"
		|"FLOAT"
		|"BOOL"
		|"CHAR"
		|"STRING"

Vector: '[' Expression ']'	{nodeAST* this = createNodeAST(IKS_AST_VETOR_INDEXADO, NULL, NULL); modify(this, 2, $2); $$ = this; }

Function:	Header Body {$$ = $2;}
		
Header:		Type "ID" List

List:	'(' ParaList ')'
		|'(' ')'

ParaList:	Parameter ',' ParaList
		| Parameter

Parameter: 	Local

Body:	 	'{' Block '}' {$$ = $2;}

Block:	{$$ = NULL;}	/*empty*/
		|Command	{$$ = $1; /*pq não tem next mesmo*/ }
		|Command SC Block	{modify($1, 4, $3); /*set $3 como next do comando*/ $$ = $1; }

Command: Local  
		| Attribution 
		| FlowControl
		| Input 
		| Output 
		| Return  
		| Call  
		| Body
		| SC

Local:		Type "ID"
{'fraction_non_alphanumeric': 0.17532697066101097, 'fraction_numerical': 0.005478967833156593, 'mean_word_length': 4.441346153846154, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1126025', 'n_tokens_mistral': 2572, 'n_tokens_neox': 2413, 'n_words': 585}