Added dot syntax for lists, and proper quote syntax. LQuoted is now unused

This commit is contained in:
Emin Arslan
2025-10-14 22:24:57 +03:00
committed by Emin Arslan
parent be6e1cd684
commit 7105b2dd39
2 changed files with 4 additions and 2 deletions

View File

@@ -11,7 +11,6 @@ let number_sign = '-' | '+'
let int = number_sign? digit+
let double = digit* '.' digit+ | digit+ '.' digit*
let white = [' ' '\t']+
let newline = '\r' | '\n' | "\r\n"
@@ -31,5 +30,6 @@ rule read =
| '(' { LPAREN }
| ')' { RPAREN }
| '\'' { QUOTE }
| '.' { DOT }
| _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf))}
| eof { EOF }

View File

@@ -9,6 +9,7 @@
%token LPAREN
%token RPAREN
%token QUOTE
%token DOT
%token EOF
%start <Ast.lisp_val option> prog
@@ -25,10 +26,11 @@ expr:
| s = SYM { LSymbol s }
| s = STR { LString (String.uppercase_ascii s) }
| LPAREN; l = lisp_list_rest { l }
| QUOTE; e = expr { LQuoted e}
| QUOTE; e = expr { LCons (LSymbol "quote", LCons (e, LNil)) }
;
lisp_list_rest:
| RPAREN { LNil }
| DOT; e = expr; RPAREN { e }
| e = expr; lr = lisp_list_rest { LCons (e, lr) }
;