diff options
Diffstat (limited to 'js/scripting-lang/grammar_detailed.ebnf')
-rw-r--r-- | js/scripting-lang/grammar_detailed.ebnf | 97 |
1 files changed, 0 insertions, 97 deletions
diff --git a/js/scripting-lang/grammar_detailed.ebnf b/js/scripting-lang/grammar_detailed.ebnf deleted file mode 100644 index 5274cd8..0000000 --- a/js/scripting-lang/grammar_detailed.ebnf +++ /dev/null @@ -1,97 +0,0 @@ -(* Detailed Scripting Language Grammar *) - -(* Program Structure *) -program = statement_list -statement_list = statement { statement } -statement = assignment | function_declaration | expression_statement | io_statement | ";" - -(* Variables and Assignment *) -assignment = identifier ":" assignment_value -assignment_value = function_call | simple_expression - -(* Function Declarations *) -function_declaration = identifier ":" parameter_list "->" function_body -parameter_list = identifier { identifier } -function_body = arithmetic_expression | case_expression - -(* Function Calls *) -function_call = identifier argument_list -argument_list = expression { expression } - -(* Expressions *) -expression = arithmetic_expression | simple_expression -simple_expression = identifier | number | string -expression_statement = expression - -(* Arithmetic Expressions - Prefix Notation *) -arithmetic_expression = arithmetic_operator expression expression -arithmetic_operator = "+" | "-" | "*" | "/" - -(* Case Expressions *) -case_expression = "case" value_list "of" case_list -value_list = expression { expression } -case_list = case_branch { case_branch } -case_branch = pattern ":" result -pattern = pattern_element { pattern_element } -pattern_element = number | wildcard | identifier -result = result_element { result_element } -result_element = string | number | identifier - -(* IO Statements *) -io_statement = io_operator [ expression ] -io_operator = "..in" | "..out" - -(* Terminals *) -identifier = letter { letter | digit } -number = digit { digit } -string = '"' { character } '"' -wildcard = "_" -letter = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z" | "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" | "W" | "X" | "Y" | "Z" -digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" -character = letter | digit | " " | "!" | "#" | "$" | "%" | "&" | "'" | "(" | ")" | "*" | "+" | "," | "-" | "." | "/" | ":" | ";" | "<" | "=" | ">" | "?" | "@" | "[" | "\" | "]" | "^" | "`" | "{" | "|" | "}" | "~" - -(* Parsing Precedence and Disambiguation *) - -(* Key Insights from Debug Analysis: *) - -(* 1. Assignment parsing needs to distinguish between function calls and simple values *) -(* assignment_value = function_call | simple_expression *) - -(* 2. Function calls in assignments: "result : add 3 4;" *) -(* - "add" is an identifier *) -(* - "3" and "4" are arguments *) -(* - Should parse as: assignment(identifier("result"), function_call("add", [3, 4])) *) - -(* 3. Case expressions work correctly but function calls within them don't *) -(* - Case patterns: "0 0", "0 _", "_ 0", "_ _" *) -(* - Case results: string literals, numbers, identifiers *) - -(* 4. Arithmetic expressions use prefix notation *) -(* - "+ x y" not "x + y" *) -(* - "* 5 2" not "5 * 2" *) - -(* 5. IO statements are special *) -(* - "..in" reads from stdin *) -(* - "..out expression" writes to stdout *) - -(* Examples with Parse Trees *) - -(* Example 1: Simple assignment *) -(* Input: "x : 5;" *) -(* Parse: assignment(identifier("x"), number(5)) *) - -(* Example 2: Function call assignment *) -(* Input: "result : add 3 4;" *) -(* Parse: assignment(identifier("result"), function_call("add", [number(3), number(4)])) *) - -(* Example 3: Case expression *) -(* Input: "compare : x y -> case x y of 0 0 : \"both zero\";" *) -(* Parse: function_declaration("compare", ["x", "y"], case_expression([identifier("x"), identifier("y")], [case_branch([number(0), number(0)], [string("both zero")])])) *) - -(* Example 4: Arithmetic expression *) -(* Input: "sum : + x y;" *) -(* Parse: assignment(identifier("sum"), arithmetic_expression("+", identifier("x"), identifier("y"))) *) - -(* Example 5: IO statement *) -(* Input: "..out \"Hello\";" *) -(* Parse: io_statement("..out", string("Hello")) *) \ No newline at end of file |