update compv1, remove def from compv1
This commit is contained in:
parent
8d1e9a5318
commit
c36292843a
|
@ -146,4 +146,4 @@ proc parseFunct*(comp: Compiler) =
|
||||||
comp.writeChunk(0, upval.index.toDU8())
|
comp.writeChunk(0, upval.index.toDU8())
|
||||||
comp.writeChunk(0, if upval.isLocal: 0'u8 else: 1'u8)
|
comp.writeChunk(0, if upval.isLocal: 0'u8 else: 1'u8)
|
||||||
|
|
||||||
tkFunct.genRule(parseFunct, nop, pcNone)
|
tkProc.genRule(parseFunct, nop, pcNone)
|
||||||
|
|
|
@ -47,9 +47,9 @@ proc statement*(comp: Compiler) =
|
||||||
if comp.match(tkVar):
|
if comp.match(tkVar):
|
||||||
comp.varStatement()
|
comp.varStatement()
|
||||||
comp.consume(tkSemicolon, "Semicolon expected after expression statement.")
|
comp.consume(tkSemicolon, "Semicolon expected after expression statement.")
|
||||||
elif comp.match(tkDef):
|
# elif comp.match(tkDef):
|
||||||
comp.procStatement()
|
# comp.procStatement()
|
||||||
comp.consume(tkSemicolon, "Semicolon expected after procedure declaration.")
|
# comp.consume(tkSemicolon, "Semicolon expected after procedure declaration.")
|
||||||
elif comp.match(tkBreak):
|
elif comp.match(tkBreak):
|
||||||
comp.breakStatement()
|
comp.breakStatement()
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -53,7 +53,7 @@ proc synchronize*(comp: Compiler) =
|
||||||
while comp.current.tokenType != tkEof:
|
while comp.current.tokenType != tkEof:
|
||||||
if comp.previous.tokenType in {tkSemicolon, tkRightBrace}:
|
if comp.previous.tokenType in {tkSemicolon, tkRightBrace}:
|
||||||
return
|
return
|
||||||
if comp.current.tokenType in {tkFunct, tkVar, tkFor, tkIf, tkWhile}:
|
if comp.current.tokenType in {tkProc, tkVar, tkFor, tkIf, tkWhile}:
|
||||||
return
|
return
|
||||||
comp.advance()
|
comp.advance()
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
# parser: converts a stream of tokens into an AST
|
# parser: converts a stream of tokens into an AST
|
||||||
|
|
||||||
import ../scanner
|
import ../scanner
|
||||||
import ../chunk
|
|
||||||
import node
|
import node
|
||||||
import ../config
|
import ../config
|
||||||
import ../types/value
|
import ../types/value
|
||||||
|
@ -10,8 +9,6 @@ import ../types/value
|
||||||
import strformat
|
import strformat
|
||||||
import strutils
|
import strutils
|
||||||
import bitops
|
import bitops
|
||||||
import sequtils
|
|
||||||
import sugar
|
|
||||||
import options
|
import options
|
||||||
|
|
||||||
# TYPEDEF
|
# TYPEDEF
|
||||||
|
@ -55,9 +52,6 @@ proc errorAt(parser: Parser, line: int, msg: string, at: string = "") =
|
||||||
parser.hadError = true
|
parser.hadError = true
|
||||||
parser.panicMode = true
|
parser.panicMode = true
|
||||||
|
|
||||||
proc error(parser: Parser, msg: string) =
|
|
||||||
parser.errorAt(parser.previous.get().line, msg)
|
|
||||||
|
|
||||||
proc errorAtCurrent(parser: Parser, msg: string) =
|
proc errorAtCurrent(parser: Parser, msg: string) =
|
||||||
parser.errorAt(parser.current.line, msg)
|
parser.errorAt(parser.current.line, msg)
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,7 @@ const debugClosures* = defined(debug) # specific closure debug switches
|
||||||
|
|
||||||
type compMode* = enum
|
type compMode* = enum
|
||||||
cmOne, cmAst
|
cmOne, cmAst
|
||||||
const compilerChoice* = cmAst
|
const compilerChoice* = cmOne
|
||||||
# choose a compiler: cmOne - version 1, deprecated
|
# choose a compiler: cmOne - version 1, deprecated
|
||||||
# cmAst - version 2, but only use parser and print AST produced
|
# cmAst - version 2, but only use parser and print AST produced
|
||||||
# cmOne will be removed once compv2 is done
|
# cmOne will be removed once compv2 is done
|
||||||
|
|
|
@ -13,4 +13,4 @@ print (a[0][0]);
|
||||||
|
|
||||||
a[0][0] = 3;
|
a[0][0] = 3;
|
||||||
print (a[0][0]);
|
print (a[0][0]);
|
||||||
//expect:3.0;
|
//expect:3.0
|
|
@ -88,14 +88,14 @@ print("finish");
|
||||||
proc() print("merry christmas") :: proc(it) it();
|
proc() print("merry christmas") :: proc(it) it();
|
||||||
//expect:merry christmas
|
//expect:merry christmas
|
||||||
|
|
||||||
// proc declaration through def
|
// proc declaration
|
||||||
|
|
||||||
def globalProc(a, b, c)
|
proc globalProc(a, b, c)
|
||||||
a + b * c
|
a + b * c
|
||||||
;
|
;
|
||||||
|
|
||||||
{
|
{
|
||||||
def localProc(d, e, f)
|
proc localProc(d, e, f)
|
||||||
2 * d + 3 * e + 4 * f
|
2 * d + 3 * e + 4 * f
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue