NAME MarpaX::Languages::C::AST - Translate a C source to an AST VERSION version 0.04 SYNOPSIS use strict; use warnings FATAL => 'all'; use MarpaX::Languages::C::AST; use Log::Log4perl qw/:easy/; use Log::Any::Adapter; use Log::Any qw/$log/; use Data::Dumper; # # Init log # our $defaultLog4perlConf = ' log4perl.rootLogger = WARN, Screen log4perl.appender.Screen = Log::Log4perl::Appender::Screen log4perl.appender.Screen.stderr = 0 log4perl.appender.Screen.layout = PatternLayout log4perl.appender.Screen.layout.ConversionPattern = %d %-5p %6P %m{chomp}%n '; Log::Log4perl::init(\$defaultLog4perlConf); Log::Any::Adapter->set('Log4perl'); # # Parse C # my $cSourceCode = ' typedef struct s1_ {int i1;} x1, y1; struct x1 {x1 i2;}; x1 x; '; my $cAstObject = MarpaX::Languages::C::AST->new(); print Dumper($cAstObject->parse(\$cSourceCode)); DESCRIPTION This modules translates a C source into an AST tree. The AST consist of blessed objects that map exactly to the C grammar in use. If you want to enable logging, be aware that this module is a Log::Any thingy. Please note that this module just *translates* a C source, it does *not* check for its correctness, i.e. the numerous grammar constraints built on top on the C grammar are not implemented, for example constraint on the number of storage class specifiers, uniqueness of labeled statements within a function, etc.. This is left to a compiler, which is not the goal here. So, to state things clearly, this module is adressing the *ambiguities* of the grammar itself, i.e. the dangling else, the typedef/enum/identifier. And produces an AST of the parse tree value. SUBROUTINES/METHODS new($class, $grammarName) Instanciate a new object. Takes as parameter an optional base name of a grammar. Default is 'ISO-ANSI-C-2011'. parse($self, $referenceToSourceCodep, $optionalArrayOfValuesb) Do the parsing and return the blessed value. Takes as first parameter the reference to a C source code. Takes as optional second parameter a flag saying if the return value should be an array of all values or not. If this flag is false, the module will croak if there more than one parse tree value. AUTHOR Jean-Damien Durand COPYRIGHT AND LICENSE This software is copyright (c) 2013 by Jean-Damien Durand. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.