<commit_before>%{

package expreduce

import (
	"math/big"
)

%}

// fields inside this union end up as the fields in a structure known
// as ${PREFIX}SymType, of which a reference is passed to the lexer.
%union{
	val Ex
	valSeq []Ex
	compExpr []Ex
}

// any non-terminal which returns a value needs a type, which is
// really a field name in the above union struct
%type <val> expr
%type <valSeq> exprseq
%type <compExpr> compexpr

// same for terminals
%token <val> FLOAT INTEGER STRING LPARSYM RPARSYM COMMASYM SEMISYM LBRACKETSYM RBRACKETSYM LCURLYSYM RCURLYSYM REPLACEREPSYM REPLACEALLSYM CONDITIONSYM PLUSSYM MINUSSYM MULTSYM DIVSYM EXPSYM RULESYM RULEDELAYEDSYM POSTFIXSYM FUNCAPPSYM APPLYSYM MAPSYM PATTESTSYM ALTSYM SAMESYM EQUALSYM UNEQUALSYM SETSYM SETDELAYEDSYM SLOTSYM NAME PATTERN MESSAGENAMESYM STRINGJOINSYM

/*Adding some of the tokens above to this precedence list can decrease the*/
/*number of conflicts*/
/*What about FLOAT, INTEGER, STRING, NAME, PATTERN?*/
%left POSTFIXSYM
%left SETSYM SETDELAYEDSYM
%left REPLACEREPSYM REPLACEALLSYM
%left RULESYM RULEDELAYEDSYM
%left CONDITIONSYM ALTSYM
%left SAMESYM
%left UNEQUALSYM
%left EQUALSYM
%left PLUSSYM /* Plus and minus seem to be reversed according to the table. Investigate this. */
%left MINUSSYM
%left MULTSYM
%left DIVSYM
%left EXPSYM
%left STRINGJOINSYM
%left APPLYSYM
%left MAPSYN
%left PATTESTSYM
%left MESSAGENAMESYM /* This might as well be part of the symbol. Use a very
high precedence. */

%right FUNCAPPSYM

%%

list	: /* empty */
	| list stat '\n'
	;

stat	:    expr
		{
			Calcrcvr.lval.val = $1
		}
	;

expr	:    LPARSYM expr RPARSYM
		{ $$  =  $2 }
	|    LPARSYM compexpr RPARSYM
		{
			ex := &Expression{}
			ex.Parts = []Ex{&Symbol{"CompoundExpression"}}
			ex.Parts = append(ex.Parts, $2...)
			$$ = ex<commit_msg>Match up operators.<commit_after>%{

package expreduce

import (
	"math/big"
)

%}

// fields inside this union end up as the fields in a structure known
// as ${PREFIX}SymType, of which a reference is passed to the lexer.
%union{
	val Ex
	valSeq []Ex
	compExpr []Ex
}

// any non-terminal which returns a value needs a type, which is
// really a field name in the above union struct
%type <val> expr
%type <valSeq> exprseq
%type <compExpr> compexpr

// same for terminals
%token <val> FLOAT INTEGER STRING LPARSYM RPARSYM COMMASYM SEMISYM LBRACKETSYM RBRACKETSYM LCURLYSYM RCURLYSYM REPLACEREPSYM REPLACEALLSYM CONDITIONSYM PLUSSYM MINUSSYM MULTSYM DIVSYM EXPSYM RULESYM RULEDELAYEDSYM POSTFIXSYM FUNCAPPSYM APPLYSYM MAPSYM PATTESTSYM ALTSYM SAMESYM EQUALSYM UNEQUALSYM SETSYM SETDELAYEDSYM SLOTSYM NAME PATTERN MESSAGENAMESYM STRINGJOINSYM

/*Adding some of the tokens above to this precedence list can decrease the*/
/*number of conflicts*/
%left SEMISYM
%left SETDELAYEDSYM
%left SETSYM
%left POSTFIXSYM
%left REPLACEREPSYM
%left REPLACEALLSYM
%left RULEDELAYEDSYM
%left RULESYM
%left CONDITIONSYM
%left ALTSYM
%left SAMESYM
%left UNEQUALSYM
%left EQUALSYM
%left PLUSSYM /* Plus and minus seem to be reversed according to the table. Investigate this. */
%left MINUSSYM
%left MULTSYM
%left DIVSYM
%left EXPSYM
%left STRINGJOINSYM
%left APPLYSYM
%left MAPSYN
%right FUNCAPPSYM
%left PATTESTSYM
%nonassoc PATTERN
%nonassoc SLOTSYM
%left MESSAGENAMESYM /* This might as well be part of the symbol. Use a very
high precedence. */
%nonassoc STRING
%nonassoc NAME
%nonassoc FLOAT
%nonassoc INTEGER

%nonassoc LBRACKETSYM RBRACKETSYM
%nonassoc LCURLYSYM RCURLYSYM
%nonassoc LPARSYM RPARSYM

%nonassoc COMMASYM


%%

list	: /* empty */
	| list stat '\n'
	;

stat	:    expr
		{
			Calcrcvr.lval.val = $1
		}
	;

expr	:    LPARSYM expr RPARSYM
		{ $$  =  $2 }
	|    LPARSYM compexpr RPARSYM
		{
			ex := &Expression{}
			ex.Parts = []Ex{&Symbol{"CompoundExpression"}}
			ex.Parts = append(ex.Parts, $2...)
			$$ = ex
{'fraction_non_alphanumeric': 0.08256880733944955, 'fraction_numerical': 0.0015727391874180866, 'mean_word_length': 4.241758241758242, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '762950', 'n_tokens_mistral': 1592, 'n_tokens_neox': 1446, 'n_words': 471}