Added dot syntax for lists, and proper quote syntax. LQuoted is now unused
This commit is contained in:
@@ -11,7 +11,6 @@ let number_sign = '-' | '+'
|
|||||||
let int = number_sign? digit+
|
let int = number_sign? digit+
|
||||||
let double = digit* '.' digit+ | digit+ '.' digit*
|
let double = digit* '.' digit+ | digit+ '.' digit*
|
||||||
|
|
||||||
|
|
||||||
let white = [' ' '\t']+
|
let white = [' ' '\t']+
|
||||||
let newline = '\r' | '\n' | "\r\n"
|
let newline = '\r' | '\n' | "\r\n"
|
||||||
|
|
||||||
@@ -31,5 +30,6 @@ rule read =
|
|||||||
| '(' { LPAREN }
|
| '(' { LPAREN }
|
||||||
| ')' { RPAREN }
|
| ')' { RPAREN }
|
||||||
| '\'' { QUOTE }
|
| '\'' { QUOTE }
|
||||||
|
| '.' { DOT }
|
||||||
| _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf))}
|
| _ { raise (SyntaxError ("Unexpected char: " ^ Lexing.lexeme lexbuf))}
|
||||||
| eof { EOF }
|
| eof { EOF }
|
||||||
|
@@ -9,6 +9,7 @@
|
|||||||
%token LPAREN
|
%token LPAREN
|
||||||
%token RPAREN
|
%token RPAREN
|
||||||
%token QUOTE
|
%token QUOTE
|
||||||
|
%token DOT
|
||||||
%token EOF
|
%token EOF
|
||||||
|
|
||||||
%start <Ast.lisp_val option> prog
|
%start <Ast.lisp_val option> prog
|
||||||
@@ -25,10 +26,11 @@ expr:
|
|||||||
| s = SYM { LSymbol s }
|
| s = SYM { LSymbol s }
|
||||||
| s = STR { LString (String.uppercase_ascii s) }
|
| s = STR { LString (String.uppercase_ascii s) }
|
||||||
| LPAREN; l = lisp_list_rest { l }
|
| LPAREN; l = lisp_list_rest { l }
|
||||||
| QUOTE; e = expr { LQuoted e}
|
| QUOTE; e = expr { LCons (LSymbol "quote", LCons (e, LNil)) }
|
||||||
;
|
;
|
||||||
|
|
||||||
lisp_list_rest:
|
lisp_list_rest:
|
||||||
| RPAREN { LNil }
|
| RPAREN { LNil }
|
||||||
|
| DOT; e = expr; RPAREN { e }
|
||||||
| e = expr; lr = lisp_list_rest { LCons (e, lr) }
|
| e = expr; lr = lisp_list_rest { LCons (e, lr) }
|
||||||
;
|
;
|
||||||
|
Reference in New Issue
Block a user