parrotcode: A grammar for parsing Ruby 1.8.4 | |
Contents | Language Implementations | Cardinal |
Cardinal::Grammar -- A grammar for parsing Ruby 1.8.4
.sub _main :main
load_bytecode 'CardinalGrammar.pir'
.local pmc start_rule
.local pmc match
.local string source
# Ruby 1 source code
source = 'puts 1;'
# Retrieve the start rule
start_rule = get_root_global [ 'parrot'; 'Cardinal::Grammar'], 'program'
# Parse the source and return a match object
match = start_rule(source)
... # Do something with the parse tree
end
.end
This is a grammar to parse Cardinal programs. It inherits the behavior of the PGE::Grammar class. It parses a string of source code according to its hierarchy of rules and returns a PGE::Match object (a parse tree).
Copyright (c) 2005 The Perl Foundation
This is free software; you may redistribute it and/or modify it under the same terms as Parrot.
Kevin Tew <kevintew@tewk.com>
|