From e95bd8bc00cf51c1cab5cc00a03e8ff3812ca2dc Mon Sep 17 00:00:00 2001 From: David Schmenk Date: Thu, 6 Nov 2014 10:09:47 -0800 Subject: [PATCH] Allow array declaration to follow type, before identifier --- src/samplesrc/sieve.pla | 4 ++-- src/samplesrc/test.pla | 18 ++++++++++-------- src/toolsrc/parse.c | 13 ++++++++++++- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/samplesrc/sieve.pla b/src/samplesrc/sieve.pla index 3a8bba0..1ed589c 100644 --- a/src/samplesrc/sieve.pla +++ b/src/samplesrc/sieve.pla @@ -40,8 +40,8 @@ for iter = 1 to 10 k = k + prime loop count = count + 1 - ;puti(prime) - ;putln + // puti(prime) + // putln fin next next diff --git a/src/samplesrc/test.pla b/src/samplesrc/test.pla index 62a0fa5..e275efb 100755 --- a/src/samplesrc/test.pla +++ b/src/samplesrc/test.pla @@ -5,17 +5,19 @@ include(stdlib.plh) include(testlib.plh) // // Declare all global variables for this module. +// Note that arrays are declared with prefix []. postfix [], or no []. +// Only arrays with predclared sizes need [ and ], such as "int[3] a". // -byte hello[] = "Hello, Apple " -byte a1[] = "1" -byte a2[] = "][" -byte a2p[] = "][+" -byte a2e[] = "//e" -byte a2c[] = "//c" -byte a3[] = "///" +byte[] hello = "Hello, Apple " +byte[] a1 = "1" +byte[] a2 = "][" +byte[] a2p = "][+" +byte[] a2e = "//e" +byte[] a2c = "//c" +byte[] a3 = "///" word struct[] = 1, 10, 100, 1000, 10000 word ptr -byte spaces[] = " " +byte spaces = " " // // Define functions. // diff --git a/src/toolsrc/parse.c b/src/toolsrc/parse.c index 93d56da..5abbe7a 100755 --- a/src/toolsrc/parse.c +++ b/src/toolsrc/parse.c @@ -983,7 +983,18 @@ int parse_var(int type) int consttype, constsize, arraysize, idlen = 0; long size = 1; - if (scan() == ID_TOKEN) + if (scan() == OPEN_BRACKET_TOKEN) + { + size = 0; + parse_constexpr(&size, &constsize); + if (scantoken != CLOSE_BRACKET_TOKEN) + { + parse_error("Missing closing bracket"); + return (0); + } + scan(); + } + if (scantoken == ID_TOKEN) { idstr = tokenstr; idlen = tokenlen;