[vm] comments
This commit is contained in:
parent
5ed453a0fc
commit
85065a23e6
2 changed files with 24 additions and 8 deletions
|
|
@ -21,9 +21,12 @@ strings :: #import "String"; // @future
|
||||||
ok := parse_string(*parser, #string END
|
ok := parse_string(*parser, #string END
|
||||||
var x = 10.0
|
var x = 10.0
|
||||||
var y = 20.0
|
var y = 20.0
|
||||||
|
var z = x + y * 2.0 / 3.0
|
||||||
|
|
||||||
print x
|
print x // 10
|
||||||
print y
|
print y // 20
|
||||||
|
print z // 23.3
|
||||||
|
// print z
|
||||||
END);
|
END);
|
||||||
|
|
||||||
interp: Interp;
|
interp: Interp;
|
||||||
|
|
|
||||||
|
|
@ -203,10 +203,6 @@ parse_string :: (p: *Parser, source: string) -> bool {
|
||||||
if node == null break;
|
if node == null break;
|
||||||
|
|
||||||
array.append(*p.toplevel, node);
|
array.append(*p.toplevel, node);
|
||||||
|
|
||||||
if node.kind == {
|
|
||||||
case .variable;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -217,7 +213,7 @@ parse_string :: (p: *Parser, source: string) -> bool {
|
||||||
|
|
||||||
parse_toplevel :: (p: *Parser) -> *Node {
|
parse_toplevel :: (p: *Parser) -> *Node {
|
||||||
t, ok := expect_token(p, .kw_var, .kw_def, .kw_print);
|
t, ok := expect_token(p, .kw_var, .kw_def, .kw_print);
|
||||||
basic.assert(ok, "var, def, print"); // @errors
|
basic.assert(ok, "var, def, print, found '%'", t.str); // @errors
|
||||||
|
|
||||||
if t.kind == {
|
if t.kind == {
|
||||||
// var sym type_expr
|
// var sym type_expr
|
||||||
|
|
@ -225,12 +221,12 @@ parse_toplevel :: (p: *Parser) -> *Node {
|
||||||
// var sym = expr
|
// var sym = expr
|
||||||
case .kw_var; #through;
|
case .kw_var; #through;
|
||||||
case .kw_def;
|
case .kw_def;
|
||||||
|
|
||||||
s:, ok = expect_token(p, .symbol);
|
s:, ok = expect_token(p, .symbol);
|
||||||
basic.assert(ok, "symbol"); // @errors
|
basic.assert(ok, "symbol"); // @errors
|
||||||
|
|
||||||
type_expr: *Node;
|
type_expr: *Node;
|
||||||
value_expr: *Node;
|
value_expr: *Node;
|
||||||
|
|
||||||
is_const := t.kind == .kw_def;
|
is_const := t.kind == .kw_def;
|
||||||
|
|
||||||
t = peek_token(p);
|
t = peek_token(p);
|
||||||
|
|
@ -499,6 +495,8 @@ consume_token :: (p: *Parser) -> Token {
|
||||||
if at_end(p) return .{ kind = .end_of_file };
|
if at_end(p) return .{ kind = .end_of_file };
|
||||||
|
|
||||||
c := p.source[p.offset];
|
c := p.source[p.offset];
|
||||||
|
|
||||||
|
// skip whitespace
|
||||||
while !at_end(p) {
|
while !at_end(p) {
|
||||||
c = p.source[p.offset];
|
c = p.source[p.offset];
|
||||||
if c == {
|
if c == {
|
||||||
|
|
@ -511,6 +509,21 @@ consume_token :: (p: *Parser) -> Token {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// line comments
|
||||||
|
// @todo(judah): don't ignore these
|
||||||
|
if c == "/" && p.offset + 1 < p.source.count && p.source[p.offset + 1] == "/" {
|
||||||
|
p.offset += 2;
|
||||||
|
|
||||||
|
while !at_end(p) {
|
||||||
|
c = p.source[p.offset];
|
||||||
|
if c == "\n" break;
|
||||||
|
p.offset += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// @todo(judah): don't recurse
|
||||||
|
return consume_token(p);
|
||||||
|
}
|
||||||
|
|
||||||
if starts_symbol(c) {
|
if starts_symbol(c) {
|
||||||
t := Token.{ str = .{ data = p.source.data + p.offset } };
|
t := Token.{ str = .{ data = p.source.data + p.offset } };
|
||||||
while !at_end(p) {
|
while !at_end(p) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue