aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2024-12-17 13:41:52 +0100
committerJulien Dessaux2024-12-17 13:41:52 +0100
commited39b6aeaaf325d73c229bfcd665335cb237bc6f (patch)
tree2252c30a17eb17156f3b40ff5cc30b85108a1ade
parent2024-13 in haskell (diff)
downloadadvent-of-code-ed39b6aeaaf325d73c229bfcd665335cb237bc6f.tar.gz
advent-of-code-ed39b6aeaaf325d73c229bfcd665335cb237bc6f.tar.bz2
advent-of-code-ed39b6aeaaf325d73c229bfcd665335cb237bc6f.zip
2024-03 part 2 in factor using an EBNF parser this time
-rw-r--r--2024/03-Mull_It_Over/03.factor25
1 files changed, 22 insertions, 3 deletions
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
<PRIVATE
@@ -85,10 +85,29 @@ PEG: parse_input ( string -- ast )
[ compute ] each
total>> ;
+! ----- 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