From ed39b6aeaaf325d73c229bfcd665335cb237bc6f Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 17 Dec 2024 13:41:52 +0100 Subject: 2024-03 part 2 in factor using an EBNF parser this time --- 2024/03-Mull_It_Over/03.factor | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to '2024/03-Mull_It_Over') diff --git a/2024/03-Mull_It_Over/03.factor b/2024/03-Mull_It_Over/03.factor index c585923..d8a734e 100644 --- a/2024/03-Mull_It_Over/03.factor +++ b/2024/03-Mull_It_Over/03.factor @@ -1,7 +1,7 @@ ! Copyright (C) 2024 Julien (adyxax) Dessaux. ! See https://git.adyxax.org/adyxax/advent-of-code/tree/LICENSE for EUPL license. -USING: accessors io.encodings.utf8 io.files kernel make math math.parser peg -peg.parsers prettyprint regexp sequences ; +USING: accessors io.encodings.utf8 io.files kernel make math math.parser +multiline peg peg.ebnf peg.parsers prettyprint regexp sequences ; IN: aoc.2024.03 > ; +! ----- part2 again with an EBNF parser this time ------------------------------ + +EBNF: parse_grammar [=[ + number=[0-9]+ => [[ string>number ]] + mul = "mul("~ number:a ","~ number:b ")"~ => [[ a b mul boa ]] + dontblock = "don't()" (!("do()") .)* "do()" => [[ nop boa ]] + ignore = .~ => [[ nop boa ]] + program=(dontblock|mul|ignore)+ +]=] + +: part2bis ( filename -- n ) + load_input + parse_grammar + 0 t computer boa + swap + [ compute ] each + total>> ; + PRIVATE> : aoc202403 ( -- ) "input" part1 . - "input" part2 . ; + "input" part2 . + "input" part2bis . ; MAIN: aoc202403 -- cgit v1.2.3