generic package burg_lr_vals_fun(package token: Token;)
: (weak) api { package parser_data : Parser_Data;
package tokens : Burg_Tokens;
}
{
package parser_data{
package header {
# burg.grammar
#
# Mythryl-Yacc grammar for BURG.
# Compiled by:
#
src/app/burg/mythryl-burg.libpackage a = burg_ast;
fun output_raw s
=
print (s: String);
};
package lr_table = token::lr_table;
package token = token;
stipulate include package lr_table; herein
my table={ action_rows =
"\
\\x01\x00\x01\x00\x00\x00\x00\x00\
\\x01\x00\x02\x00\x0a\x00\x03\x00\x09\x00\x04\x00\x08\x00\x05\x00\x07\x00\
\\x06\x00\x06\x00\x0e\x00\x05\x00\x00\x00\
\\x01\x00\x07\x00\x18\x00\x00\x00\
\\x01\x00\x08\x00\x26\x00\x00\x00\
\\x01\x00\x0b\x00\x28\x00\x00\x00\
\\x01\x00\x0b\x00\x2d\x00\x00\x00\
\\x01\x00\x0c\x00\x1d\x00\x00\x00\
\\x01\x00\x0e\x00\x15\x00\x10\x00\x14\x00\x00\x00\
\\x01\x00\x0f\x00\x27\x00\x00\x00\
\\x01\x00\x0f\x00\x2e\x00\x00\x00\
\\x01\x00\x10\x00\x0c\x00\x00\x00\
\\x01\x00\x10\x00\x0d\x00\x00\x00\
\\x01\x00\x10\x00\x0e\x00\x00\x00\
\\x01\x00\x10\x00\x0f\x00\x00\x00\
\\x01\x00\x10\x00\x12\x00\x00\x00\
\\x01\x00\x10\x00\x1a\x00\x00\x00\
\\x01\x00\x10\x00\x1c\x00\x00\x00\
\\x01\x00\x10\x00\x20\x00\x00\x00\
\\x31\x00\x00\x00\
\\x32\x00\x00\x00\
\\x33\x00\x00\x00\
\\x34\x00\x0d\x00\x16\x00\x00\x00\
\\x35\x00\x00\x00\
\\x36\x00\x00\x00\
\\x37\x00\x00\x00\
\\x38\x00\x00\x00\
\\x39\x00\x00\x00\
\\x3a\x00\x00\x00\
\\x3b\x00\x0c\x00\x17\x00\x00\x00\
\\x3c\x00\x00\x00\
\\x3d\x00\x00\x00\
\\x3e\x00\x00\x00\
\\x3f\x00\x00\x00\
\\x40\x00\x00\x00\
\\x41\x00\x0a\x00\x1e\x00\x00\x00\
\\x42\x00\x00\x00\
\\x43\x00\x09\x00\x25\x00\x00\x00\
\\x44\x00\x00\x00\
\\x45\x00\x0a\x00\x23\x00\x00\x00\
\\x46\x00\x00\x00\
\\x47\x00\x09\x00\x2b\x00\x00\x00\
\\x48\x00\x00\x00\
\";
action_row_numbers =
"\x13\x00\x01\x00\x14\x00\x1e\x00\
\\x0a\x00\x0b\x00\x0c\x00\x0d\x00\
\\x0e\x00\x07\x00\x19\x00\x18\x00\
\\x17\x00\x16\x00\x15\x00\x1a\x00\
\\x1c\x00\x1f\x00\x02\x00\x12\x00\
\\x0e\x00\x0f\x00\x10\x00\x1b\x00\
\\x1d\x00\x06\x00\x22\x00\x11\x00\
\\x10\x00\x26\x00\x21\x00\x24\x00\
\\x03\x00\x08\x00\x04\x00\x10\x00\
\\x20\x00\x28\x00\x23\x00\x24\x00\
\\x05\x00\x09\x00\x25\x00\x27\x00\
\\x28\x00\x29\x00\x00\x00";
goto_table =
"\
\\x01\x00\x2e\x00\x0a\x00\x01\x00\x00\x00\
\\x03\x00\x02\x00\x00\x00\
\\x00\x00\
\\x0b\x00\x09\x00\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x04\x00\x0f\x00\x0d\x00\x0e\x00\x00\x00\
\\x0c\x00\x11\x00\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x04\x00\x17\x00\x00\x00\
\\x00\x00\
\\x08\x00\x19\x00\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x07\x00\x1d\x00\x00\x00\
\\x08\x00\x1f\x00\x00\x00\
\\x05\x00\x20\x00\x00\x00\
\\x00\x00\
\\x09\x00\x22\x00\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x08\x00\x27\x00\x00\x00\
\\x00\x00\
\\x06\x00\x28\x00\x00\x00\
\\x00\x00\
\\x09\x00\x2a\x00\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x00\x00\
\\x06\x00\x2d\x00\x00\x00\
\\x00\x00\
\\x00\x00\
\";
numstates = 47;
numrules = 24;
s = REF ""; index = REF 0;
string_to_int = \\ () =
{ i = *index;
index := i+2;
string::get_byte(*s, i) + string::get_byte(*s, i+1) * 256;
};
string_to_list = \\ s' =
{ len = string::length_in_bytes s';
fun f () =
if (*index < len)
string_to_int() ! f();
else NIL; fi;
index := 0;
s := s';
f ();
};
string_to_pairlist = \\ (conv_key, conv_entry) = f
where
fun f ()
=
case (string_to_int ())
0 => EMPTY;
n => PAIR (conv_key (n - 1), conv_entry (string_to_int()), f());
esac;
end;
string_to_pairlist_default = \\ (conv_key, conv_entry) =
{ conv_row = string_to_pairlist (conv_key, conv_entry);
\\ () =
{ default = conv_entry (string_to_int());
row = conv_row();
(row, default);
};
};
string_to_table = \\ (convert_row, s') =
{ len = string::length_in_bytes s';
fun f ()
=
if (*index < len)
convert_row() ! f();
else NIL; fi;
s := s';
index := 0;
f ();
};
stipulate
memo = rw_vector::make_rw_vector (numstates+numrules, ERROR);
my _ ={ fun g i
=
{ rw_vector::set (memo, i, REDUCE (i-numstates));
g (i+1);
};
fun f i
=
if (i == numstates)
g i;
else rw_vector::set (memo, i, SHIFT (STATE i));
f (i+1);
fi;
f 0
except
INDEX_OUT_OF_BOUNDS = ();
};
herein
entry_to_action
=
\\ 0 => ACCEPT;
1 => ERROR;
j => rw_vector::get (memo, (j - 2));
end;
end;
goto_table = rw_vector::from_list (string_to_table (string_to_pairlist (NONTERM, STATE), goto_table));
action_rows = string_to_table (string_to_pairlist_default (TERM, entry_to_action), action_rows);
action_row_numbers = string_to_list action_row_numbers;
action_table
=
{ action_row_lookup
=
{ a=rw_vector::from_list (action_rows);
\\ i = rw_vector::get (a, i);
};
rw_vector::from_list (map action_row_lookup action_row_numbers);
};
lr_table::make_lr_table {
actions => action_table,
gotos => goto_table,
rule_count => numrules,
state_count => numstates,
initial_state => STATE 0 };
};
end;
stipulate include package header; herein
Source_Position = Int;
Arg = Void;
package values {
Semantic_Value = TM_VOID
| NT_VOID Void | RAW (List String ) | ID (String) | INT (Int) | PPERCENT (List String ) | QQ_POSTLUDE (Void) | QQ_PRELUDE (Void) | QQ_RAW (Void)
| QQ_BINDINGLIST (List ((String, Null_Or String)) ) | QQ_RULE (a::Rule_Ast) | QQ_RULES (List a::Rule_Ast ) | QQ_DECLS (List a::Decl_Ast ) | QQ_PATTERNTAIL (List a::Pattern_Ast )
| QQ_PATTERN (a::Pattern_Ast) | QQ_RULENAME (String) | QQ_COSTTAIL (List Int ) | QQ_COST (List Int ) | QQ_BINDING ((String, Null_Or String)) | QQ_DECL (a::Decl_Ast) | QQ_SPEC (a::Spec_Ast)
| QQ_FULL (a::Spec_Ast);
};
Semantic_Value = values::Semantic_Value;
Result = a::Spec_Ast;
end;
package error_recovery{
include package lr_table;
infix my 60 @@;
fun x @@ y = y ! x;
is_keyword =
\\ _ => FALSE; end;
my preferred_change: List( (List( Terminal ), List( Terminal )) ) =
NIL;
no_shift =
\\ _ => FALSE; end;
show_terminal =
\\ (TERM 0) => "K_EOF"
; (TERM 1) => "K_TERM"
; (TERM 2) => "K_START"
; (TERM 3) => "K_TERMPREFIX"
; (TERM 4) => "K_RULEPREFIX"
; (TERM 5) => "K_SIG"
; (TERM 6) => "K_COLON"
; (TERM 7) => "K_SEMICOLON"
; (TERM 8) => "K_COMMA"
; (TERM 9) => "K_LPAREN"
; (TERM 10) => "K_RPAREN"
; (TERM 11) => "K_EQUAL"
; (TERM 12) => "K_PIPE"
; (TERM 13) => "PPERCENT"
; (TERM 14) => "INT"
; (TERM 15) => "ID"
; (TERM 16) => "RAW"
; _ => "bogus-term"; end;
stipulate include package header; herein
errtermvalue=
\\ _ => values::TM_VOID;
end; end;
my terms: List( Terminal ) = NIL
@@ (TERM 12) @@ (TERM 11) @@ (TERM 10) @@ (TERM 9) @@ (TERM 8) @@ (TERM 7) @@ (TERM 6) @@ (TERM 5) @@ (TERM 4) @@ (TERM 3) @@ (TERM 2) @@ (TERM 1) @@ (TERM 0);
};
package actions {
exception MLY_ACTION Int;
stipulate include package header; herein
actions =
\\ (i392, default_position, stack,
(()): Arg) =
case (i392, stack)
( 0, ( ( _, ( values::PPERCENT ppercent2, _, ppercent2right)) ! ( _, ( values::QQ_RULES rules, _, _)) ! ( _, ( values::PPERCENT ppercent1, _, _)) ! ( _, ( values::QQ_DECLS decls,
decls1left, _)) ! rest671)) => { my result = values::QQ_FULL (a::SPEC{ head => ppercent1,
decls => reverse decls,
rules => reverse rules,
tail => ppercent2});
(
lr_table::NONTERM 0, ( result, decls1left, ppercent2right), rest671);
}
; ( 1, ( rest671)) => { my result = values::QQ_DECLS ([]);
( lr_table::NONTERM 9, ( result, default_position, default_position), rest671);
}
; ( 2, ( ( _, ( values::QQ_DECL decl, _, decl1right)) ! ( _, ( values::QQ_DECLS decls, decls1left, _)) ! rest671)) => { my result = values::QQ_DECLS (decl ! decls);
( lr_table::NONTERM 9
, ( result, decls1left, decl1right), rest671);
}
; ( 3, ( ( _, ( values::QQ_BINDINGLIST bindinglist, _, bindinglist1right)) ! ( _, ( _, k_term1left, _)) ! rest671)) => { my result = values::QQ_DECL (a::TERM (reverse bindinglist));
(
lr_table::NONTERM 2, ( result, k_term1left, bindinglist1right), rest671);
}
; ( 4, ( ( _, ( values::ID id, _, id1right)) ! ( _, ( _, k_start1left, _)) ! rest671)) => { my result = values::QQ_DECL (a::START id);
( lr_table::NONTERM 2, ( result, k_start1left,
id1right), rest671);
}
; ( 5, ( ( _, ( values::ID id, _, id1right)) ! ( _, ( _, k_termprefix1left, _)) ! rest671)) => { my result = values::QQ_DECL (a::TERMPREFIX id);
( lr_table::NONTERM 2, ( result,
k_termprefix1left, id1right), rest671);
}
; ( 6, ( ( _, ( values::ID id, _, id1right)) ! ( _, ( _, k_ruleprefix1left, _)) ! rest671)) => { my result = values::QQ_DECL (a::RULEPREFIX id);
( lr_table::NONTERM 2, ( result,
k_ruleprefix1left, id1right), rest671);
}
; ( 7, ( ( _, ( values::ID id, _, id1right)) ! ( _, ( _, k_sig1left, _)) ! rest671)) => { my result = values::QQ_DECL (a::BEGIN_API id);
( lr_table::NONTERM 2, ( result, k_sig1left,
id1right), rest671);
}
; ( 8, ( ( _, ( values::QQ_BINDING binding, binding1left, binding1right)) ! rest671)) => { my result = values::QQ_BINDINGLIST ([binding]);
( lr_table::NONTERM 12, ( result, binding1left,
binding1right), rest671);
}
; ( 9, ( ( _, ( values::QQ_BINDING binding, _, binding1right)) ! _ ! ( _, ( values::QQ_BINDINGLIST bindinglist, bindinglist1left, _)) ! rest671)) => { my result = values::QQ_BINDINGLIST (
binding ! bindinglist);
( lr_table::NONTERM 12, ( result, bindinglist1left, binding1right), rest671);
}
; ( 10, ( ( _, ( values::ID id, id1left, id1right)) ! rest671)) => { my result = values::QQ_BINDING ((id, NULL));
( lr_table::NONTERM 3, ( result, id1left, id1right), rest671);
}
; ( 11, ( ( _, ( values::ID id2, _, id2right)) ! _ ! ( _, ( values::ID id1, id1left, _)) ! rest671)) => { my result = values::QQ_BINDING ((id1, THE id2));
( lr_table::NONTERM 3, (
result, id1left, id2right), rest671);
}
; ( 12, ( rest671)) => { my result = values::QQ_RULES ([]);
( lr_table::NONTERM 10, ( result, default_position, default_position), rest671);
}
; ( 13, ( ( _, ( values::QQ_RULE rule, _, rule1right)) ! ( _, ( values::QQ_RULES rules, rules1left, _)) ! rest671)) => { my result = values::QQ_RULES (rule ! rules);
( lr_table::NONTERM
10, ( result, rules1left, rule1right), rest671);
}
; ( 14, ( ( _, ( _, _, k_semicolon1right)) ! ( _, ( values::QQ_COST cost, _, _)) ! ( _, ( values::QQ_RULENAME rulename, _, _)) ! _ ! ( _, ( values::QQ_PATTERN pattern, _, _)) ! _ !
( _, ( values::ID id, id1left, _)) ! rest671)) => { my result = values::QQ_RULE (a::RULE(id, pattern, rulename, cost));
( lr_table::NONTERM 11, ( result, id1left, k_semicolon1right),
rest671);
}
; ( 15, ( ( _, ( values::ID id, id1left, id1right)) ! rest671)) => { my result = values::QQ_RULENAME (id);
( lr_table::NONTERM 6, ( result, id1left, id1right), rest671);
}
; ( 16, ( ( _, ( values::ID id, id1left, id1right)) ! rest671)) => { my result = values::QQ_PATTERN (a::PAT(id, []));
( lr_table::NONTERM 7, ( result, id1left, id1right), rest671);
}
; ( 17, ( ( _, ( _, _, k_rparen1right)) ! ( _, ( values::QQ_PATTERNTAIL patterntail, _, _)) ! ( _, ( values::QQ_PATTERN pattern, _, _)) ! _ ! ( _, ( values::ID id, id1left, _)) !
rest671)) => { my result = values::QQ_PATTERN (a::PAT(id, pattern ! patterntail));
( lr_table::NONTERM 7, ( result, id1left, k_rparen1right), rest671);
}
; ( 18, ( rest671)) => { my result = values::QQ_PATTERNTAIL ([]);
( lr_table::NONTERM 8, ( result, default_position, default_position), rest671);
}
; ( 19, ( ( _, ( values::QQ_PATTERNTAIL patterntail, _, patterntail1right)) ! ( _, ( values::QQ_PATTERN pattern, _, _)) ! ( _, ( _, k_comma1left, _)) ! rest671)) => { my result =
values::QQ_PATTERNTAIL (pattern ! patterntail);
( lr_table::NONTERM 8, ( result, k_comma1left, patterntail1right), rest671);
}
; ( 20, ( rest671)) => { my result = values::QQ_COST ([]);
( lr_table::NONTERM 4, ( result, default_position, default_position), rest671);
}
; ( 21, ( ( _, ( _, _, k_rparen1right)) ! ( _, ( values::QQ_COSTTAIL costtail, _, _)) ! ( _, ( values::INT int, _, _)) ! ( _, ( _, k_lparen1left, _)) ! rest671)) => { my result =
values::QQ_COST (int ! costtail);
( lr_table::NONTERM 4, ( result, k_lparen1left, k_rparen1right), rest671);
}
; ( 22, ( rest671)) => { my result = values::QQ_COSTTAIL ([]);
( lr_table::NONTERM 5, ( result, default_position, default_position), rest671);
}
; ( 23, ( ( _, ( values::QQ_COSTTAIL costtail, _, costtail1right)) ! ( _, ( values::INT int, _, _)) ! ( _, ( _, k_comma1left, _)) ! rest671)) => { my result = values::QQ_COSTTAIL (
int ! costtail);
( lr_table::NONTERM 5, ( result, k_comma1left, costtail1right), rest671);
}
; _ => raise exception (MLY_ACTION i392);
esac;
end;
void = values::TM_VOID;
extract = \\ a = (\\ values::QQ_FULL x => x;
_ => { exception PARSE_INTERNAL;
raise exception PARSE_INTERNAL; }; end ) a ;
};
};
package tokens : (weak) Burg_Tokens {
Semantic_Value = parser_data::Semantic_Value;
Token (X,Y) = token::Token(X,Y);
fun k_eof (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 0, (parser_data::values::TM_VOID, p1, p2));
fun k_term (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 1, (parser_data::values::TM_VOID, p1, p2));
fun k_start (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 2, (parser_data::values::TM_VOID, p1, p2));
fun k_termprefix (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 3, (parser_data::values::TM_VOID, p1, p2));
fun k_ruleprefix (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 4, (parser_data::values::TM_VOID, p1, p2));
fun k_sig (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 5, (parser_data::values::TM_VOID, p1, p2));
fun k_colon (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 6, (parser_data::values::TM_VOID, p1, p2));
fun k_semicolon (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 7, (parser_data::values::TM_VOID, p1, p2));
fun k_comma (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 8, (parser_data::values::TM_VOID, p1, p2));
fun k_lparen (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 9, (parser_data::values::TM_VOID, p1, p2));
fun k_rparen (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 10, (parser_data::values::TM_VOID, p1, p2));
fun k_equal (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 11, (parser_data::values::TM_VOID, p1, p2));
fun k_pipe (p1, p2) = token::TOKEN (parser_data::lr_table::TERM 12, (parser_data::values::TM_VOID, p1, p2));
fun ppercent (i, p1, p2) = token::TOKEN (parser_data::lr_table::TERM 13, (parser_data::values::PPERCENT i, p1, p2));
fun int (i, p1, p2) = token::TOKEN (parser_data::lr_table::TERM 14, (parser_data::values::INT i, p1, p2));
fun id (i, p1, p2) = token::TOKEN (parser_data::lr_table::TERM 15, (parser_data::values::ID i, p1, p2));
fun raw (i, p1, p2) = token::TOKEN (parser_data::lr_table::TERM 16, (parser_data::values::RAW i, p1, p2));
};
};