Cleanup success

This commit is contained in:
Daniel Flanagan 2019-11-19 22:28:05 -06:00
parent 58f9f43896
commit ed602ab3f3

View file

@ -1,22 +1,16 @@
Nonterminals Nonterminals
grammar grammar
expr_list e_list
expr e
assign_expr assignment
add_expr add
sub_expr sub
mult_expr mult
div_expr div
idiv_expr idiv
unary_expr unary
max_expr
number number
unary_op unary
add_op
sub_op
mult_op
div_op
idiv_op
. .
Terminals Terminals
@ -34,65 +28,53 @@ Left 400 '*'.
Left 400 '/'. Left 400 '/'.
Left 400 '//'. Left 400 '//'.
grammar -> expr_list : '$1'. grammar -> e_list : '$1'.
grammar -> '$empty' : []. grammar -> '$empty' : [].
expr_list -> eol : []. e_list -> eol : [].
expr_list -> expr : ['$1']. e_list -> e : ['$1'].
expr_list -> expr eol : ['$1']. e_list -> e eol : ['$1'].
expr_list -> eol expr_list : '$2'. e_list -> eol e_list : '$2'.
expr_list -> expr eol expr_list : ['$1'|'$3']. e_list -> e eol e_list : ['$1'|'$3'].
%% Minimum expressions %% Minimum expressions
max_expr -> var : '$1'. e -> var : '$1'.
max_expr -> number : '$1'. e -> number : '$1'.
max_expr -> '(' expr ')' : '$2'. e -> '(' e ')' : '$2'.
%% Numbers %% Numbers
number -> float : '$1'. number -> float : '$1'.
number -> integer : ?e(3, '$1'). number -> integer : ?e(3, '$1').
%% Unary operator e -> mult : '$1'.
unary_op -> '+' : '$1'. e -> div : '$1'.
unary_op -> '-' : '$1'. e -> idiv : '$1'.
e -> assignment : '$1'.
e -> add : '$1'.
e -> sub : '$1'.
e -> unary : '$1'.
%% Infix Operators assignment -> var '=' e :
add_op -> '+' : '$1'.
sub_op -> '-' : '$1'.
mult_op -> '*' : '$1'.
div_op -> '/' : '$1'.
idiv_op -> '//' : '$1'.
expr -> mult_expr : '$1'.
expr -> div_expr : '$1'.
expr -> idiv_expr : '$1'.
expr -> assign_expr : '$1'.
expr -> add_expr : '$1'.
expr -> sub_expr : '$1'.
expr -> unary_expr : '$1'.
expr -> max_expr : '$1'.
assign_expr -> var '=' expr :
{ '=', ?meta('$2'), [?var('$1'), '$3'] }. { '=', ?meta('$2'), [?var('$1'), '$3'] }.
%% Arithmetic operations %% Arithmetic operations
add_expr -> expr add_op expr : add -> e '+' e :
{ '+', ?meta('$2'), ['$1', '$3'] }. { '+', ?meta('$2'), ['$1', '$3'] }.
sub_expr -> expr sub_op expr : sub -> e '-' e :
{ '-', ?meta('$2'), ['$1', '$3'] }. { '-', ?meta('$2'), ['$1', '$3'] }.
mult_expr -> expr mult_op expr : mult -> e '*' e :
{ '*', ?meta('$2'), ['$1', '$3'] }. { '*', ?meta('$2'), ['$1', '$3'] }.
div_expr -> expr div_op expr : div -> e '/' e :
{ '/', ?meta('$2'), ['$1', '$3'] }. { '/', ?meta('$2'), ['$1', '$3'] }.
idiv_expr -> expr idiv_op expr : idiv -> e '//' e :
{ 'div', ?meta('$2'), ['$1', '$3'] }. { 'div', ?meta('$2'), ['$1', '$3'] }.
unary_expr -> unary_op expr : unary -> '+' e : { '+', ?meta('$1'), ?op('$1'), '$2' }.
{ unary_op, ?meta('$1'), ?op('$1'), '$2' }. unary -> '-' e : { '-', ?meta('$1'), ?op('$1'), '$2' }.
Erlang code. Erlang code.