Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
137 lines (97 sloc) 2.76 KB
# Copyright (C) 2006-2009, Parrot Foundation.
# $Id$
=head1 a grammar for testing lexico
=head2 Description
Just emits code that prints terminal nodes.
Used by F<languages/lua/test_lex.pir>.
=cut
grammar Lua::DumpLex is TGE::Grammar;
=head3 Functions
=over 4
=item C<transform past (ROOT)>
=cut
transform past (ROOT) :language('PIR') {
.local pmc past
$P0 = get_hll_global ['PAST'], 'Stmts'
past = $P0.'new'('node'=>node)
$P0 = node['token']
if null $P0 goto L1
.local pmc it
it = iter $P0
L2:
unless it goto L1
$P0 = shift it
$P1 = tree.'get'('past', $P0, 'Lua::TestLex::token')
past.'push'($P1)
goto L2
L1:
$P0 = get_hll_global ['PAST'], 'Block'
.tailcall $P0.'new'(past, 'node'=>node, 'name'=>'anon')
}
=item C<transform past (Lua::TestLex::token)>
=cut
transform past (Lua::TestLex::token) :language('PIR') {
.local pmc past
$S0 = node.'find_key'()
$P0 = node[$S0]
$S1 = concat 'Lua::TestLex::', $S0
past = tree.'get'('past', $P0, $S1)
$P0 = get_hll_global ['PAST'], 'Op'
.tailcall $P0.'new'(past, 'node'=>node, 'name'=>'println', 'pasttype'=>'call')
}
=item C<transform past (Lua::TestLex::keyword)>
=cut
transform past (Lua::TestLex::keyword) :language('PIR') {
$S0 = node.'ast'()
$S1 = concat "keyword:\t", $S0
$P0 = get_hll_global ['PAST'], 'Val'
.tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}
=item C<transform past (Lua::TestLex::punctuator)>
=cut
transform past (Lua::TestLex::punctuator) :language('PIR') {
$S0 = node.'ast'()
$S1 = concat "punct:\t", $S0
$P0 = get_hll_global ['PAST'], 'Val'
.tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}
=item C<transform past (Lua::TestLex::Name)>
=cut
transform past (Lua::TestLex::Name) :language('PIR') {
$S0 = node.'ast'()
$S1 = concat "Name:\t", $S0
$P0 = get_hll_global ['PAST'], 'Val'
.tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}
=item C<transform past (Lua::TestLex::String)>
=cut
transform past (Lua::TestLex::String) :language('PIR') {
$I0 = defined node['quoted_literal']
unless $I0 goto L1
$P0 = node['quoted_literal']
$S0 = $P0.'ast'()
$S1 = concat "String:\t", $S0
goto L9
L1:
$I0 = defined node['long_string']
unless $I0 goto L2
$P0 = node['long_string']
$S0 = $P0.'ast'()
$S1 = concat "LongString:\t", $S0
goto L9
L2:
internal_error('unknown string')
L9:
$P0 = get_hll_global ['PAST'], 'Val'
.tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}
=item C<transform past (Lua::TestLex::Number)>
=cut
transform past (Lua::TestLex::Number) :language('PIR') {
$S0 = node.'ast'()
$S1 = concat "Number:\t", $S0
$P0 = get_hll_global ['PAST'], 'Val'
.tailcall $P0.'new'('node'=>node, 'value'=>$S1)
}
=back
=cut