Added object assignments

This commit is contained in:
Dane Johnson 2021-11-25 11:31:47 -06:00
parent 29ff4cf2d8
commit 5b514a82bb
4 changed files with 41 additions and 4 deletions

31
buildup.dee Normal file
View File

@ -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

View File

@ -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 ## <undef> (or maybe it does)
print(apples) ## <undef> (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

View File

@ -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;

View File

@ -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
%%