Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use strict;
- use warnings;
- use Data::Printer;
- use Regexp::Grammars;
- {
- my $parser = qr {
- <nocontext:>
- <debug: off>
- <C>
- <rule: C> <FunctionWithoutParams>
- <rule: FunctionWithoutParams> <ReturnType> <FunctionName> \(\) <CodeBlock>
- <token: ReturnType> \w+
- <token: FunctionName> \w+
- <rule: CodeBlock> \{ <Blocks> \}
- <rule: Blocks> <[Block]>+
- <rule: Block> <IF> | <Statement>
- <rule: IF> if \( <BoolExpr> \) <CodeBlock>
- <token: BoolExpr> .*?
- <token: Statement> .*?;
- }xms;
- my $data = '
- void func() {
- int x = 10;
- if( x == 10 ) {
- printf("print statement");
- int y = 20;
- if( y == 20 ) {
- printf("y equals twenty");
- }
- }
- }';
- if ($data =~ $parser) {
- my %res = %/;
- p \%res;
- #print Dumper \%res;
- }
- else {
- warn "No match";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement