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)
|
||||
loop (loop|LOOP)
|
||||
setq (setq|SETQ)
|
||||
setf (setf|SETF)
|
||||
quote (quote|QUOTE)
|
||||
for (for|FOR)
|
||||
in (in|IN)
|
||||
|
|
@ -55,6 +56,8 @@ to (to|TO)
|
|||
dotimes (dotimes|DOTIMES)
|
||||
dolist (dolist|DOLIST)
|
||||
do (do|DO)
|
||||
aref (aref|AREF)
|
||||
makearray (make-array|MAKE-ARRAY)
|
||||
defconstant (defconstant|DEFCONSTANT)
|
||||
|
||||
%%
|
||||
|
|
@ -274,6 +277,11 @@ defconstant (defconstant|DEFCONSTANT)
|
|||
return token::TOKEN_SETQ;
|
||||
};
|
||||
|
||||
{setf} {
|
||||
std::printf("Scanned setf\n");
|
||||
return token::TOKEN_SETF;
|
||||
};
|
||||
|
||||
{quote} {
|
||||
std::printf("Scanned quote\n");
|
||||
return token::TOKEN_QUOTE;
|
||||
|
|
@ -314,6 +322,21 @@ defconstant (defconstant|DEFCONSTANT)
|
|||
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} {
|
||||
std::printf("Scanned identifier: %s\n", yytext);
|
||||
yylval->emplace<std::string>(std::string(yytext, yyleng));
|
||||
|
|
|
|||
33
DragonLisp.y
33
DragonLisp.y
|
|
@ -74,6 +74,7 @@ namespace DragonLisp {
|
|||
PRINT "print"
|
||||
LOOP "loop"
|
||||
SETQ "setq"
|
||||
SETF "setf"
|
||||
QUOTE "quote"
|
||||
FOR "for"
|
||||
IN "in"
|
||||
|
|
@ -82,6 +83,8 @@ namespace DragonLisp {
|
|||
DOTIMES "dotimes"
|
||||
DOLIST "dolist"
|
||||
DO "do"
|
||||
AREF "aref"
|
||||
MAKE_ARRAY "make-array"
|
||||
DEFCONSTANT "defconstant"
|
||||
;
|
||||
|
||||
|
|
@ -115,6 +118,14 @@ S-Exprs
|
|||
| 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
|
||||
: IDENTIFIER { std::printf("Parsed R-Value -> IDENTIFIER\n"); }
|
||||
| S-Expr { std::printf("Parsed R-Value -> S-Expr\n"); }
|
||||
|
|
@ -129,12 +140,13 @@ R-Value-list
|
|||
;
|
||||
|
||||
S-Expr
|
||||
: LPAREN S-Expr-helper RPAREN { std::printf("Parsed S-Expr -> LPAREN S-Expr-helper RPAREN\n"); }
|
||||
| LPAREN RPAREN { std::printf("Parsed S-Expr -> LPAREN RPAREN\n"); }
|
||||
: LPAREN S-Expr-helper RPAREN { std::printf("Parsed S-Expr -> ( S-Expr-helper )\n"); }
|
||||
| LPAREN RPAREN { std::printf("Parsed S-Expr -> ()\n"); }
|
||||
;
|
||||
|
||||
S-Expr-helper
|
||||
: 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-binary { std::printf("Parsed S-Expr-helper -> S-Expr-binary\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"); }
|
||||
;
|
||||
|
||||
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
|
||||
: unary-tokens R-Value { std::printf("Parsed S-Expr-unary -> unary-tokens R-Value\n"); }
|
||||
;
|
||||
|
|
@ -162,6 +184,7 @@ S-Expr-unary
|
|||
unary-tokens
|
||||
: NOT { std::printf("Parsed unary-tokens -> NOT\n"); }
|
||||
| PRINT { std::printf("Parsed unary-tokens -> PRINT\n"); }
|
||||
| MAKE_ARRAY { std::printf("Parsed unary-tokens -> MAKE_ARRAY\n"); }
|
||||
;
|
||||
|
||||
S-Expr-binary
|
||||
|
|
@ -206,14 +229,12 @@ S-Expr-if
|
|||
|
||||
S-Expr-loop
|
||||
: 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"); }
|
||||
| DOTIMES LPAREN IDENTIFIER S-Expr RPAREN S-Exprs { std::printf("Parsed S-Expr-loop -> DOTIMES LPAREN IDENTIFIER S-Expr RPAREN 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"); }
|
||||
| DOTIMES LPAREN IDENTIFIER S-Expr RPAREN S-Exprs { std::printf("Parsed S-Expr-loop -> DOTIMES ( IDENTIFIER S-Expr ) S-Exprs\n"); }
|
||||
;
|
||||
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue