Added object assignments
This commit is contained in:
parent
29ff4cf2d8
commit
5b514a82bb
31
buildup.dee
Normal file
31
buildup.dee
Normal 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
|
@ -12,12 +12,12 @@ want <- 11
|
|||||||
need <- have - want ## This is subtraction
|
need <- have - want ## This is subtraction
|
||||||
have-want <- 1 ## This is a variable named "have-want"
|
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
|
%%option meaningful-casing
|
||||||
Apples <- 1
|
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 <- -> print("Hi from inside a function")
|
||||||
say-hi() ## Hi from inside a function
|
say-hi() ## Hi from inside a function
|
||||||
|
2
lexer.l
2
lexer.l
@ -42,7 +42,7 @@ elif return ELIF;
|
|||||||
{letter}({letter}|{digit}|[?-])* yylval.sym = yytext; return ID;
|
{letter}({letter}|{digit}|[?-])* yylval.sym = yytext; return ID;
|
||||||
"<-" return GETS;
|
"<-" return GETS;
|
||||||
"->" return MAPS;
|
"->" return MAPS;
|
||||||
[().,*/+-] return yytext[0];
|
[(){}.,*/+-] return yytext[0];
|
||||||
[\t ] // Eat whitespace not first on a line
|
[\t ] // Eat whitespace not first on a line
|
||||||
"/"\n // Eat newlines ending in /
|
"/"\n // Eat newlines ending in /
|
||||||
[\n;] BEGIN(freshline); return STOP;
|
[\n;] BEGIN(freshline); return STOP;
|
||||||
|
6
parser.y
6
parser.y
@ -30,8 +30,10 @@ statements: statements statement STOP
|
|||||||
| // null production ;
|
| // null production ;
|
||||||
statement: assignment | funcall | conditional;
|
statement: assignment | funcall | conditional;
|
||||||
assignment: ID GETS expr;
|
assignment: ID GETS expr;
|
||||||
|
assignments: assignments assignment STOP | // null production;
|
||||||
expr: funcdef
|
expr: funcdef
|
||||||
| funcall
|
| funcall
|
||||||
|
| objdef
|
||||||
| expr '+' expr
|
| expr '+' expr
|
||||||
| expr '-' expr
|
| expr '-' expr
|
||||||
| expr '*' expr
|
| expr '*' expr
|
||||||
@ -41,6 +43,7 @@ expr: funcdef
|
|||||||
|
|
||||||
funcdef: param MAPS expr | param MAPS block;
|
funcdef: param MAPS expr | param MAPS block;
|
||||||
param: ID | '_' | // null production;
|
param: ID | '_' | // null production;
|
||||||
|
|
||||||
funcall: ID '(' exprlist ')'
|
funcall: ID '(' exprlist ')'
|
||||||
exprlist: exprlist ',' expr | expr | // null production;
|
exprlist: exprlist ',' expr | expr | // null production;
|
||||||
|
|
||||||
@ -48,5 +51,8 @@ conditional: IF expr block elifs
|
|||||||
| IF expr block elifs ELSE block;
|
| IF expr block elifs ELSE block;
|
||||||
elifs: ELIF expr block elifs| // null production;
|
elifs: ELIF expr block elifs| // null production;
|
||||||
|
|
||||||
|
objdef: '{' block_assignments '}' | '{' '}'
|
||||||
|
|
||||||
block: STOP INDENT statement statements DEDENT
|
block: STOP INDENT statement statements DEDENT
|
||||||
|
block_assignments: STOP INDENT assignments DEDENT
|
||||||
%%
|
%%
|
Loading…
Reference in New Issue
Block a user