From 5b514a82bb76ddfc66ab97157764f6113f1a117b Mon Sep 17 00:00:00 2001 From: Dane Johnson Date: Thu, 25 Nov 2021 11:31:47 -0600 Subject: [PATCH] Added object assignments --- buildup.dee | 31 +++++++++++++++++++++++++++++++ example.dee | 6 +++--- lexer.l | 2 +- parser.y | 6 ++++++ 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 buildup.dee diff --git a/buildup.dee b/buildup.dee new file mode 100644 index 0000000..16f3d39 --- /dev/null +++ b/buildup.dee @@ -0,0 +1,31 @@ +## Comments +apple <- 1 ## assignments +pear() ## function calls +pear(x, y) ## function calls with arguments +apple <- pear(x, y) + z ## compound assignments +foo <- -> bar() ## function definitions +foo <- -> + bar() + baz() +## functions with block statements +foo <- x -> y -> x * y + 7 ## Multiple argument functions +if test?() + do-something() +elif other-test?() + do-something-else() +else + a <- 4 +## Block conditionals + +if test?() + do-nothing() +else + if second-test?() + do-a-real-bad-thing() +## Nested blocks + +obj <- { + field <- "hello" + method <- x -> x * 2 +} +## Object creation \ No newline at end of file diff --git a/example.dee b/example.dee index 9c86291..45a58f7 100644 --- a/example.dee +++ b/example.dee @@ -12,12 +12,12 @@ want <- 11 need <- have - want ## This is subtraction have-want <- 1 ## This is a variable named "have-want" -print HaVe-WAnt ## 1 (case doesn't matter) +print(HaVe-WAnt) ## 1 (case doesn't matter) %%option meaningful-casing Apples <- 1 -print apples ## (or maybe it does) +print(apples) ## (or maybe it does) -print("one fish"); print("two fish") ## Two variables on the same line +print("one fish"); print("two fish") ## Two statements on the same line say-hi <- -> print("Hi from inside a function") say-hi() ## Hi from inside a function diff --git a/lexer.l b/lexer.l index 7801203..bb0447a 100644 --- a/lexer.l +++ b/lexer.l @@ -42,7 +42,7 @@ elif return ELIF; {letter}({letter}|{digit}|[?-])* yylval.sym = yytext; return ID; "<-" return GETS; "->" return MAPS; -[().,*/+-] return yytext[0]; +[(){}.,*/+-] return yytext[0]; [\t ] // Eat whitespace not first on a line "/"\n // Eat newlines ending in / [\n;] BEGIN(freshline); return STOP; diff --git a/parser.y b/parser.y index f00d78b..09df882 100644 --- a/parser.y +++ b/parser.y @@ -30,8 +30,10 @@ statements: statements statement STOP | // null production ; statement: assignment | funcall | conditional; assignment: ID GETS expr; +assignments: assignments assignment STOP | // null production; expr: funcdef | funcall + | objdef | expr '+' expr | expr '-' expr | expr '*' expr @@ -41,6 +43,7 @@ expr: funcdef funcdef: param MAPS expr | param MAPS block; param: ID | '_' | // null production; + funcall: ID '(' exprlist ')' exprlist: exprlist ',' expr | expr | // null production; @@ -48,5 +51,8 @@ conditional: IF expr block elifs | IF expr block elifs ELSE block; elifs: ELIF expr block elifs| // null production; +objdef: '{' block_assignments '}' | '{' '}' + block: STOP INDENT statement statements DEDENT +block_assignments: STOP INDENT assignments DEDENT %% \ No newline at end of file