diff --git a/.gitignore b/.gitignore index 3a55b65..3133a4b 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ prompt.sh prompt.txt compile_grammar.sh waddle.bnf +waddle_flattened.bnf diff --git a/grammar/core/base_types.bnf b/grammar/core/base_types.bnf index 98eacf6..727b473 100644 --- a/grammar/core/base_types.bnf +++ b/grammar/core/base_types.bnf @@ -1,12 +1,8 @@ - ::= | | | + ::= | | | | + + ::= | | ::= | | | - ::= + ::= - ::= - | - | - | "Any" - - ::= "[" ( "," )* "]" | diff --git a/grammar/core/comments.bnf b/grammar/core/comments.bnf index 2902644..7e8dbea 100644 --- a/grammar/core/comments.bnf +++ b/grammar/core/comments.bnf @@ -1,6 +1,6 @@ ::= | - ::= * + ::= * ::= ( | )* @@ -8,4 +8,5 @@ ::= | | | - ::= | | | + ::= | | | + diff --git a/grammar/core/identifiers.bnf b/grammar/core/identifiers.bnf index 8325013..1c09b07 100644 --- a/grammar/core/identifiers.bnf +++ b/grammar/core/identifiers.bnf @@ -1,4 +1,4 @@ - ::= ( | )* + ::= ( | )* ::= ("," )* @@ -14,14 +14,5 @@ ::= "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" - ::= "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "+" | "=" | "[" | "]" | "{" | "}" | "|" | "\" | ":" | ";" | "<" | ">" | "," | "." | "?" | "/" + ::= "!" | "@" | "#" | "$" | "%" | "^" | "&" | "*" | "(" | ")" | "-" | "_" | "+" | "=" | "[" | "]" | "{" | "}" | "|" | "\\" | ":" | ";" | "<" | ">" | "," | "." | "?" | "/" - ::= | | - - ::= " " | "\t" - - ::= "\n" | "\r" - - ::= * - - | )* \ No newline at end of file diff --git a/grammar/core/keywords.bnf b/grammar/core/keywords.bnf index fde281a..6852fa2 100644 --- a/grammar/core/keywords.bnf +++ b/grammar/core/keywords.bnf @@ -2,6 +2,10 @@ ::= "->" + ::= "\"" + + ::= "'" + ::= "//" ::= "/*" @@ -40,7 +44,7 @@ ::= "on_create" - ::= "on_destroy" + ::= "on_destroy" ::= "use" @@ -60,4 +64,5 @@ ::= "using" - ::= "fail" \ No newline at end of file + ::= "fail" + diff --git a/grammar/core/literals.bnf b/grammar/core/literals.bnf index 5c1d563..d1dac3e 100644 --- a/grammar/core/literals.bnf +++ b/grammar/core/literals.bnf @@ -14,16 +14,12 @@ ::= | - ::= * - ::= * + ::= * - ::= - ::= - - ::= "\"" - ::= "'" + ::= * ::= | | | + ::= | | | ::= | @@ -32,4 +28,13 @@ ::= ? - ::= ("," )* + ::= | | | + + ::= ("," )* + + ::= ("," )* + + ::= ("," )* + + ::= ("," )* + diff --git a/grammar/core/visibility.bnf b/grammar/core/visibility.bnf index 05b8afe..5d9f246 100644 --- a/grammar/core/visibility.bnf +++ b/grammar/core/visibility.bnf @@ -2,3 +2,4 @@ | | + diff --git a/grammar/core/whitespace.bnf b/grammar/core/whitespace.bnf new file mode 100644 index 0000000..4061352 --- /dev/null +++ b/grammar/core/whitespace.bnf @@ -0,0 +1,16 @@ + ::= | + + ::= " " | "\t" | "\u00A0" + + ::= "\n" | "\r" | "\u2028" | "\u2029" + + ::= * + + ::= * + + ::= + + + ::= + + + ::= + | + + diff --git a/grammar/declarations/function_declarations.bnf b/grammar/declarations/function_declarations.bnf index f601983..4a4403b 100644 --- a/grammar/declarations/function_declarations.bnf +++ b/grammar/declarations/function_declarations.bnf @@ -1,23 +1,20 @@ ::= - + - "{" - - * - - "}" + - ::= "(" ? ")" - + ::= "(" ? ")" ? - ::= ("," )* + ::= - ::= ("/" )? + ::= "[" | ( "|" )? "]" + + ::= "[" ("," )* "]" ::= ? @@ -30,17 +27,19 @@ ::= ( - | "," ) + | "," ) ::= ( | "," ) - ::= + ::= - ::= ".default(" ")" + ::= ".default(" ")" - ::= "(" ? ")" - "[" "]" - "{" * "}" + ::= "(" ? ")" + + ::= + + ::= diff --git a/grammar/declarations/type_declarations.bnf b/grammar/declarations/type_declarations.bnf index ac13062..0295a93 100644 --- a/grammar/declarations/type_declarations.bnf +++ b/grammar/declarations/type_declarations.bnf @@ -9,12 +9,13 @@ "}" ::= + (* ( | | | | - | )* + | ))* ::= ( "/")? @@ -23,8 +24,6 @@ ::= - ::= ("," )* - ::= @@ -35,13 +34,3 @@ ::= ".define(" ");" - ::= - "(" ? ")" - ( )? - "{" * "}" - - ::= - "(" ? ")" - ( )? - "{" * "}" - diff --git a/grammar/interfaces/interface_definitions.bnf b/grammar/interfaces/interface_definitions.bnf index d9a8027..7e49e96 100644 --- a/grammar/interfaces/interface_definitions.bnf +++ b/grammar/interfaces/interface_definitions.bnf @@ -12,5 +12,3 @@ ::= "[" "]" - ::= - diff --git a/grammar/main.bnf b/grammar/main.bnf index 9e4d126..e0e3b67 100644 --- a/grammar/main.bnf +++ b/grammar/main.bnf @@ -1,21 +1,22 @@ ::= * + + * * + * + ::= - - - ("." )* + + ("." )* ";" - ::= ( - | - | ) - + ::= | | import "core/keywords.bnf" import "core/comments.bnf" +import "core/whitespace.bnf" import "core/base_types.bnf" import "core/identifiers.bnf" import "core/literals.bnf" diff --git a/grammar/operations/control_flow.bnf b/grammar/operations/control_flow.bnf index d162214..9724768 100644 --- a/grammar/operations/control_flow.bnf +++ b/grammar/operations/control_flow.bnf @@ -1,15 +1,6 @@ - ::= - | - | - | - | - | - | - | - | - | - ::= + * + ( | | @@ -21,6 +12,8 @@ | | ) + * + ::= ".set(" ")" ";" @@ -30,7 +23,7 @@ ")" - "{" * "}" + ( "(" @@ -38,37 +31,35 @@ ")" - "{" - * - "}" + )? ( - "{" - * - "}" + )? - ::= "(" ")" - "{" * "}" + ::= "{" * "}" + + ::= "(" ")" ::= "(" "," "->" ("," )? ")" - "{" * "}" + ::= "(" "," "->" ("," )? ")" - "{" * "}" + ::= "(" ? ")" ";" ::= ";" ::= ".set(" ")" - "{" * "}" + ::= ".attempt" "{" * "}" - ::= ("ok" | | "error") "{" * "}" + ::= ("ok" | | "error") + + ::= "." "(" ("(" ? ")")? ")" ";" - ::= "." "(" ("(" ? ")")? ")" ";" diff --git a/grammar/operations/method_calls.bnf b/grammar/operations/method_calls.bnf index 9f93717..ebd058b 100644 --- a/grammar/operations/method_calls.bnf +++ b/grammar/operations/method_calls.bnf @@ -17,3 +17,4 @@ | ::= ("," )* + diff --git a/scripts/flatten.sh b/scripts/flatten.sh new file mode 100755 index 0000000..3518394 --- /dev/null +++ b/scripts/flatten.sh @@ -0,0 +1,59 @@ +#!/bin/bash + +# Check if input file is provided +#if [ $# -eq 0 ]; then +# echo "Usage: $0 [output_file]" +# exit 1 +#fi + +# Input and output file names +INPUT_FILE="./working/waddle.bnf" +OUTPUT_FILE="./working/waddle_flattened.bnf" + +# Flatten multi-line BNF definitions +awk ' +BEGIN { + in_definition = 0 + current_line = "" +} + +/^[[:space:]]*$/ { + # Empty line + if (in_definition) { + # Remove leading/trailing whitespace and collapse internal whitespace + gsub(/^[[:space:]]+|[[:space:]]+$/, "", current_line) + gsub(/[[:space:]]+/, " ", current_line) + print current_line + current_line = "" + in_definition = 0 + } + next +} + +/^[[:space:]]*import/ { + # Print import line as-is + print $0 + next +} + +{ + in_definition = 1 + # Append current line to definition, removing leading/trailing whitespace + if (current_line == "") { + current_line = $0 + } else { + current_line = current_line " " $0 + } +} + +END { + # Handle last definition if exists + if (in_definition) { + gsub(/^[[:space:]]+|[[:space:]]+$/, "", current_line) + gsub(/[[:space:]]+/, " ", current_line) + print current_line + } +} +' "$INPUT_FILE" > "$OUTPUT_FILE" + +echo "Flattened BNF saved to $OUTPUT_FILE" diff --git a/compiler/.gitkeep b/scripts/working/.gitkeep similarity index 100% rename from compiler/.gitkeep rename to scripts/working/.gitkeep