add: more syntax
This commit is contained in:
parent
e53f559f36
commit
ecf948e382
36
DragonLisp.l
36
DragonLisp.l
|
|
@ -54,6 +54,7 @@ from (from|FROM)
|
||||||
to (to|TO)
|
to (to|TO)
|
||||||
dotimes (dotimes|DOTIMES)
|
dotimes (dotimes|DOTIMES)
|
||||||
dolist (dolist|DOLIST)
|
dolist (dolist|DOLIST)
|
||||||
|
do (do|DO)
|
||||||
defconstant (defconstant|DEFCONSTANT)
|
defconstant (defconstant|DEFCONSTANT)
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
@ -278,6 +279,41 @@ defconstant (defconstant|DEFCONSTANT)
|
||||||
return token::TOKEN_QUOTE;
|
return token::TOKEN_QUOTE;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{for} {
|
||||||
|
std::printf("Scanned for\n");
|
||||||
|
return token::TOKEN_FOR;
|
||||||
|
};
|
||||||
|
|
||||||
|
{in} {
|
||||||
|
std::printf("Scanned in\n");
|
||||||
|
return token::TOKEN_IN;
|
||||||
|
};
|
||||||
|
|
||||||
|
{from} {
|
||||||
|
std::printf("Scanned from\n");
|
||||||
|
return token::TOKEN_FROM;
|
||||||
|
};
|
||||||
|
|
||||||
|
{to} {
|
||||||
|
std::printf("Scanned to\n");
|
||||||
|
return token::TOKEN_TO;
|
||||||
|
};
|
||||||
|
|
||||||
|
{dotimes} {
|
||||||
|
std::printf("Scanned dotimes\n");
|
||||||
|
return token::TOKEN_DOTIMES;
|
||||||
|
};
|
||||||
|
|
||||||
|
{dolist} {
|
||||||
|
std::printf("Scanned dolist\n");
|
||||||
|
return token::TOKEN_DOLIST;
|
||||||
|
};
|
||||||
|
|
||||||
|
{do} {
|
||||||
|
std::printf("Scanned do\n");
|
||||||
|
return token::TOKEN_DO;
|
||||||
|
};
|
||||||
|
|
||||||
{id} {
|
{id} {
|
||||||
std::printf("Scanned identifier: %s\n", yytext);
|
std::printf("Scanned identifier: %s\n", yytext);
|
||||||
yylval->emplace<std::string>(std::string(yytext, yyleng));
|
yylval->emplace<std::string>(std::string(yytext, yyleng));
|
||||||
|
|
|
||||||
126
DragonLisp.y
126
DragonLisp.y
|
|
@ -81,6 +81,7 @@ namespace DragonLisp {
|
||||||
TO "to"
|
TO "to"
|
||||||
DOTIMES "dotimes"
|
DOTIMES "dotimes"
|
||||||
DOLIST "dolist"
|
DOLIST "dolist"
|
||||||
|
DO "do"
|
||||||
DEFCONSTANT "defconstant"
|
DEFCONSTANT "defconstant"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -96,6 +97,131 @@ namespace DragonLisp {
|
||||||
|
|
||||||
S
|
S
|
||||||
: END
|
: END
|
||||||
|
| S-Exprs END
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Exprs
|
||||||
|
: S-Exprs empty S-Expr
|
||||||
|
| S-Expr
|
||||||
|
;
|
||||||
|
|
||||||
|
spaces
|
||||||
|
: SPACE
|
||||||
|
| spaces SPACE
|
||||||
|
;
|
||||||
|
|
||||||
|
empty
|
||||||
|
:
|
||||||
|
| spaces
|
||||||
|
;
|
||||||
|
|
||||||
|
R-Value
|
||||||
|
: IDENTIFIER
|
||||||
|
| literal
|
||||||
|
| S-Expr
|
||||||
|
|
||||||
|
S-Expr
|
||||||
|
: LPAREN empty S-Expr-helper empty RPAREN
|
||||||
|
| LPAREN empty RPAREN
|
||||||
|
;
|
||||||
|
|
||||||
|
literal
|
||||||
|
: INTEGER
|
||||||
|
| FLOAT
|
||||||
|
| STRING
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Expr-helper
|
||||||
|
: S-Expr-var-op
|
||||||
|
| S-Expr-unary
|
||||||
|
| S-Expr-binary
|
||||||
|
| S-Expr-list
|
||||||
|
| S-Expr-if
|
||||||
|
| S-Expr-loop
|
||||||
|
| S-Expr-func-def
|
||||||
|
| S-Expr-func-call
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Expr-var-op
|
||||||
|
: var-op-tokens spaces IDENTIFIER spaces R-Value
|
||||||
|
;
|
||||||
|
|
||||||
|
var-op-tokens
|
||||||
|
: DEFVAR
|
||||||
|
| SETQ
|
||||||
|
| INCF
|
||||||
|
| DECF
|
||||||
|
| DEFCONSTANT
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Expr-unary
|
||||||
|
: unary-tokens spaces R-Value
|
||||||
|
;
|
||||||
|
|
||||||
|
unary-tokens
|
||||||
|
: NOT
|
||||||
|
| PRINT
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Expr-binary
|
||||||
|
: binary-tokens spaces S-Expr empty S-Expr
|
||||||
|
;
|
||||||
|
|
||||||
|
binary-tokens
|
||||||
|
: LESS
|
||||||
|
| LESS_EQUAL
|
||||||
|
| GREATER
|
||||||
|
| GREATER_EQUAL
|
||||||
|
| LOGNOR
|
||||||
|
| MOD
|
||||||
|
| REM
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Expr-list
|
||||||
|
: list-tokens spaces S-Exprs
|
||||||
|
;
|
||||||
|
|
||||||
|
list-tokens
|
||||||
|
: EQUAL
|
||||||
|
| NOT_EQUAL
|
||||||
|
| AND
|
||||||
|
| OR
|
||||||
|
| MAX
|
||||||
|
| MIN
|
||||||
|
| LOGAND
|
||||||
|
| LOGIOR
|
||||||
|
| LOGXOR
|
||||||
|
| LOGEQV
|
||||||
|
| PLUS
|
||||||
|
| MINUS
|
||||||
|
| MULTIPLY
|
||||||
|
| DIVIDE
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Expr-if
|
||||||
|
: IF spaces S-Expr empty S-Expr empty S-Expr
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Expr-loop
|
||||||
|
: LOOP empty S-Exprs
|
||||||
|
| LOOP spaces FOR spaces IDENTIFIER spaces IN empty S-Expr empty DO empty S-Exprs
|
||||||
|
| LOOP spaces FOR spaces IDENTIFIER spaces FROM empty S-Expr empty TO empty S-Expr empty DO empty S-Exprs
|
||||||
|
| DOTIMES empty LPAREN empty IDENTIFIER empty S-Expr empty RPAREN empty S-Exprs
|
||||||
|
| DOLIST empty LPAREN empty IDENTIFIER empty S-Expr empty RPAREN empty S-Exprs
|
||||||
|
;
|
||||||
|
|
||||||
|
S-Expr-func-def
|
||||||
|
: DEFUN spaces IDENTIFIER empty LPAREN empty identifier-list empty RPAREN ignored-func-doc S-Exprs
|
||||||
|
;
|
||||||
|
|
||||||
|
ignored-func-doc
|
||||||
|
: empty STRING empty
|
||||||
|
;
|
||||||
|
|
||||||
|
identifier-list
|
||||||
|
: identifier-list IDENTIFIER
|
||||||
|
| IDENTIFIER
|
||||||
|
;
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue