fix: complete tokens & syntax
This commit is contained in:
parent
92cc782c68
commit
b9e173c39b
23
DragonLisp.l
23
DragonLisp.l
|
|
@ -47,6 +47,7 @@ defun (defun|DEFUN)
|
||||||
print (print|PRINT)
|
print (print|PRINT)
|
||||||
loop (loop|LOOP)
|
loop (loop|LOOP)
|
||||||
setq (setq|SETQ)
|
setq (setq|SETQ)
|
||||||
|
setf (setf|SETF)
|
||||||
quote (quote|QUOTE)
|
quote (quote|QUOTE)
|
||||||
for (for|FOR)
|
for (for|FOR)
|
||||||
in (in|IN)
|
in (in|IN)
|
||||||
|
|
@ -55,6 +56,8 @@ to (to|TO)
|
||||||
dotimes (dotimes|DOTIMES)
|
dotimes (dotimes|DOTIMES)
|
||||||
dolist (dolist|DOLIST)
|
dolist (dolist|DOLIST)
|
||||||
do (do|DO)
|
do (do|DO)
|
||||||
|
aref (aref|AREF)
|
||||||
|
makearray (make-array|MAKE-ARRAY)
|
||||||
defconstant (defconstant|DEFCONSTANT)
|
defconstant (defconstant|DEFCONSTANT)
|
||||||
|
|
||||||
%%
|
%%
|
||||||
|
|
@ -274,6 +277,11 @@ defconstant (defconstant|DEFCONSTANT)
|
||||||
return token::TOKEN_SETQ;
|
return token::TOKEN_SETQ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{setf} {
|
||||||
|
std::printf("Scanned setf\n");
|
||||||
|
return token::TOKEN_SETF;
|
||||||
|
};
|
||||||
|
|
||||||
{quote} {
|
{quote} {
|
||||||
std::printf("Scanned quote\n");
|
std::printf("Scanned quote\n");
|
||||||
return token::TOKEN_QUOTE;
|
return token::TOKEN_QUOTE;
|
||||||
|
|
@ -314,6 +322,21 @@ defconstant (defconstant|DEFCONSTANT)
|
||||||
return token::TOKEN_DO;
|
return token::TOKEN_DO;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
{aref} {
|
||||||
|
std::printf("Scanned aref\n");
|
||||||
|
return token::TOKEN_AREF;
|
||||||
|
};
|
||||||
|
|
||||||
|
{makearray} {
|
||||||
|
std::printf("Scanned makearray\n");
|
||||||
|
return token::TOKEN_MAKE_ARRAY;
|
||||||
|
};
|
||||||
|
|
||||||
|
{defconstant} {
|
||||||
|
std::printf("Scanned defconstant\n");
|
||||||
|
return token::TOKEN_DEFCONSTANT;
|
||||||
|
};
|
||||||
|
|
||||||
{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));
|
||||||
|
|
|
||||||
33
DragonLisp.y
33
DragonLisp.y
|
|
@ -74,6 +74,7 @@ namespace DragonLisp {
|
||||||
PRINT "print"
|
PRINT "print"
|
||||||
LOOP "loop"
|
LOOP "loop"
|
||||||
SETQ "setq"
|
SETQ "setq"
|
||||||
|
SETF "setf"
|
||||||
QUOTE "quote"
|
QUOTE "quote"
|
||||||
FOR "for"
|
FOR "for"
|
||||||
IN "in"
|
IN "in"
|
||||||
|
|
@ -82,6 +83,8 @@ namespace DragonLisp {
|
||||||
DOTIMES "dotimes"
|
DOTIMES "dotimes"
|
||||||
DOLIST "dolist"
|
DOLIST "dolist"
|
||||||
DO "do"
|
DO "do"
|
||||||
|
AREF "aref"
|
||||||
|
MAKE_ARRAY "make-array"
|
||||||
DEFCONSTANT "defconstant"
|
DEFCONSTANT "defconstant"
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
@ -115,6 +118,14 @@ S-Exprs
|
||||||
| S-Expr { std::printf("Parsed S-Exprs -> S-Expr\n"); }
|
| S-Expr { std::printf("Parsed S-Exprs -> S-Expr\n"); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
array-ref
|
||||||
|
: LPAREN AREF IDENTIFIER R-Value RPAREN { std::printf("Parsed array-ref -> ( AREF IDENTIFIER R-Value )\n"); }
|
||||||
|
;
|
||||||
|
|
||||||
|
L-Value
|
||||||
|
: IDENTIFIER
|
||||||
|
| array-ref
|
||||||
|
|
||||||
R-Value
|
R-Value
|
||||||
: IDENTIFIER { std::printf("Parsed R-Value -> IDENTIFIER\n"); }
|
: IDENTIFIER { std::printf("Parsed R-Value -> IDENTIFIER\n"); }
|
||||||
| S-Expr { std::printf("Parsed R-Value -> S-Expr\n"); }
|
| S-Expr { std::printf("Parsed R-Value -> S-Expr\n"); }
|
||||||
|
|
@ -129,12 +140,13 @@ R-Value-list
|
||||||
;
|
;
|
||||||
|
|
||||||
S-Expr
|
S-Expr
|
||||||
: LPAREN S-Expr-helper RPAREN { std::printf("Parsed S-Expr -> LPAREN S-Expr-helper RPAREN\n"); }
|
: LPAREN S-Expr-helper RPAREN { std::printf("Parsed S-Expr -> ( S-Expr-helper )\n"); }
|
||||||
| LPAREN RPAREN { std::printf("Parsed S-Expr -> LPAREN RPAREN\n"); }
|
| LPAREN RPAREN { std::printf("Parsed S-Expr -> ()\n"); }
|
||||||
;
|
;
|
||||||
|
|
||||||
S-Expr-helper
|
S-Expr-helper
|
||||||
: S-Expr-var-op { std::printf("Parsed S-Expr-helper -> S-Expr-var-op\n"); }
|
: S-Expr-var-op { std::printf("Parsed S-Expr-helper -> S-Expr-var-op\n"); }
|
||||||
|
| S-Expr-Lval-op { std::printf("Parsed S-Expr-helper -> S-Expr-Lval-op\n"); }
|
||||||
| S-Expr-unary { std::printf("Parsed S-Expr-helper -> S-Expr-unary\n"); }
|
| S-Expr-unary { std::printf("Parsed S-Expr-helper -> S-Expr-unary\n"); }
|
||||||
| S-Expr-binary { std::printf("Parsed S-Expr-helper -> S-Expr-binary\n"); }
|
| S-Expr-binary { std::printf("Parsed S-Expr-helper -> S-Expr-binary\n"); }
|
||||||
| S-Expr-list { std::printf("Parsed S-Expr-helper -> S-Expr-list\n"); }
|
| S-Expr-list { std::printf("Parsed S-Expr-helper -> S-Expr-list\n"); }
|
||||||
|
|
@ -155,6 +167,16 @@ var-op-tokens
|
||||||
| DEFCONSTANT { std::printf("Parsed var-op-tokens -> DEFCONSTANT\n"); }
|
| DEFCONSTANT { std::printf("Parsed var-op-tokens -> DEFCONSTANT\n"); }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
S-Expr-Lval-op
|
||||||
|
: lval-op-tokens L-Value R-Value { std::printf("Parsed S-Expr-Lval-op -> lval-op-tokens L-Value R-Value\n"); }
|
||||||
|
;
|
||||||
|
|
||||||
|
lval-op-tokens
|
||||||
|
: SETF { std::printf("Parsed lval-op-tokens -> SETF\n"); }
|
||||||
|
| INCF { std::printf("Parsed lval-op-tokens -> INCF\n"); }
|
||||||
|
| DECF { std::printf("Parsed lval-op-tokens -> DECF\n"); }
|
||||||
|
;
|
||||||
|
|
||||||
S-Expr-unary
|
S-Expr-unary
|
||||||
: unary-tokens R-Value { std::printf("Parsed S-Expr-unary -> unary-tokens R-Value\n"); }
|
: unary-tokens R-Value { std::printf("Parsed S-Expr-unary -> unary-tokens R-Value\n"); }
|
||||||
;
|
;
|
||||||
|
|
@ -162,6 +184,7 @@ S-Expr-unary
|
||||||
unary-tokens
|
unary-tokens
|
||||||
: NOT { std::printf("Parsed unary-tokens -> NOT\n"); }
|
: NOT { std::printf("Parsed unary-tokens -> NOT\n"); }
|
||||||
| PRINT { std::printf("Parsed unary-tokens -> PRINT\n"); }
|
| PRINT { std::printf("Parsed unary-tokens -> PRINT\n"); }
|
||||||
|
| MAKE_ARRAY { std::printf("Parsed unary-tokens -> MAKE_ARRAY\n"); }
|
||||||
;
|
;
|
||||||
|
|
||||||
S-Expr-binary
|
S-Expr-binary
|
||||||
|
|
@ -206,14 +229,12 @@ S-Expr-if
|
||||||
|
|
||||||
S-Expr-loop
|
S-Expr-loop
|
||||||
: LOOP S-Exprs { std::printf("Parsed S-Expr-loop -> LOOP S-Exprs\n"); }
|
: LOOP S-Exprs { std::printf("Parsed S-Expr-loop -> LOOP S-Exprs\n"); }
|
||||||
| LOOP FOR IDENTIFIER IN S-Expr DO S-Exprs { std::printf("Parsed S-Expr-loop -> LOOP FOR IDENTIFIER IN S-Expr DO S-Exprs\n"); }
|
|
||||||
| LOOP FOR IDENTIFIER FROM S-Expr TO S-Expr DO S-Exprs { std::printf("Parsed S-Expr-loop -> LOOP FOR IDENTIFIER FROM S-Expr TO S-Expr DO S-Exprs\n"); }
|
| LOOP FOR IDENTIFIER FROM S-Expr TO S-Expr DO S-Exprs { std::printf("Parsed S-Expr-loop -> LOOP FOR IDENTIFIER FROM S-Expr TO S-Expr DO S-Exprs\n"); }
|
||||||
| DOTIMES LPAREN IDENTIFIER S-Expr RPAREN S-Exprs { std::printf("Parsed S-Expr-loop -> DOTIMES LPAREN IDENTIFIER S-Expr RPAREN S-Exprs\n"); }
|
| DOTIMES LPAREN IDENTIFIER S-Expr RPAREN S-Exprs { std::printf("Parsed S-Expr-loop -> DOTIMES ( IDENTIFIER S-Expr ) S-Exprs\n"); }
|
||||||
| DOLIST LPAREN IDENTIFIER S-Expr RPAREN S-Exprs { std::printf("Parsed S-Expr-loop -> DOLIST LPAREN IDENTIFIER S-Expr RPAREN S-Exprs\n"); }
|
|
||||||
;
|
;
|
||||||
|
|
||||||
func-def
|
func-def
|
||||||
: LPAREN DEFUN IDENTIFIER LPAREN identifier-list RPAREN ignored-func-doc S-Exprs RPAREN { std::printf("Parsed func-def -> DEFUN IDENTIFIER LPAREN identifier-list RPAREN ignored-func-doc S-Exprs\n"); }
|
: LPAREN DEFUN IDENTIFIER LPAREN identifier-list RPAREN ignored-func-doc S-Exprs RPAREN { std::printf("Parsed func-def -> DEFUN IDENTIFIER ( identifier-list ) ignored-func-doc S-Exprs\n"); }
|
||||||
;
|
;
|
||||||
|
|
||||||
ignored-func-doc
|
ignored-func-doc
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue