Compiler/lexical analyzer: Difference between revisions

Content deleted Content added
Thundergnat (talk | contribs)
→‎{{header|Perl 6}}: avoid unnecessary reparsing
Thundergnat (talk | contribs)
m →‎{{header|Perl 6}}: minor cleanup
Line 1,497: Line 1,497:
This is more complicated than strictly necessary for this task. It is set up to be easily adapted to do syntax analysis.
This is more complicated than strictly necessary for this task. It is set up to be easily adapted to do syntax analysis.


(Note: there are several bogus comments added strictly to help with syntax highlighting.)
(Note: there are several bogus comments added solely to help with syntax highlighting.)


{{works with|Rakudo|2016.08}}
{{works with|Rakudo|2016.08}}
Line 1,577: Line 1,577:
my $l;
my $l;
my @pos = gather for $c_code.lines».chars.kv -> $line, $v {
my @pos = gather for $c_code.lines».chars.kv -> $line, $v {
take [ $line + 1, $_ ] for 1 .. ($v+1); # v for newline
take [ $line + 1, $_ ] for 1 .. ($v+1); # v+1 for newline
$l = $line+2;
$l = $line+2;
}
}
Line 1,583: Line 1,583:


for flat $c_code<tokens>.list, $c_code<eoi> -> $m {
for flat $c_code<tokens>.list, $c_code<eoi> -> $m {
say join "\t", @pos[$m.from].fmt('%3d'), $m.ast; ;
say join "\t", @pos[$m.from].fmt('%3d'), $m.ast;
}
}
}
}