From 2a8260dac5ac78d41ab2f8aeadb69045583b318d Mon Sep 17 00:00:00 2001 From: jgjanes Date: Thu, 28 Apr 2022 21:43:57 -0700 Subject: [PATCH] Updated Grammar to match to current parser Co-Authored-By: Joseph Hale <47901316+jhale1805@users.noreply.github.com> Co-Authored-By: Sai Nishanth Vaka Co-Authored-By: Rithvik Arun <43283635+rarun321@users.noreply.github.com> --- doc/grammar.md | 64 ++++++++++++++++++++------------------------------ 1 file changed, 26 insertions(+), 38 deletions(-) diff --git a/doc/grammar.md b/doc/grammar.md index a9452dc..b54e12e 100644 --- a/doc/grammar.md +++ b/doc/grammar.md @@ -1,30 +1,31 @@ // Initial Definitions -`identifier` := \w+(-\w+)* -`identifier_answer` := answer -`identifier_answer` := no-answer +`identifier` := \w+ +`command` := `comment` +`command` := `assignment` +`command` := `loop` +`command` := `show` +`command` := `selection` +`command` := `command` `command` + +`program` := `command` -`block` := `assignment` \n -`block` := `assignment` \n `block` -`block` := `print_statement` \n -`block` := `print_statement` \n `block` // Requirement 1a `boolean` := true `boolean` := false -`expression_boolean` := `expression_boolean` and `expression_boolean` -`expression_boolean` := `expression_boolean` or `expression_boolean` -`expression_boolean` := not `expression_boolean` +`boolean` := not `boolean` +`boolean` := `expression` and `expression` +`boolean` := `expression` or `expression` +`boolean` := `expression` is_greater_than `expression` +`boolean` := `expression` is_less_than `expression` +`boolean` := `expression` equals `expression` // Requirement 1b `number` := [0-9]+(\.[0-9]+)? `expression` := `number` -`expression` := `boolean` -`expression` := `string` `expression` := `identifier` -`expression` := `ternary` -`expression` := `function_call` `expression` := `expression` plus `expression` `expression` := `expression` minus `expression` `expression` := `expression` times `expression` @@ -37,42 +38,29 @@ // Requirement 2 `assignment` := `identifier` stores `expression` -`assignment_answer` := `identifier_answer` stores `expression` +`assignment` := `identifier` stores `string` +`assignment` := `identifier` stores `ternary` // Requirement 3a -`ternary` := `expression` if `expression_boolean` otherwise `expression` +`ternary` := `expression` if `boolean` otherwise `expression` // Requirement 3b -`if_statement` := if `expression_boolean` \n `block` \n move-on -`if_statement` := if `expression_boolean` \n `block` \n otherwise \n `block` \n move-on -`if_statement` := if `expression_boolean` \n `block` \n otherwise `if_statement` \n move-on +`if_statement` := if `boolean` `command` move-on +`if_statement` := if `boolean` `command` otherwise `command` move-on // Requirement 4a -`loop_for` := for `identifier` from `identifer` \n `block` \n repeat +`loop_for` := for `identifier` from `expression` to `expression` by `expression` `command` repeat // Requirement 4b -`loop_while` := while `expression_boolean` \n `block` \n repeat +`loop_while` := while `boolean` `command` repeat // Requirement 4c -// TODO - I'm thinking that "range(2,5)" could be a function that returns an iterable collection. That's how Python does it... +`loop_for` := for `identifier` from `expression` to `expression` `command` repeat // Requirement 5 -`print_statement` := show `identifier` - -// Other Features: Functions -`argument` := `identifier` -`argument_list` := `argument` -`argument_list` := `argument` with `argument_list` - -`function_definition` := `identifier` needs `argument_list` \n `block` \n `assignment_answer` \n - -`function_call` := `identifier` of `argument_list` +`print` := show `string` +`print` := show `number` +`print` := show `identifier` // Other Features: Comments `comment` := fyi `string` \n - -// Comparison Operators -`greater_than` := `expression` is-greater-than `expression` -`less_than` := `expression` is-less-than `expression` -`equal-to` := `expression` is-equal-to `expression` - -- knotmirror 0.0.1