This repository has been archived by the owner on Feb 23, 2022. It is now read-only.
forked from hedyorg/hedy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Level 20, 21 and 22 implemented (hedyorg#442)
* Level 20, 21 and 22 implemented Levels were the same as before but at a different position now
- Loading branch information
Showing
14 changed files
with
2,751 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
// trying to simply copy level 6 allowing for spaces | ||
// the idea here is: | ||
// allows for almost the same grammar as 6, easy for us | ||
// gives better error messages out of the box | ||
// we check indents in code, we can give better indent errors | ||
|
||
start: program | ||
program: _EOL* command (" ")* (_EOL+ command (" ")*)* _EOL* //lines may end on spaces and might be separated by many newlines | ||
?command: print | ||
| ifs (elifs)* elses? | ||
| input | ||
| for_loop | ||
| while_loop | ||
| assign_list | ||
| list_access_var | ||
| change_list_item | ||
| comment | ||
| assign //placing it here means print is will print 'is' and print is Felienne will print 'is Felienne' | ||
|
||
//we had to drop invalid, I think because of the if-ifelse, but for now it is pretty ok!! | ||
|
||
_EOL: "\r"?"\n" | ||
|
||
|
||
print : "print(" (quoted_text | list_access | var | sum | length) (" " (quoted_text | list_access | var | sum | length))* ")" | ||
input : var " = input(" (quoted_text | list_access | var | sum | length) (" " (quoted_text | list_access | var | sum | length))* ")" | ||
assign_list: var " = [" quoted_text ((", "|",") quoted_text)+ "]" | ||
|
||
//TODO: sum needs to be expression here too (like in 7 and up) | ||
|
||
assign : var " = " length | var " = " sum | var " = " textwithoutspaces | list_access " = " sum | list_access " = " textwithoutspaces | ||
invalid: textwithoutspaces " " textwithspaces | ||
|
||
|
||
// new commands for level 4 | ||
elses : _EOL (" ")* "else"":" _EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block" | ||
ifs: "if " (condition|andcondition|orcondition) ":" _EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block" //'if' cannot be used in Python, hence the name of the rule is 'ifs' | ||
elifs: _EOL (" ")* "elif " (condition|andcondition|orcondition) ":"_EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block" | ||
|
||
|
||
condition: (equality_check|in_list_check|smaller|bigger) | ||
list_access_var : var " = " var "[" (index | random | var) "]" | ||
equality_check: (length | textwithoutspaces | list_access | sum) " == " (length | textwithoutspaces | list_access | sum) | ||
in_list_check: textwithoutspaces " in " var | ||
|
||
//new for level 6 | ||
?sum: product | ||
| sum " "* "+" " "* product -> addition | ||
| sum " "* "-" " "* product -> substraction | ||
|
||
?product: atom | ||
| product " "* "*" " "* atom -> multiplication | ||
| product " "* "/" " "* atom -> division | ||
|
||
?atom: NUMBER | var | NAME | list_access //TODO: means we cannot assign strings with spaces? would we want that? | ||
|
||
//new for level 8 | ||
for_loop: "for " (NAME | var) " in " "range(" (NUMBER | var | length)(", "|",") (NUMBER | var | length) "):" _EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block" | ||
|
||
//new for level 12, assignment of list[i] | ||
change_list_item : var "[" (index | var) "] = " (var | textwithoutspaces) | ||
|
||
//new for level 14 | ||
andcondition: (equality_check|in_list_check) (" and " condition)* | ||
orcondition: (equality_check|in_list_check) (" or " condition)* | ||
|
||
//new for level 15 | ||
comment: "#" (textwithspaces)* | ||
|
||
//new for level 16 | ||
smaller: (textwithoutspaces | list_access | length) " < " (textwithoutspaces | list_access | length) | ||
bigger: (textwithoutspaces | list_access | length) " > " (textwithoutspaces | list_access | length) | ||
|
||
//new for level 17 | ||
while_loop: "while " (condition|andcondition|orcondition) ":" _EOL (" "+ command) (_EOL " "+ command)* _EOL "end-block" | ||
|
||
//new for level 19 | ||
length: "length(" var ")" | ||
|
||
var: NAME -> var | ||
list_access : var "[" (index | random | var | length) "]" | ||
index : NUMBER | ||
random : "random" | ||
|
||
textwithspaces: /([^\n,]+)/ -> text //anything can be parsed except for a newline and a comma for list separators | ||
textwithoutspaces: /([^\n, :*+-\/]+)/ -> text //anything can be parsed except for spaces (plus: a newline and a comma for list separators) | ||
//plus in level 6, calculation elements | ||
//plus in level 8, colon | ||
|
||
quoted_text_no_escape: /'([^']*)'/ -> text //simply all between quotes should this be used at earlier levels? | ||
quoted_text: /'((?:[^\\']|\\.)*)'/ -> text //text can be between single quotes, but quotes may be escaped with \ | ||
|
||
%import common.LETTER // imports from terminal library | ||
%import common.DIGIT // imports from terminal library | ||
%import common.WS_INLINE // imports from terminal library | ||
%import common.NEWLINE // imports from terminal library | ||
%import common.SIGNED_INT -> NUMBER | ||
%import common.CNAME -> NAME |
Oops, something went wrong.