Created
January 20, 2022 07:06
-
-
Save loguntsov/658fa7e05f8bcc42e08e1e9d64725140 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Header | |
"%%" | |
"%% @Author: Sergey Loguntsov <loguntsov@gmail.com>" | |
"%%" | |
"%%". | |
Nonterminals | |
main_program exp_el | |
expression | |
func_call args | |
list list_items list_items_with_map | |
hlist hlist_item hlist_items | |
map map_items | |
probability_weight | |
left_arrow right_arrow plus_arrow | |
attention | |
pointer | |
range | |
. | |
Terminals str identifier ',' '[' ']' ':' '::' '=' '@' '{' '}' '(' ')' '#' '||' '->' '<-' '+>' '!' '&' '--'. | |
Rootsymbol main_program. | |
main_program -> list_items : '$1'. | |
main_program -> list_items_with_map : '$1'. | |
main_program -> map_items : '$1'. | |
exp_el -> str : '$1'. | |
exp_el -> identifier : ai_dsl_token:try_convert_to_number_token('$1'). | |
exp_el -> func_call : '$1'. | |
exp_el -> list : '$1'. | |
exp_el -> hlist : '$1'. | |
exp_el -> map : '$1'. | |
exp_el -> identifier '=' exp_el : | |
#assign_token{ | |
line = ai_dsl_token:get_line('$1'), | |
name = '$1', | |
value = '$3' | |
}. | |
exp_el -> exp_el '@' identifier : | |
#assign_token{ | |
line = ai_dsl_token:get_line('$1'), | |
name = #identifier{ value = <<"@", ('$3'#identifier.value)/binary>> }, | |
value = '$1' | |
}. | |
exp_el -> '@' identifier : | |
#identifier{ value = <<"@", ('$2'#identifier.value)/binary>> }. | |
exp_el -> '@' : #identifier{ value = <<"@">> }. | |
exp_el -> probability_weight : '$1'. | |
exp_el -> '(' expression ')' : '$2'. | |
exp_el -> attention : '$1'. | |
exp_el -> pointer : '$1'. | |
exp_el -> range : '$1'. | |
probability_weight -> identifier '#' exp_el : | |
#weight{ | |
weight = ai_dsl_token:try_convert_to_number_token('$1'), | |
func = '$3' | |
}. | |
expression -> exp_el : '$1'. | |
expression -> '@' func_call : | |
#postponed_token{ | |
line = ai_dsl_token:get_line('$2'), | |
value = [ '$2' ] | |
}. | |
expression -> '@' '{' list_items '}' : #postponed_token{ line = element(2, '$1'), value = '$3' }. | |
expression -> left_arrow : '$1'. | |
expression -> right_arrow : '$1'. | |
expression -> plus_arrow : '$1'. | |
list -> '[' ']' : []. | |
list -> '[' list_items ']' : '$2'. | |
list -> '[' list_items_with_map ']' : '$2'. | |
list_items -> expression : ['$1']. | |
list_items -> list_items ',' : '$1'. | |
list_items -> list_items ',' expression : '$1' ++ ['$3']. | |
list_items_with_map -> list_items ',' map_items : '$1' ++ ['$3']. | |
hlist -> '[' hlist_items ']' : '$2'. | |
hlist -> '(' hlist_items ')' : '$2'. | |
hlist_item -> list_items : '$1'. | |
hlist_item -> list_items_with_map : '$1'. | |
hlist_items -> hlist_item '||' hlist_item : #hlist{ list = ['$1', '$3']}. | |
hlist_items -> '||' hlist_item : #hlist{ list = ['$2']}. | |
hlist_items -> '||' : #hlist{ list = [[]] }. | |
hlist_items -> hlist_items '||' hlist_item : #hlist{ list = '$1'#hlist.list ++ ['$3'] }. | |
hlist_items -> hlist_items '||' : #hlist{ list = '$1'#hlist.list ++ [[]] }. | |
map -> '[' map_items ']' : '$2'. | |
map_items -> identifier ':' expression : #{ '$1' => '$3' }. | |
map_items -> map_items ',' : '$1'. | |
map_items -> map_items ',' identifier ':' expression : maps:put('$3', '$5', '$1'). | |
func_call -> identifier args : | |
#func{ | |
line = ai_dsl_token:get_line('$1'), | |
func = { default_module, ai_dsl_token:get_value('$1') }, | |
arg = '$2' | |
}. | |
func_call -> identifier '::' identifier args : | |
#func{ | |
line = ai_dsl_token:get_line('$1'), | |
func = { ai_dsl_token:get_value('$1'), ai_dsl_token:get_value('$3') }, | |
arg = '$4' | |
}. | |
args -> str : '$1'. | |
args -> list : '$1'. | |
args -> map : '$1'. | |
args -> hlist : '$1'. | |
right_arrow -> exp_el '->' right_arrow : '$3'#sequence{ list = [ '$1' | '$3'#sequence.list ]}. | |
right_arrow -> exp_el '->' exp_el : #sequence{ type ='-', list = [ '$1', '$3' ]}. | |
left_arrow -> left_arrow '<-' exp_el : '$1'#sequence{ list = [ '$3' | '$1'#sequence.list ]}. | |
left_arrow -> exp_el '<-' exp_el : #sequence{ type = '-', list = [ '$3', '$1' ]}. | |
plus_arrow -> exp_el '+>' plus_arrow : '$3'#sequence{ list = [ '$1' | '$3'#sequence.list ]}. | |
plus_arrow -> exp_el '+>' exp_el : #sequence{ type = '+', list = [ '$1', '$3' ]}. | |
attention -> '!' expression : {'!', '$2' }. | |
pointer -> '&' identifier : {'&', '$2' }. | |
range -> exp_el '--' exp_el : #range{ start = '$1', finish = '$3' }. | |
Erlang code. | |
to_list(Element) when is_tuple(Element) -> [Element]; | |
to_list(List) when is_list(List) -> List. | |
get_finish([]) -> 0; | |
get_finish([ Token | List ]) -> | |
max(element(4, Token), get_finish(List)). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment