mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2024-11-05 20:50:43 +00:00
281b683e14
standard, implemented in Ruamoko. Currently works for a few simple "Hello, world!" programs.
55 lines
1,008 B
R
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
|