Mercurial > hg > index.cgi
diff lwasm/pass1.c @ 399:6153cb49403c
Initial commit of pragma newsource
pragma newsource enables a source code variant as follows:
1. no line numbers
2. no implied comments at the end of lines
3. all comments must be introduced by a comment character
4. spaces are allowed in operands
(4) is not quite complete. This commit handles "operandless" instructions
(anything where the parser calls skip_operand()) and expression parsing.
author | William Astle <lost@l-w.ca> |
---|---|
date | Tue, 13 Oct 2015 23:38:02 -0600 |
parents | 4fd16faa4d93 |
children | b1adf549d181 |
line wrap: on
line diff
--- a/lwasm/pass1.c Sun Oct 11 09:31:06 2015 -0600 +++ b/lwasm/pass1.c Tue Oct 13 23:38:02 2015 -0600 @@ -38,7 +38,7 @@ /* pass 1: parse the lines -line format: +line format if PRAGMA_NEWSOURCE is not in force: [<symbol>] <opcode> <operand>[ <comment>] @@ -48,6 +48,14 @@ white space and must be followed by a single whitespace character. After that whitespace character, the line is parsed as if it had no line number. +Also, no spaces are permitted within <operand>. + +With PRAGMA_NEWSOURCE in effect, line numbers are not allowed and there +is no automatic comment at the end of each line. All comments must be +introduced with the comment character. This allows the parser to handle +spaces in operands unambiguously so in this mode, spaces are permitted +within operands. + */ void do_pass1(asmstate_t *as) { @@ -174,12 +182,12 @@ } // skip comments - // commends do not create a context break + // comments do not create a context break if (*line == '*' || *line == ';' || *line == '#') goto nextline; p1 = line; - if (isdigit(*p1)) + if (isdigit(*p1) && !CURPRAGMA(cl, PRAGMA_NEWSOURCE)) { // skip line number while (*p1 && isdigit(*p1)) @@ -212,8 +220,6 @@ else stspace = 0; -// if (*p1 == '*' || *p1 == ';' || *p1 == '#') -// goto nextline; if (!*p1) { // nothing but whitespace - context break @@ -235,7 +241,7 @@ p1++; for (; *p1 && isspace(*p1); p1++) /* do nothing */ ; - + if (*p1 == '=') { tok = p1++; @@ -263,12 +269,12 @@ } if (*tok) { - if (CURPRAGMA(cl, PRAGMA_TESTMODE)) - { - /* in test mode, terminate the line here so we don't affect the parsers */ - /* (cl -> ltext retains the full, unmodified string) */ - char *t = strstr(p1, ";."); - if (t) *t = 0; + if (CURPRAGMA(cl, PRAGMA_TESTMODE)) + { + /* in test mode, terminate the line here so we don't affect the parsers */ + /* (cl -> ltext retains the full, unmodified string) */ + char *t = strstr(p1, ";."); + if (t) *t = 0; } // look up operation code @@ -371,10 +377,23 @@ else cl -> dlen = cl -> len; } - if (*p1 && !isspace(*p1) && !(cl -> err)) + if (!CURPRAGMA(cl, PRAGMA_NEWSOURCE)) { - // flag bad operand error - lwasm_register_error2(as, cl, E_OPERAND_BAD, "(%s)", p1); + if (*p1 && !isspace(*p1) && !(cl -> err)) + { + // flag bad operand error + lwasm_register_error2(as, cl, E_OPERAND_BAD, "(%s)", p1); + } + } + else + { + lwasm_skip_to_next_token(cl, &p1); + /* if we did not hit the end of the line and we aren't at a comment character, error out */ + if (*p1 && *p1 != ';' && *p1 != '#' && *p1 != ';') + { + // flag bad operand error + lwasm_register_error2(as, cl, E_OPERAND_BAD, "%s", p1); + } } /* do a reduction on the line expressions to avoid carrying excessive expression baggage if not needed */