Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
7.0 kB
2
Indexable
Never
grammar Latino;

program : statement_list EOF;
statement_list : statement statement_list | ;
statement : ID statement2 | statement_builtin_function | function_definition | if_statement | switch_statement | for_desde_statement | for_para_statement | while_statement | do_while_statement | ROMPER | return;
statement2 : increment_op | decrement_op | attribute_access2;
switch_statement : ELEGIR exp switch_body optional_defecto FIN;
switch_body : CASO caso_value TKN_COLON switch_body3 statement statement_list switch_body2 | defecto;
switch_body2 : CASO caso_value TKN_COLON switch_body3 statement statement_list switch_body2 | ;
switch_body3 : CASO caso_value TKN_COLON switch_body3 | ;
caso_value : TKN_REAL | TKN_STR;
defecto : defecto_keyword TKN_COLON statement statement_list;
optional_defecto : defecto_keyword TKN_COLON statement statement_list | ;
defecto_keyword : DEFECTO | OTRO;
for_desde_statement : DESDE TKN_OPENING_PAR ID assignment TKN_SEMICOLON exp TKN_SEMICOLON statement TKN_CLOSING_PAR statement statement_list FIN;
for_para_statement : PARA ID EN rango statement statement_list FIN;
rango : RANGO TKN_OPENING_PAR rango_params TKN_CLOSING_PAR;
rango_params : signed_number rango_params_tail;
rango_params_tail : TKN_COMMA signed_number rango_params_tail2 | ;
rango_params_tail2 : TKN_COMMA signed_number | ;
signed_number : TKN_MINUS TKN_REAL | TKN_REAL;
while_statement : MIENTRAS exp statement statement_list FIN;
do_while_statement : REPETIR statement statement_list HASTA exp;
if_statement : SI exp statement statement_list osi_statements sino_statement FIN;
osi_statements : OSI exp statement statement_list osi_statements | ;
sino_statement : SINO statement statement_list | ;
function_definition : FUN ID TKN_OPENING_PAR function_params TKN_CLOSING_PAR statement statement_list FIN | FUNCION ID TKN_OPENING_PAR function_params TKN_CLOSING_PAR statement statement_list FIN;
function_definition_without_id : FUN TKN_OPENING_PAR function_params TKN_CLOSING_PAR statement statement_list FIN | FUNCION TKN_OPENING_PAR function_params TKN_CLOSING_PAR statement statement_list FIN;
function_params : ID function_params_tail | ;
function_params_tail : TKN_COMMA ID function_params_tail | ;
return : return_keyword exp;
return_keyword : RETORNAR | RET | RETORNO;
call_function : TKN_OPENING_PAR function_args TKN_CLOSING_PAR;
function_args : exp function_args2 | ;
function_args2 : TKN_COMMA exp function_args2 | ;
statement_builtin_function : builtin_function_zero_args TKN_OPENING_PAR TKN_CLOSING_PAR | builtin_function_one_arg TKN_OPENING_PAR exp TKN_CLOSING_PAR | IMPRIMIRF TKN_OPENING_PAR TKN_STR function_args2 TKN_CLOSING_PAR | ACADENA TKN_OPENING_PAR exp TKN_CLOSING_PAR;
builtin_function_zero_args : LIMPIAR;
builtin_function_one_arg : ESCRIBIR | PONER | IMPRIMIR;
builtin_function_in_exp : builtin_function_in_exp_keyword TKN_OPENING_PAR exp TKN_CLOSING_PAR;
builtin_function_in_exp_keyword : ACADENA | ALOGICO | ANUMERO | TIPO;
increment_op : TKN_INCREMENT;
decrement_op : TKN_DECREMENT;
assignment : simple_assignment | TKN_COMMA multiple_assignment;
simple_assignment : augmented_assignment_op exp | TKN_ASSIGN simple_assignment2;
simple_assignment2 : exp_list;
augmented_assignment_op : TKN_MOD_ASSIGN | TKN_DIV_ASSIGN | TKN_TIMES_ASSIGN | TKN_MINUS_ASSIGN | TKN_PLUS_ASSIGN;
multiple_assignment : id_list TKN_ASSIGN exp_list;
id : ID attribute_access;
attribute_access : TKN_PERIOD dot_access | bracket_access | ;
dot_access : ID attribute_access;
bracket_access : TKN_OPENING_BRA bracket_access_value attribute_access;
bracket_access_value : exp TKN_CLOSING_BRA;
attribute_access2 : TKN_PERIOD dot_access2 | bracket_access2 | call_function | assignment;
dot_access2 : ID attribute_access2;
bracket_access2 : TKN_OPENING_BRA exp TKN_CLOSING_BRA attribute_access2;
id_list : ID id_list1;
id_list1 : TKN_COMMA ID id_list1 | ;
exp_list : exp exp_list1 | LEER TKN_OPENING_PAR TKN_CLOSING_PAR;
exp_list1 : TKN_COMMA exp_list2 | ;
exp_list2 : exp exp_list1 | LEER TKN_OPENING_PAR TKN_CLOSING_PAR;
exp :	exp_bool exp1;
exp1 :	TKN_OR exp_bool exp1 | ;
exp_bool :	exp_concat exp_bool1;
exp_bool1 : TKN_AND exp_concat exp_bool1 | ;
exp_concat : exp_rel exp_concat2;
exp_concat2 : TKN_CONCAT exp_rel exp_concat2 | ;
exp_rel : exp_sum exp_rel1;
exp_rel1 : rel_op exp_sum | ;
rel_op : TKN_LESS | TKN_LEQ | TKN_GREATER | TKN_GEQ | TKN_EQUAL | TKN_NEQ | TKN_REGEX;
exp_sum : term exp_sum2;
exp_sum2 : sum_op term exp_sum2 | ;
sum_op : TKN_PLUS | TKN_MINUS;
term : exp_pot term2;
term2 : mul_op exp_pot term2 | ;
mul_op : TKN_DIV | TKN_MOD | TKN_TIMES;
exp_pot : factor exp_pot2;
exp_pot2 : TKN_POWER factor exp_pot2 | ;
factor : TKN_STR | TKN_REAL | VERDADERO | FALSO | NULO | CIERTO | unary_op factor | TKN_OPENING_PAR exp TKN_CLOSING_PAR | builtin_function_in_exp | array | dict | ID factor2;
unary_op : TKN_NOT | TKN_MINUS | TKN_PLUS;
factor2 : attribute_access factor3;
factor3 : call_function | ;
array : TKN_OPENING_BRA array_elements TKN_CLOSING_BRA;
array_elements : exp array_elements_tail | function_definition_without_id array_elements_tail | ;
array_elements_tail : TKN_COMMA array_elements | ;
dict : TKN_OPENING_KEY dict_elements TKN_CLOSING_KEY;
dict_elements : dict_key TKN_COLON dict_value dict_elements_tail | ;
dict_elements_tail : TKN_COMMA dict_elements | ;
dict_key : exp;
dict_value : exp | function_definition_without_id;


TKN_COLON : ':';
TKN_OPENING_PAR : '(';
TKN_CLOSING_PAR : ')';
TKN_SEMICOLON : ';';
TKN_COMMA : ',';
TKN_MINUS : '-';
TKN_REAL : [0-9]+('.'[0-9]+)?;
TKN_STR : '\'' (ESC_SEQ | ~[\\'] | '\\' .)*? '\'' | '"' (ESC_SEQ | ~[\\"] | '\\' .)*? '"';
fragment ESC_SEQ : '\\' [btnfr"'\\] ;
TKN_INCREMENT : '++';
TKN_DECREMENT : '--';
TKN_PERIOD : '.';
TKN_OPENING_BRA : '[';
TKN_CLOSING_BRA : ']';
TKN_OPENING_KEY : '{';
TKN_CLOSING_KEY : '}';
TKN_ASSIGN : '=';
TKN_MOD_ASSIGN : '%=';
TKN_DIV_ASSIGN : '/=';
TKN_TIMES_ASSIGN : '*=';
TKN_MINUS_ASSIGN : '-=';
TKN_PLUS_ASSIGN : '+=';
TKN_OR : '||';
TKN_AND : '&&';
TKN_CONCAT : '..';
TKN_LESS : '<';
TKN_LEQ : '<=';
TKN_GREATER : '>';
TKN_GEQ : '>=';
TKN_EQUAL : '==';
TKN_NEQ : '!=';
TKN_REGEX : '~=';
TKN_PLUS : '+';
TKN_DIV : '/';
TKN_MOD : '%';
TKN_TIMES : '*';
TKN_POWER : '^';
VERDADERO : 'verdadero';
FALSO : 'falso';
NULO : 'nulo';
CIERTO : 'cierto';
TKN_NOT : '!';
IMPRIMIRF : 'imprimirf';
LEER : 'leer';
LIMPIAR : 'limpiar';
ESCRIBIR : 'escribir';
PONER : 'poner';
IMPRIMIR : 'imprimir';
ACADENA : 'acadena';
ALOGICO : 'alogico';
ANUMERO : 'anumero';
TIPO : 'tipo';
ROMPER : 'romper';
ELEGIR : 'elegir';
CASO : 'caso';
DEFECTO : 'defecto';
OTRO : 'otro';
DESDE : 'desde';
PARA : 'para';
EN : 'en';
RANGO : 'rango';
MIENTRAS : 'mientras';
REPETIR : 'repetir';
HASTA : 'hasta';
SI : 'si';
OSI : 'osi';
SINO : 'sino';
FUN : 'fun';
FUNCION : 'funcion';
RETORNAR : 'retornar';
RET : 'ret';
RETORNO : 'retorno';
FIN : 'fin';
ID : [a-zA-Z_][a-zA-Z0-9_]*;
WS : [ \t\r\n]+ -> skip ;
LINE_COMMENT : '//' ~[\r\n]* -> skip ;
LINE_COMMENT_2 : '#' ~[\r\n]* -> skip ;
BLOCK_COMMENT : '/*' .*? '*/' -> skip ;
Leave a Comment