All Downloads are FREE. Search and download functionalities are using the official Maven repository.

moss.4.3.1.source-code.postfix2.grammar Maven / Gradle / Ivy

The newest version!
Package prerna.sablecc2;

Helpers
 all = [0 .. 0xFFFF];
 letter_s = ['a' .. 'z'];
 letter_b = ['A' .. 'Z'];
 digit = ['0' .. '9'];
 underscore = '_';
 // words in double quotes
 // allow for escaped double quotes
 double_quote = '"';
 escaped_double_quote = '\"';
 not_double_quote = [all - '"'] | escaped_double_quote;
 double_quote_word = double_quote not_double_quote* double_quote;
 // words in single quotes
 // does not allow for escaped single quotes
 single_quote = ''';
 not_single_quote = [all - '''];
 single_quote_word = single_quote not_single_quote* single_quote;
 url_unescaped_chars = ('-' | '_' | '.' | '!' | '~' | '*' | '+' | ''' | '(' | ')' | '%');
 encoded_values = (letter_s | letter_b | digit | url_unescaped_chars);
 not_hash = [all - '#'];
 not_star = [all - '*'];
 not_star_not_slash = [all - ['*' + '/']];
 traditional_comment = '/*' not_star+ '*'+ (not_star_not_slash not_star* '*'+)* '/';
 documentation_comment = '/**' '*'* (not_star_not_slash not_star* '*'+)* '/';
 hash_comment = '##' not_hash+ (not_hash | ('#' not_hash)+)* '##'; 
 
Tokens
 null = 'null';
 number = ['0' .. '9']+;
 boolean = ('TRUE' | 'FALSE' | 'true' | 'false');
 meta = 'META';
 id = (letter_s | letter_b | digit | underscore)*;
 dot = '.';
 semicolon = ';';
 colon = ':';
 plus = '+';
 minus = '-';
 mod = '%';
 pow = '^';
 word = (single_quote_word | double_quote_word);
 comment = traditional_comment | documentation_comment | hash_comment;
 mult = '*';
 comma = ',';
 div = '/';
 comparator = ('>' | '<' | '<=' | '>=' | '!=' | '?like' | '?nlike' | '?begins' | '?nbegins' | '?ends' | '?nends' | '==' | '<>');
 and_comparator = ' AND ';
 or_comparator = ' OR ';
 equal = '=';
 l_par = '(';
 r_par = ')';
 l_brac = '[';
 r_brac = ']';
 l_curl = '{';
 r_curl = '}';
 frameprefix = 'f$';
 frameid = 'f.';
 blank = (' ' | 13 | 10);
 java = '' encoded_values* '';
 if = 'if';
 as_op = ('.as' | '.out');
 custom = '|';
 rel_type = ('inner.join' | 'outer.join' | 'right.outer.join' | 'left.outer.join' | 'cross.join' | 'self.join' ); 
 help_token = '-- help' | '--help';

 
Ignored Tokens
 blank;

Productions 

 ///////////////////////////////////////////////////////////////////////
 ///////////////////////// START HIGHEST LEVEL /////////////////////////
 ///////////////////////////////////////////////////////////////////////
 
 configuration = {routine} routine* | {empty} emptyroutine;
 
 // all routines are a series of scripts
 // or an assignment from the series of scripts
 routine = 
	{output} script semicolon+
	| {assign} assignment semicolon+
	| {meta} meta_routine semicolon+
	| {main_comment} comment
	;
 
 emptyroutine = semicolon+;
 
 script = master_expr otherscript*;
 otherscript = custom master_expr;
 // an assignment if a word or number equal to
 // some kind of evaluation
 assignment = id equal script;

 // allow for meta expressions + assignments
 meta_routine = {meta_script} meta custom script |
	{meta_assignment} meta custom assignment;
 
 // i need a way to allow for an embedded_script
 // but i need it to not conflict with a formula
 // so this is basically just enforcing that there is a pipe
 mandatory_scriptchain = master_expr otherscript+;
 
 base_sub_expr = master_expr semicolon;
 base_sub_script = mandatory_scriptchain semicolon;
 base_assignment = assignment semicolon;
 sub_routine_options = {simple} base_sub_expr | {chain} base_sub_script | {assignment} base_assignment; 
 sub_routine = sub_routine_options+;
 
 ///////////////////////////////////////////////////////////////////////
 ///////////////////////// END HIGHEST LEVEL ///////////////////////////
 ///////////////////////////////////////////////////////////////////////
  
 ///////////////////////////////////////////////////////////////////////
 //////////////////////////// COMPOSITES  //////////////////////////////
 ///////////////////////////////////////////////////////////////////////
 
 // this is the highest level object that the user interacts with
 // this is a base expression -> which goes all the way down to a basic number/string
 // and it includes comparisons

 master_expr = {normal} expr
	| {comparison} comparison_expr
	;
 
 expr = {base_expr} base_expr
	// note that the embedded_assignment can be set to an inner script!
	// or we can have a full inner script just for fun as well!
	| {embedded_routine} l_par sub_routine r_par 
	| {embedded_assignment} l_par assignment r_par
	| {help} id help_token
	| {comment} comment
	;
 
 // expr component goes from a defined reactor all the way down to basic number/string
 // everything else is just some mathematical operation using expr_component
 base_expr =  
	{expr_component} expr_component
	| {plus} [left]:expr_component plus [right]:base_expr
	| {minus} [left]:expr_component minus [right]:base_expr
	| {mult} [left]:expr_component mult [right]:base_expr 
	| {div} [left]:expr_component div [right]:base_expr 
	| {mod} [left]:expr_component mod [right]:base_expr
	;
 
 // base expression component is a term or a power
 expr_component = {term} term | {power} power | {embedded_scriptchain} l_par mandatory_scriptchain r_par ;
 
 // to handle 5 ^ 2
 power = [base]:expr_component pow [exponent]:term;
 
 term = {reg_term} reg_term | {neg_term} neg_term | {pos_term} pos_term;
 // to accomodate for -var and +var 
 neg_term = minus term;
 pos_term = plus term;
 
 reg_term =
    {scalar} scalar
	| {map} map
	| {formula} formula
	| {operation} operation
	| {ref} rcol
	| {dotcol} dotcol 
	| {java_op} java_op 
	| {list} list
	| {csv} gen_row
  	; 
 
 // need to able to group expressions 
 // will call this a formula
 // required for correct order of operations
 formula = l_par expr r_par;
 
 // need to allow a list of expressions
 list = 
	{empty} no_values_list 
	| {filled} values_list
	;
 no_values_list = l_par r_par;
 values_list = l_par master_expr other_expr+ r_par;
 other_expr = comma master_expr;
 
 // operation is how is how we define PKSL functions (reactors)
 // previously had frameop and operation_formula
 // now they are combined so you can have ID(a, b, x=[c]) all in one
 operation = id l_par op_input? other_op_input* r_par asop?;
 op_input = {noun} noun | {input} col_def;
 other_op_input = comma op_input;

 // when we need an array of arrays
 gen_row = l_brac col_def? othercol* r_brac; 
 othercol =  comma col_def;
 
 // col def is an expression, a prop, or a relationship
 col_def = {expr} master_expr 
		| {prop} prop 
		| {relation} relationship
		;
  
 // NOUN ::: id = [gen_row, gen_row, gen_row...]
 noun = id equal gen_row;
 // SHORTHAND NOTATION FOR NOUN
 prop = id equal scalar;
 
 // operation used for aliasing columns
 asop = as_op l_par gen_row r_par;
 
 // relationship is used for joins within a database and table joining when adding new data to existing frame
 relationship = {explicit} explicit_rel | {explicit_comparator} explicit_rel_comparator | {implicit} implicit_rel;
 implicit_rel = l_par [lcol]:col_def [comma1]:comma rel_type [comma2]:comma [rcol]:col_def r_par;
 explicit_rel_comparator = l_par [lcol]:col_def [comma1]:comma rel_type [comma2]:comma [rcol]:col_def [comma3]:comma [comparator]:comparator r_par;
 explicit_rel = l_par [lcol]:col_def [comma1]:comma rel_type [comma2]:comma [rcol]:col_def [comma3]:comma [relationship_name]:col_def r_par;
 
 ///////////////////////////////////////////////////////////////////////
 /////////////////////////// COMPARISONS ///////////////////////////////
 /////////////////////////////////////////////////////////////////////// 
 
 comparison_expr = {term} comparison_term
		| {comparison_group} comparison_group
		| {complex_or} comparison_group or_comparator comparison_expr
		| {complex_and} comparison_group and_comparator comparison_expr
		;

 comparison_term = {basic} base_simple_comparison
	| {basic_and} and_comparison
	| {basic_or} or_comparison
	;		
		
 comparison_group = l_par comparison_expr r_par;
 
 and_comparison = {simple_case} [left]:term and_comparator [right]:term [more_right]:repeating_and_comparison*
	| {left_complex} [left]:term and_comparator [right]:base_simple_comparison [more_right]:repeating_and_comparison*
	| {right_complex} [left]:base_simple_comparison and_comparator [right]:term [more_right]:repeating_and_comparison*
	| {both_complex} [left]:base_simple_comparison and_comparator [right]:base_simple_comparison [more_right]:repeating_and_comparison*
	;
 repeating_and_comparison = and_comparator base_simple_comparison;

 or_comparison = {simple_case} [left]:term or_comparator [right]:term [more_right]:repeating_or_comparison*
	| {left_complex} [left]:term or_comparator [right]:base_simple_comparison [more_right]:repeating_or_comparison*
	| {right_complex} [left]:base_simple_comparison or_comparator [right]:term [more_right]:repeating_or_comparison*
	| {both_complex} [left]:base_simple_comparison or_comparator [right]:base_simple_comparison [more_right]:repeating_or_comparison*
	;
 repeating_or_comparison = or_comparator base_simple_comparison;

 base_simple_comparison = [left]:base_expr comparator [right]:base_expr;

 ///////////////////////////////////////////////////////////////////////
 ////////////////////////// END COMPOSITES  ////////////////////////////
 ///////////////////////////////////////////////////////////////////////
  
 ///////////////////////////////////////////////////////////////////////
 ////////////////////////////// OTHER  /////////////////////////////////
 ///////////////////////////////////////////////////////////////////////
  
 // for java and r operations
 java_op = java;

 // reference - this means the 4th column in the current frame
 rcol = frameprefix [column_name]:id; // f$Title
 dotcol = frameid [column_name]:id; // f.Title
 
 ///////////////////////////////////////////////////////////////////////
 //////////////////////////// END OTHER  ///////////////////////////////
 ///////////////////////////////////////////////////////////////////////

 ///////////////////////////////////////////////////////////////////////
 ////////////////////////////// MAP ////////////////////////////////////
 ///////////////////////////////////////////////////////////////////////
 
 // map is a key : value
 // where the value is a scalar, variable, vector of scalars/variables, or another nested map
 map = l_curl map_entry? other_map_entry* r_curl;
 
 map_entry = [key]:map_key colon [val]:values;
 other_map_entry = [comma]:comma map_entry;
 
 // DO NOT USE THE BELOW FOR ANYTHING ASIDE FOR MAPS!
 // we already have a way to take vectors
 // this is just because we only want to maintain scalars and not allow for
 // evaluations in maps that are being stored on the BE
 values = {simple} map_base_input | {list} map_list | {nested_map} map | {map_operation} operation;
 
 map_list = l_brac map_extended_input? map_list_extend* r_brac;
 map_list_extend = comma map_extended_input;
 
 map_key = {word} word | {var} map_var;
 map_extended_input = {list} map_list | {scalar} map_base_input | {nested_map} map;  
 map_base_input = {map_var} map_var | {normal_scalar} scalar | {map_neg_num} map_neg_num;
 map_var = [start]:l_curl [var]:id [end]:r_curl;
 map_neg_num = minus decimal;
 
 
 ///////////////////////////////////////////////////////////////////////
 /////////////////////////// END MAP ///////////////////////////////////
 ///////////////////////////////////////////////////////////////////////
 
 
 ///////////////////////////////////////////////////////////////////////
 ///////////////////////// LOWEST LEVEL ////////////////////////////////
 ///////////////////////////////////////////////////////////////////////
 
 // word or id or number
 scalar = {num} decimal | {boolean} boolean | {null} null | {word_or_id} word_or_id ;
 
 // word or an id
 word_or_id = {word} word | {id} id;
 
 // numbers
 decimal = {whole_decimal} whole_decimal | {fraction_decimal} fraction_decimal;
 whole_decimal = [whole]:number dot? [fraction]:number?;
 fraction_decimal = dot [fraction]:number;
 
 ///////////////////////////////////////////////////////////////////////
 /////////////////////// END LOWEST LEVEL //////////////////////////////
 ///////////////////////////////////////////////////////////////////////
 




© 2015 - 2025 Weber Informatics LLC | Privacy Policy