<commit_before>%{
import com.davidmogar.njc.lexicon.Lexicon;
import com.davidmogar.njc.ast.*;
import java.util.*;

%}
      
/* Primitive types */
%token CHARACTER DOUBLE INTEGER

/* Primitive types literals */
%token CHARACTER_LITERAL DOUBLE_LITERAL INTEGER_LITERAL

/* Complex types */
%token STRING VOID

/* Complex types literals */
%token STRING_LITERAL

/* Control flow */
%token ELSE IF WHILE

/* Reserved words */
%token MAIN READ RETURN WRITE

/* Other tokens */
%token AND DECREMENT EQUALS GREATER_EQUALS IDENTIFIER INCREMENT LOWER_EQUALS NOT_EQUALS OR

%nonassoc LOWER_THAN_ELSE
%nonassoc ELSE
%left AND OR '!'
%left EQUALS GREATER_EQUALS LOWER_EQUALS NOT_EQUALS
%left '+' '-'
%left '*' '/'
%nonassoc '(' ')'

%%

program:    functions
            | declarations functions ;

statement:  function_call ';'
            | declaration ';'
            | if
            | while
            | read ';'
            | return ';'
            | write ';'
            | assignment ';' ;

statements: statement | statements statement ;

/* Identifiers, declarations and assignments */

literal:    CHARACTER_LITERAL
            | DOUBLE_LITERAL
            | INTEGER_LITERAL
            | STRING_LITERAL ;

type:       CHARACTER
            | DOUBLE
            | INTEGER
            | STRING ;

array_position:     '[' expression ']'
                    | '[' expression ']' array_position ;

array_access:       IDENTIFIER array_position ;

array_declaration:  type array_position identifiers;

assignment:         IDENTIFIER '=' expression | array_access '=' expression ;

declaration:        type identifiers
                    | array_declaration ;

declarations:       declarations declaration ';'
                    | declaration ';' ;

identifiers:        IDENTIFIER
                    | identifiers ',' IDENTIFIER ;

/* Blocks, functions and control flow */

block:                  '{' '}'
                        | '{' statements '}' ;
<commit_msg>Change assignment rule to accept expressions in left side<commit_after>%{
import com.davidmogar.njc.lexicon.Lexicon;
import com.davidmogar.njc.ast.*;
import java.util.*;

%}
      
/* Primitive types */
%token CHARACTER DOUBLE INTEGER

/* Primitive types literals */
%token CHARACTER_LITERAL DOUBLE_LITERAL INTEGER_LITERAL

/* Complex types */
%token STRING VOID

/* Complex types literals */
%token STRING_LITERAL

/* Control flow */
%token ELSE IF WHILE

/* Reserved words */
%token MAIN READ RETURN WRITE

/* Other tokens */
%token AND DECREMENT EQUALS GREATER_EQUALS IDENTIFIER INCREMENT LOWER_EQUALS NOT_EQUALS OR

%nonassoc LOWER_THAN_ELSE
%nonassoc ELSE
%left AND OR '!'
%left EQUALS GREATER_EQUALS LOWER_EQUALS NOT_EQUALS
%left '+' '-'
%left '*' '/'
%nonassoc '(' ')'

%%

program:    functions
            | declarations functions ;

statement:  function_call ';'
            | declaration ';'
            | if
            | while
            | read ';'
            | return ';'
            | write ';'
            | assignment ';' ;

statements: statement | statements statement ;

/* Identifiers, declarations and assignments */

literal:    CHARACTER_LITERAL
            | DOUBLE_LITERAL
            | INTEGER_LITERAL
            | STRING_LITERAL ;

type:       CHARACTER
            | DOUBLE
            | INTEGER
            | STRING ;

array_position:     '[' expression ']'
                    | '[' expression ']' array_position ;

array_access:       IDENTIFIER array_position ;

array_declaration:  type array_position identifiers;

assignment:         expression '=' expression ;

declaration:        type identifiers
                    | array_declaration ;

declarations:       declarations declaration ';'
                    | declaration ';' ;

identifiers:        IDENTIFIER
                    | identifiers ',' IDENTIFIER ;

/* Blocks, functions and control flow */

block:                  '{' '}'
                        | '{' statements '}' ;

{'fraction_non_alphanumeric': 0.10111788617886179, 'fraction_numerical': 0.0, 'mean_word_length': 2.1775625504439065, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '6261760', 'n_tokens_mistral': 1237, 'n_tokens_neox': 1165, 'n_words': 278}