quakeforge/ruamoko/scheme/Parser.r
Brian Koropoff 281b683e14 Initial commit of a future partial implementation of the R5RS Scheme
standard, implemented in Ruamoko.  Currently works for a few simple
"Hello, world!" programs.
2005-05-01 11:48:36 +00:00

55 lines
1,008 B
R

#include "Cons.h"
#include "Parser.h"
#include "Nil.h"
#include "defs.h"
@implementation Parser
+ (id) newFromSource: (string) s
{
return [[self alloc] initWithSource: s];
}
- (id) initWithSource: (string) s
{
lexer = [Lexer newFromSource: s];
return [super init];
}
- (SchemeObject) readList
{
local SchemeObject token;
token = [self read];
if (!token)
return NIL;
if (token == [Symbol rightParen]) {
return [Nil nil];
} else {
return [Cons newWithCar: token cdr: [self readList]];
}
}
- (SchemeObject) read
{
local SchemeObject token;
local SchemeObject list;
token = [lexer nextToken];
if (!token) {
return NIL;
}
if (token == [Symbol leftParen]) {
list = [self readList];
return list;
} else if (token == [Symbol quote]) {
return cons([Symbol forString: "quote"], cons([self read], [Nil nil]));
} else return token;
}
@end