1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-01-22 08:31:36 +00:00

Fix parseing to check for extraneous/buggy syntax

This commit is contained in:
Dave Schmenk 2017-11-03 17:08:54 -07:00
parent 7ab051f06a
commit 98a107d734
6 changed files with 37 additions and 21 deletions

View File

@ -1,6 +1,6 @@
import testlib
predef puti(i)#0
word print(s)#0
word print
const dec = 0
const hex = 2
const newln = 4

View File

@ -186,7 +186,7 @@ def recvDHCP(remip, remport, pkt, len, param)
//putip(remip);putc(':');puti(remport);putln
//dumpdhcp(pkt)
if pkt=>dhcp_xid:0 == $0201 and pkt=>dhcp_xid:2 = $0403
if pkt=>dhcp_xid:0 == $0201 and pkt=>dhcp_xid:2 == $0403
when pkt->dhcp_opts.[parseopts(@pkt->dhcp_opts, 53) + 2]
is DHCP_OFFER
//

View File

@ -526,7 +526,7 @@ def etherServiceIP
if port
lclport = swab(rxptr=>udp_dst)
for i = 1 to MAX_UDP_NOTIFIES
if port=>notify_port == lclport)
if port=>notify_port == lclport
port=>notify_func(@iphdr=>ip_src,swab(rxptr=>udp_src),rxptr+t_udphdr,swab(rxptr=>udp_len),port=>notify_parm)
break
fin

View File

@ -59,7 +59,7 @@ def openDir(cmd, filename)
namelen = 0
spiSend(cmd)
namelen = spiRecv
if namelen == 0xFF
if namelen == $FF
namelen = 0
fin
if namelen

View File

@ -6,7 +6,7 @@
#include "plasm.h"
char *statement, *tokenstr, *scanpos = "", *strpos = "";
t_token scantoken, prevtoken;
t_token scantoken = EOL_TOKEN, prevtoken;
int tokenlen;
long constval;
FILE* inputfile;
@ -440,6 +440,12 @@ int next_line(void)
}
else
{
if (!(scantoken == EOL_TOKEN || scantoken == EOF_TOKEN))
{
fprintf(stderr, "scantoken = %d (%c)\n", scantoken & 0x7F, scantoken & 0x7F);
parse_error("Extraneous characters");
return EOF_TOKEN;
}
statement = inputline;
scanpos = inputline;
/*
@ -492,6 +498,10 @@ int next_line(void)
scantoken = EOF_TOKEN;
return EOF_TOKEN;
}
if (scan() != EOL_TOKEN)
{
parse_error("Extraneous characters");
}
outer_inputfile = inputfile;
outer_filename = filename;
outer_lineno = lineno;

View File

@ -820,7 +820,7 @@ int parse_stmnt(void)
tag_endif = tag_new(BRANCH_TYPE);
seq = gen_brfls(seq, tag_else);
emit_seq(seq);
scan();
//scan();
do
{
while (parse_stmnt()) next_line();
@ -1075,7 +1075,7 @@ int parse_stmnt(void)
}
break;
case EOL_TOKEN:
case COMMENT_TOKEN:
//case COMMENT_TOKEN:
return (1);
case ELSE_TOKEN:
case ELSEIF_TOKEN:
@ -1131,7 +1131,7 @@ int parse_stmnt(void)
}
}
}
if (scan() != EOL_TOKEN && scantoken != COMMENT_TOKEN)
if (scan() != EOL_TOKEN /*&& scantoken != COMMENT_TOKEN*/)
{
parse_error("Extraneous characters");
return (0);
@ -1224,6 +1224,7 @@ int parse_struc(void)
struclen = tokenlen;
for (idlen = 0; idlen < struclen; idlen++)
strucid[idlen] = tokenstr[idlen];
scan();
}
while (next_line() == BYTE_TOKEN || scantoken == WORD_TOKEN || scantoken == EOL_TOKEN)
{
@ -1266,12 +1267,16 @@ int parse_struc(void)
idconst_add(idstr, idlen, offset);
offset += size;
} while (scantoken == COMMA_TOKEN);
if (scantoken != EOL_TOKEN && scantoken != COMMENT_TOKEN)
if (scantoken != EOL_TOKEN /*&& scantoken != COMMENT_TOKEN*/)
return (0);
}
if (struclen)
idconst_add(strucid, struclen, offset);
return (scantoken == END_TOKEN);
//return (scantoken == END_TOKEN);
if (scantoken != END_TOKEN)
return (0);
scan();
return (1);
}
int parse_vars(int type)
{
@ -1444,7 +1449,7 @@ int parse_vars(int type)
return (0);
}
case EOL_TOKEN:
case COMMENT_TOKEN:
//case COMMENT_TOKEN:
return (1);
default:
return (0);
@ -1468,13 +1473,13 @@ int parse_mods(void)
parse_error("Syntax error");
return (0);
}
if (scan() != EOL_TOKEN && scantoken != COMMENT_TOKEN)
if (scan() != EOL_TOKEN /*&& scantoken != COMMENT_TOKEN*/)
{
parse_error("Extraneous characters");
return (0);
}
}
if (scantoken == EOL_TOKEN || scantoken == COMMENT_TOKEN)
if (scantoken == EOL_TOKEN /*|| scantoken == COMMENT_TOKEN*/)
return (1);
emit_moddep(0, 0);
return (0);
@ -1651,7 +1656,7 @@ int parse_defs(void)
parse_error("Syntax error");
return (0);
}
if (scan() != EOL_TOKEN && scantoken != COMMENT_TOKEN)
if (scan() != EOL_TOKEN /*&& scantoken != COMMENT_TOKEN*/)
{
parse_error("Extraneous characters");
return (0);
@ -1740,18 +1745,19 @@ int parse_defs(void)
idstr[idlen] = c;
do
{
if (scantoken == EOL_TOKEN || scantoken == COMMENT_TOKEN)
next_line();
else if (scantoken != END_TOKEN)
///if (scantoken == EOL_TOKEN /*|| scantoken == COMMENT_TOKEN*/)
//next_line();
if (scantoken != END_TOKEN && scantoken != EOL_TOKEN)
{
scantoken = EOL_TOKEN;
emit_asm(inputline);
next_line();
}
}
while (scantoken != END_TOKEN);
next_line();
} while (scantoken != END_TOKEN);
scan();
return (1);
}
if (scantoken == EOL_TOKEN || scantoken == COMMENT_TOKEN)
if (scantoken == EOL_TOKEN /*|| scantoken == COMMENT_TOKEN*/)
return (1);
return (0);
}