1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2026-04-19 09:23:06 +00:00

Add line continuation to compiler lexer

This commit is contained in:
David Schmenk
2025-01-14 09:28:31 -08:00
parent ea39e71ed9
commit 08db20753b
7 changed files with 84 additions and 35 deletions
+14 -14
View File
@@ -153,8 +153,8 @@ def bitMonoGlyphStr(x, y, strptr)#2
return x, y
end
def pixPropGlyphStr(x, y, strptr)#2
var glyptrs, glyph, left, top
byte first, last, i, ch, width, height
var glyptrs, glyph
byte first, last, i, ch
dhgrOp(OP_XOR)
first = fontPtr->fnt_first
@@ -164,11 +164,11 @@ def pixPropGlyphStr(x, y, strptr)#2
ch = ^(strptr + i)
if ch >= first and ch <= last
glyph = glyptrs=>[ch - first]
left = glyph=>gly_left
top = glyph=>gly_top
width = glyph->gly_width
height = glyph->gly_height
dcgrPixmap((x + left) / 4, y + top, width, height, glyph + gly_strike)
dcgrPixmap((x + glyph=>gly_left) / 4, \
y + glyph=>gly_top, \
glyph->gly_width, \
glyph->gly_height, \
glyph + gly_strike)
x = x + glyph->gly_adv
else
when ch
@@ -186,8 +186,8 @@ def pixPropGlyphStr(x, y, strptr)#2
end
def bitPropGlyphStr(x, y, strptr)#2
var glyptrs, glyph, left, top
byte first, last, i, ch, width, height
var glyptrs, glyph
byte first, last, i, ch
dhgrOp(OP_SRC)
first = fontPtr->fnt_first
@@ -197,11 +197,11 @@ def bitPropGlyphStr(x, y, strptr)#2
ch = ^(strptr + i)
if ch >= first and ch <= last
glyph = glyptrs=>[ch - first]
left = glyph=>gly_left
top = glyph=>gly_top
width = glyph->gly_width
height = glyph->gly_height
dcgrBitmap(x + left, y + top, width, height, glyph + gly_strike)
dcgrBitmap(x + glyph=>gly_left, \
y + glyph=>gly_top, \
glyph->gly_width, \
glyph->gly_height, \
glyph + gly_strike)
x = x + glyph->gly_adv
else
when ch
+3 -1
View File
@@ -1,4 +1,6 @@
include "inc/cmdsys.plh"
puts("Hello, world.\n")
puts( \
"Hello, world.\n" \
)
done
+29 -6
View File
@@ -91,7 +91,6 @@ int hexdigit(char ch)
else
return -1;
}
t_token scan(void)
{
prevtoken = scantoken;
@@ -107,6 +106,11 @@ t_token scan(void)
;
else if (*scanpos == '\0' || *scanpos == '\n' || *scanpos == ';')
scantoken = EOL_TOKEN;
else if (*scanpos == '\\')
{
scantoken = CNT_TOKEN;
next_line();
}
else if ((scanpos[0] >= 'a' && scanpos[0] <= 'z')
|| (scanpos[0] >= 'A' && scanpos[0] <= 'Z')
|| (scanpos[0] == '_'))
@@ -438,10 +442,11 @@ int scan_lookahead(void)
tokenlen = prevlen;
return (look);
}
char inputline[512];
char inputline[MAX_INPUT_LEN];
char conststr[1024];
int next_line(void)
{
char *inptr;
int len;
t_token token;
char* new_filename;
@@ -453,18 +458,36 @@ int next_line(void)
}
else
{
if (!(scantoken == EOL_TOKEN || scantoken == EOF_TOKEN))
if (!(scantoken == EOL_TOKEN || scantoken == EOF_TOKEN || scantoken == CNT_TOKEN))
{
fprintf(stderr, "scantoken = %d (%c)\n", scantoken & 0x7F, scantoken & 0x7F);
parse_error("Extraneous characters");
return EOF_TOKEN;
}
statement = inputline;
scanpos = inputline;
if (scantoken == CNT_TOKEN)
{
/*
* Add to iput line
*/
inptr = scanpos;
len = MAX_INPUT_LEN - (inptr - inputline);
if (len <= 0)
parse_error("Input overflow");
}
else
{
/*
* Read fresh input line
*/
statement = inputline;
scanpos = inputline;
inptr = inputline;
len = MAX_INPUT_LEN;
}
/*
* Read next line from the current file, and strip newline from the end.
*/
if (fgets(inputline, 512, inputfile) == NULL)
if (fgets(inptr, len, inputfile) == NULL)
{
inputline[0] = 0;
/*
+28 -8
View File
@@ -73,7 +73,6 @@ def scannum
fin
return num
end
def scan
//
// Skip whitespace
@@ -289,6 +288,12 @@ def scan
token = EOL_TKN
fin
break
is '\\'
if token <> EOF_TKN
token = CNT_TKN
nextln
fin
break
otherwise
//
// Simple single character tokens
@@ -322,16 +327,31 @@ end
// Get next line of input
//
def nextln
var inptr, inlen
strconstptr = strconstbuff // Reset string constant buffer
if ^scanptr == ';'
scanptr++
scan
else
if token <> EOL_TKN and token <> EOF_TKN; putc(token&$7F); puts("Extraneous characters\n"); exit_err(0); fin
scanptr = inbuff
^instr = fileio:read(refnum, inbuff, 127)
if ^instr
^(instr + ^instr) = NULL // NULL terminate string
if token <> EOL_TKN and token <> EOF_TKN and token <> CNT_TKN
putc(token&$7F); puts("Extraneous characters\n")
exit_err(0)
fin
if token == CNT_TKN
inptr = scanptr
inlen = MAX_INPUT_LEN - (inptr - inbuff)
if inlen <= 0
puts("Input "); exit_err(ERR_OVER)
fin
else
scanptr = inbuff
inptr = inbuff
inlen = MAX_INPUT_LEN
fin
inlen = fileio:read(refnum, inptr, inlen)
if inlen
^(inptr + inlen - 1) = NULL // NULL terminate input
lineno++
if !(lineno & $0F); putc('.'); fin
if scan == INCLUDE_TKN
@@ -362,8 +382,8 @@ def nextln
lineno = srcline
return nextln
else
*instr = NULL // NULL terminated 0 length string
token = EOF_TKN
^inbuff = NULL // NULL terminated 0 length string
token = EOF_TKN
fin
fin
fin
+1
View File
@@ -12,6 +12,7 @@
#define STREAM (1<<8)
#define FALSE 0
#define TRUE (!FALSE)
#define MAX_INPUT_LEN 1024
extern int outflags;
extern FILE *inputfile, *outputfile;
extern char *filename, modfile[17];
+8 -6
View File
@@ -10,6 +10,7 @@ const ID_TKN = $D6 // V
const CHR_TKN = $C3 // C
const INT_TKN = $C9 // I
const STR_TKN = $D3 // S
const CNT_TKN = $DC // \
const EOL_TKN = $02
const EOF_TKN = $01
const ERR_TKN = $00
@@ -253,6 +254,7 @@ word codebuff, codeptr, entrypoint
word modsysflags
byte[16] moddep_tbl[MODDEPNUM]
byte moddep_cnt, def_cnt = 1
predef nextln
predef parse_mods
predef emit_pending_seq#0
//
@@ -282,7 +284,7 @@ word srcline // Saved source line number
//
// Scanner variables
//
word instr
const MAX_INPUT_LEN = 1024
word inbuff
word scanptr
byte token = EOL_TKN
@@ -451,9 +453,10 @@ def nametostr(namestr, len, strptr)#0
memcpy(strptr + 1, namestr, len)
end
def putcurln#0
byte i
var i
putln; puts(parsefile); putc('['); puti(lineno); puts("]\n")
puts(instr); putln
i = inbuff; while ^i; putc(^i); i++; loop; putln
for i = tknptr - inbuff downto 1
putc(' ')
next
@@ -579,10 +582,9 @@ if srcfile and relfile
refnum = srcref
parsefile = @srcfile
strconstbuff = heapalloc(80)
instr = cmdsys:cmdline
inbuff = instr + 1
inbuff = heapalloc(MAX_INPUT_LEN)
scanptr = inbuff
*instr = NULL
^inbuff = NULL
exit = heapalloc(t_except)
if not except(exit)
//
+1
View File
@@ -110,6 +110,7 @@
//#define COMMENT_TOKEN TOKEN(';')
#define DROP_TOKEN TOKEN(';')
#define EOL_TOKEN TOKEN(0)
#define CNT_TOKEN TOKEN('\\')
#define INCLUDE_TOKEN TOKEN(0x7E)
#define EOF_TOKEN TOKEN(0x7F)