Created
September 9, 2014 15:24
-
-
Save rns/3b2f48477fc23d0ab0f7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use 5.010; | |
use strict; | |
use warnings; | |
use Marpa::R2 2.090; # for parse() | |
my $g = Marpa::R2::Scanless::G->new( { | |
source => \(<<'END_OF_SOURCE'), | |
:default ::= action => [ name, value] | |
lexeme default = action => [ name, value] latm => 1 | |
file ::= directive+ | |
directive ::= define | if | include | |
define ::= '#define' const value | |
if ::= '#if' '(' const ')' defines else defines endif | |
else ::= '#else' comment | |
else ::= '#else' | |
endif ::= '#endif' comment | |
endif ::= '#endif' | |
include ::= '#include' '"' file_name '"' | |
defines ::= define+ | |
file_name ~ [a-zA-Z_\.0-9]+ | |
const ~ [A-Z_0-9]+ | |
value ~ non_nl [\n] | |
non_nl ~ [^\n]+ | |
comment ~ '//' non_nl [\n] | |
:discard ~ whitespace | |
whitespace ~ [\s]+ | |
END_OF_SOURCE | |
} ); | |
my $input = <<EOI; | |
#include "File_A1.h" | |
#include "File_A2.h" | |
#if (FAST_FLUSH_SUPPORT ) | |
#define MEMORY_BUDGET_FLASH_DIR (12 * 256) | |
#define MEMORY_BUDGET_FLASH_CFG (15 * 256) | |
#else //(FAST_FLUSH_SUPPORT ) | |
#define MEMORY_BUDGET_FLASH_DIR (0) | |
#define MEMORY_BUDGET_FLASH_CFG (0) | |
#endif //(FAST_FLUSH_SUPPORT ) | |
#define DRAM_OFFSET_FLASH_DIR (DUMMY_ENGR2_LOAD_ADDRESS) | |
#define DRAM_OFFSET_FLASH_CFG (DRAM_OFFSET_FLASH_DIR + MEMORY_BUDGET_FLASH_DIR) | |
#define DRAM_OFFSET_FLASH_LOG (DRAM_OFFSET_FLASH_CFG + MEMORY_BUDGET_FLASH_CFG) | |
EOI | |
use YAML; | |
say Dump ${ $g->parse( { | |
input => \$input, | |
} ) }; |
Author
rns
commented
Sep 9, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment