1
0
mirror of https://github.com/dschmenk/PLASMA.git synced 2025-08-15 09:27:34 +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 import testlib
predef puti(i)#0 predef puti(i)#0
word print(s)#0 word print
const dec = 0 const dec = 0
const hex = 2 const hex = 2
const newln = 4 const newln = 4

View File

@@ -186,7 +186,7 @@ def recvDHCP(remip, remport, pkt, len, param)
//putip(remip);putc(':');puti(remport);putln //putip(remip);putc(':');puti(remport);putln
//dumpdhcp(pkt) //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] when pkt->dhcp_opts.[parseopts(@pkt->dhcp_opts, 53) + 2]
is DHCP_OFFER is DHCP_OFFER
// //

View File

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

View File

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

View File

@@ -6,7 +6,7 @@
#include "plasm.h" #include "plasm.h"
char *statement, *tokenstr, *scanpos = "", *strpos = ""; char *statement, *tokenstr, *scanpos = "", *strpos = "";
t_token scantoken, prevtoken; t_token scantoken = EOL_TOKEN, prevtoken;
int tokenlen; int tokenlen;
long constval; long constval;
FILE* inputfile; FILE* inputfile;
@@ -440,6 +440,12 @@ int next_line(void)
} }
else 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; statement = inputline;
scanpos = inputline; scanpos = inputline;
/* /*
@@ -492,6 +498,10 @@ int next_line(void)
scantoken = EOF_TOKEN; scantoken = EOF_TOKEN;
return EOF_TOKEN; return EOF_TOKEN;
} }
if (scan() != EOL_TOKEN)
{
parse_error("Extraneous characters");
}
outer_inputfile = inputfile; outer_inputfile = inputfile;
outer_filename = filename; outer_filename = filename;
outer_lineno = lineno; outer_lineno = lineno;

View File

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