[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
|
||||
var x = 10.0
|
||||
var y = 20.0
|
||||
var z = x + y * 2.0 / 3.0
|
||||
|
||||
print x
|
||||
print y
|
||||
print x // 10
|
||||
print y // 20
|
||||
print z // 23.3
|
||||
// print z
|
||||
END);
|
||||
|
||||
interp: Interp;
|
||||
|
|
|
|||
|
|
@ -203,10 +203,6 @@ parse_string :: (p: *Parser, source: string) -> bool {
|
|||
if node == null break;
|
||||
|
||||
array.append(*p.toplevel, node);
|
||||
|
||||
if node.kind == {
|
||||
case .variable;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -217,7 +213,7 @@ parse_string :: (p: *Parser, source: string) -> bool {
|
|||
|
||||
parse_toplevel :: (p: *Parser) -> *Node {
|
||||
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 == {
|
||||
// var sym type_expr
|
||||
|
|
@ -225,12 +221,12 @@ parse_toplevel :: (p: *Parser) -> *Node {
|
|||
// var sym = expr
|
||||
case .kw_var; #through;
|
||||
case .kw_def;
|
||||
|
||||
s:, ok = expect_token(p, .symbol);
|
||||
basic.assert(ok, "symbol"); // @errors
|
||||
|
||||
type_expr: *Node;
|
||||
value_expr: *Node;
|
||||
|
||||
is_const := t.kind == .kw_def;
|
||||
|
||||
t = peek_token(p);
|
||||
|
|
@ -499,6 +495,8 @@ consume_token :: (p: *Parser) -> Token {
|
|||
if at_end(p) return .{ kind = .end_of_file };
|
||||
|
||||
c := p.source[p.offset];
|
||||
|
||||
// skip whitespace
|
||||
while !at_end(p) {
|
||||
c = p.source[p.offset];
|
||||
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) {
|
||||
t := Token.{ str = .{ data = p.source.data + p.offset } };
|
||||
while !at_end(p) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue