$ param dest_dir = '.', build_system = {false} $ param basedir = $dest_dir, namespace = {translate(/parser/@package, '.', '_')} $ param libname = {translate(/parser/@package, '.', '_')} $ param incdir = $basedir + '/' + $libname $ param streambuf = 'std::streambuf' $ ecmascript // Escape a unicode string into java edible string literal function escape_string_literal(val) { var ret = ''; for ( var i = 0; i < val.length; i++ ) { if ( val.charAt(i) == '\n' ) { ret += '\\n'; } else if ( val.charAt(i) == '\r' ) { ret += '\\r'; } else if ( val.charAt(i) == '"' ) { ret += '\\"'; } else if ( val.charAt(i) == '\\' ) { ret += '\\\\'; } else if ( val.charCodeAt(i) == 0 ) { ret += '\\0'; } else if ( val.charCodeAt(i) < 0x20 || val.charCodeAt(i) > 0x7f || val.charAt(i) == '"' || val.charAt(i) == '\\') { var str = val.charCodeAt(i).toString(16); while ( str.length < 4 ) str = '0' + str; ret += '\\u' + str; } else { ret += val.charAt(i); } } return ret; } var maxnodes = 0; var maxlists = 0; var maxpops = 0; var maxargs = 0; var node2id; var nodeid; var list2id; var listid; var pop2id; var popid; var acount; var rargs = ''; var actions = ''; function get_maxnodes () { return maxnodes; } function get_maxlists () { return maxlists; } function get_maxpops () { return maxpops; } function get_maxargs () { return maxargs; } function start_rule (index) { node2id = new Array(); nodeid = 0; list2id = new Array(); listid = 0; pop2id = new Array(); popid = 0; actions += 'static reduce_command rcmd' + index + '[] = {\n'; return ''; } function end_rule () { actions += '};\n\n'; if (nodeid > maxnodes ) maxnodes = nodeid; if (listid > maxlists ) maxlists = listid; if (popid > maxpops ) maxpops = popid; return ''; } function action_pop (result) { var id = pop2id[result] = popid++; actions += ' {CMD_POP, ' + id + ', -1, -1, 0, 0},\n'; return ''; } function action_fetchnode (result, index, from) { var id = node2id[result] = nodeid++; actions += ' {CMD_FETCHNODE, ' + id + ', ' + pop2id[from] + ', ' + index + ', 0, 0},\n'; return ''; } function action_fetchlist (result, index, from) { var id = list2id[result] = listid++; actions += ' {CMD_FETCHLIST, ' + id + ', ' + pop2id[from] + ', ' + index + ', 0, 0},\n'; return ''; } function action_addnode (tolist, node) { actions += ' {CMD_ADDNODE, ' + list2id[tolist] + ', ' + node2id[node] + ', -1, 0, 0},\n'; return ''; } function action_addlist (tolist, fromlist) { actions += ' {CMD_ADDLIST, ' + list2id[tolist] + ', ' + list2id[fromlist] + ', -1, 0, 0},\n'; return ''; } function action_makelist (result) { var id = list2id[result] = listid++; actions += ' {CMD_MAKELIST, ' + id + ', -1, -1, 0, 0},\n'; return ''; } var argid = 0; function action_makenode (result, etype) { var id = node2id[result] = nodeid++; actions += ' {CMD_MAKENODE, ' + id + ', -1, -1, rargs' + argid + ', &' + etype + '::type_info},\n'; rargs += 'static int rargs' + argid + '[] = {'; acount = 0; return ''; } function action_makenode_arg (name) { var id = node2id[name]; if (typeof id == 'undefined' ) id = list2id[name]; if ( typeof id == 'undefined' ) rargs += '-1, '; else rargs += id + ', '; acount++; return ''; } function action_makenode_done () { rargs += '};\n'; argid++; if ( acount > maxargs ) maxargs = acount; return ''; } function action_returnnode (node) { if ( node != '' ) actions += ' {CMD_RETURNNODE, -1, ' + node2id[node] + ', -1, 0, 0},\n'; else actions += ' {CMD_RETURNNODE, -1, -1, -1, 0, 0},\n'; return ''; } function action_returnlist (list) { actions += ' {CMD_RETURNLIST, -1, ' + list2id[list] + ', -1, 0, 0},\n'; return ''; } function rulecode () { return rargs + '\n' + actions; } $ end ecmascript $ include 'list.xss' $ include 'node.xss' $ include 'tokens.xss' $ include 'prods.xss' $ include 'typeinfo.xss' $ include 'analysis.xss' $ include 'lexer.xss' $ include 'parser.xss' $ include 'makesystem.xss' $ include 'utils.xss' $ call make_analysis() $ call make_typeinfo() $ call make_prods() $ call make_tokens() $ call make_node() $ call make_list() $ call make_lexer() $ call make_parser() $ if $build_system $ call make_makesystem() $ call make_utils() $ end