diff --git a/README.md b/README.md new file mode 100644 index 0000000..4dc3d15 --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# PLTHY +The programming language that hates you. \ No newline at end of file diff --git a/documentation/plthy.pdf b/documentation/plthy.pdf index e71e68b..2b51666 100644 Binary files a/documentation/plthy.pdf and b/documentation/plthy.pdf differ diff --git a/documentation/plthy.tex b/documentation/plthy.tex index c93611a..1d59838 100644 --- a/documentation/plthy.tex +++ b/documentation/plthy.tex @@ -21,7 +21,7 @@ \textit{statement} & $\rightarrow$ & \textit{statement} \texttt{if} \textit{expression} \\ \hline \textit{statement} & $\rightarrow$ & \textit{statement} \texttt{because} \textit{expression} \\ \hline \textit{statement} & $\rightarrow$ & \texttt{until} \textit{expression} \textit{statement} \\ \hline - \textit{statement} & $\rightarrow$ & \textit{expression} \texttt{->} \textbf{id} \\ \hline + \textit{statement} & $\rightarrow$ & \texttt{set} \textit{expression} \texttt{->} \textbf{id} \\ \hline \textit{statement} & $\rightarrow$ & \texttt{define} \textbf{function} \texttt{<} \textbf{int} \texttt{>} \texttt{as} \textit{statement} \\ \hline \textit{statement} & $\rightarrow$ & \texttt{return} \textit{expression} \\ \hline\hline \textit{command} & $\rightarrow$ & \textbf{builtin} \texttt{<} \textit{expressions} \texttt{>} \\ \hline diff --git a/plthy_impl/ast_nodes.py b/plthy_impl/ast_nodes.py index cbfa3d7..62abba8 100644 --- a/plthy_impl/ast_nodes.py +++ b/plthy_impl/ast_nodes.py @@ -50,7 +50,7 @@ class ExpVariable(Exp): self.variable_name = variable_id def __repr__(self) -> str: - return f"exp_variable({self.variable_name})" + return f"variable({self.variable_name})" def eval(self, vtable, ftable): return vtable, ftable, vtable[self.variable_name] @@ -369,7 +369,7 @@ class Program(BaseBox): def __init__(self, statements: list[Statement]) -> None: self.statements = statements random.seed(str(self)) - r = random.randint(1,20) + r = random.randint(1,10) if r == 1: print("E004: Random compiler error") exit() diff --git a/plthy_impl/lexer.py b/plthy_impl/lexer.py index d8bdd38..16c17b9 100644 --- a/plthy_impl/lexer.py +++ b/plthy_impl/lexer.py @@ -32,7 +32,10 @@ DATA_TOKENS = [ ] SYMBOL_TOKENS = [ + ("SYMBOL_OR", r"\\\/"), + ("SYMBOL_AND", r"\/\\"), ("SYMBOL_SET", r"\-\>"), + ("SYMBOL_TILDE", r"\~"), # ("SYMBOL_LPARENS", r"\("), # ("SYMBOL_RPARENS", r"\)"), ("SYMBOL_LBRACKET", r"\["), diff --git a/plthy_impl/parser.py b/plthy_impl/parser.py index c48ef8f..a5f6cc2 100644 --- a/plthy_impl/parser.py +++ b/plthy_impl/parser.py @@ -11,9 +11,9 @@ class Parser(): ('left', ["KEYWORD_MAYBE", "KEYWORD_RETURN"]), ('left', ["KEYWORD_IF", "KEYWORD_BECAUSE", "KEYWORD_UNTIL", "KEYWORD_DEFINE", "KEYWORD_AS"]), ('left', ["KEYWORD_DO", "BUILTIN", "SYMBOL_SET"]), - ('left', ["SYMBOL_EQUALS"]), - ('left', ["SYMBOL_PLUS", "SYMBOL_MINUS"]), - ('left', ["SYMBOL_TIMES", "SYMBOL_DIVIDE", "SYMBOL_LT","SYMBOL_GT"]) + ('left', ["SYMBOL_EQUALS", "SYMBOL_LT","SYMBOL_GT"]), + ('left', ["SYMBOL_PLUS", "SYMBOL_MINUS", "SYMBOL_OR", "SYMBOL_AND"]), + ('left', ["SYMBOL_TIMES", "SYMBOL_DIVIDE", "SYMBOL_TILDE"]) ] ) @@ -118,6 +118,15 @@ class Parser(): def exp_a_binop(tokens): return ast_nodes.ExpABinop(tokens[1].value,tokens[0],tokens[2]) + @self.pg.production('expression : expression SYMBOL_OR expression') + @self.pg.production('expression : expression SYMBOL_AND expression') + def exp_b_binop(tokens): + pass + + @self.pg.production('expression : SYMBOL_TILDE expression') + def exp_not(tokens): + pass + @self.pg.production('expression : KEYWORD_ARGUMENT ARG') def exp_arg(tokens): return ast_nodes.ExpArg(int(tokens[1].value[1:])) diff --git a/tests/02_variable.plthy b/tests/02_variable.plthy index fb6fe5b..7e546fe 100644 --- a/tests/02_variable.plthy +++ b/tests/02_variable.plthy @@ -1,4 +1,4 @@ hello| -set 2 -> x| -do print| +set 2 -> z| +do print| goodbye| \ No newline at end of file diff --git a/tests/08_precedence.expected b/tests/08_precedence.expected index b7dfd93..a326b49 100644 --- a/tests/08_precedence.expected +++ b/tests/08_precedence.expected @@ -1,3 +1,4 @@ 7 5 5 6 +15 diff --git a/tests/08_precedence.plthy b/tests/08_precedence.plthy index 1fb801c..d700bc2 100644 --- a/tests/08_precedence.plthy +++ b/tests/08_precedence.plthy @@ -5,4 +5,7 @@ set 5 -> y if variable x = 7| do print| set set 5 -> z + 1 -> a| do print| +set 15 -> x if variable x+3>2*2+5| +set 1 -> x if variable x+3<2*2+5| +do print| goodbye| \ No newline at end of file diff --git a/tests/16_E004.expected b/tests/16_E004.expected new file mode 100644 index 0000000..9032d21 --- /dev/null +++ b/tests/16_E004.expected @@ -0,0 +1 @@ +E004: Random compiler error diff --git a/tests/16_E004.plthy b/tests/16_E004.plthy new file mode 100644 index 0000000..fb6fe5b --- /dev/null +++ b/tests/16_E004.plthy @@ -0,0 +1,4 @@ +hello| +set 2 -> x| +do print| +goodbye| \ No newline at end of file