]> ocean-lang.org Git - ocean/log
ocean
2 years agooceani: perform analysis before printing
NeilBrown [Sun, 7 Nov 2021 00:28:04 +0000 (11:28 +1100)]
oceani: perform analysis before printing

This will allow information attached during analysis to
be printed out as comments.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add an 'interp' case for Func
NeilBrown [Sun, 7 Nov 2021 00:04:34 +0000 (11:04 +1100)]
oceani: add an 'interp' case for Func

For Func we jut call interp_exec on b->right.
This ensures that interp_exec() gets called on each exec, so
it can do cleanup (in future patch).

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: create separate scope for do part of while
NeilBrown [Sat, 6 Nov 2021 23:59:23 +0000 (10:59 +1100)]
oceani: create separate scope for do part of while

Any variables created in the do part won't be created in the final
iteration, so we want them to be constrained to the do part, not seen as
part of the whole loop body.
This makes while/do match if/then better.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: create a separate 'exec' for the while/do part
NeilBrown [Sat, 6 Nov 2021 22:20:05 +0000 (09:20 +1100)]
oceani: create a separate 'exec' for the while/do part

As while/do is a sub-scope within a cond-statement, create a separate
'struct exec' for it (a binode/Loop) so there is an exec for each scope.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move var_block_close() calls to the code sections that close the block
NeilBrown [Sat, 6 Nov 2021 02:04:54 +0000 (13:04 +1100)]
oceani: move var_block_close() calls to the code sections that close the block

Rather than calling var_block_close() from common non-terminals, move
the calls into the body of the parent non-terminal.  This places them
after the 'struct exec' which represents the scope has been created.

This is needed to attach the variables to the point where their scope is
closed, so they can be freed.

This change helped me focus on some untested - and broken - code.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: fix up the while/do scope
NeilBrown [Sat, 6 Nov 2021 23:00:29 +0000 (10:00 +1100)]
oceani: fix up the while/do scope

The scope created for while/do does NOT extend into the case/else part.
This is because it is a repeating scope and needs to close and re-open.

We *could* include case/else in the final instance of that scope, but
I'm not at all sure that I want to.  Maybe later.

So close the scope properly and fix up the test code which depends on
the scope being extended.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: change variable.merged to never be NULL
NeilBrown [Sat, 6 Nov 2021 01:17:13 +0000 (12:17 +1100)]
oceani: change variable.merged to never be NULL

variable.merged is now always the primary variable, so it is initialised
to the address of the variable itself.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: simplify loop in var_block_close()
NeilBrown [Fri, 5 Nov 2021 23:55:01 +0000 (10:55 +1100)]
oceani: simplify loop in var_block_close()

The 'step' was not in the 'for' header, which makes it harder to follow
how the loop works.
Also add a comment to explain where is happening when ->name->var != v.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: simplify test in var_block_close.
NeilBrown [Fri, 5 Nov 2021 23:30:34 +0000 (10:30 +1100)]
oceani: simplify test in var_block_close.

v->depth is never less than v->min_depth, so checking that
both exceed ->scope_depth is pointless, only test ->min_depth.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add lots of UNTESTED markers.
NeilBrown [Wed, 3 Nov 2021 02:08:45 +0000 (13:08 +1100)]
oceani: add lots of UNTESTED markers.

These serve to remind me what needs testing (or marking NOTEST), and
will make it easier to notice when new untested code is added.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: var storage needs to be free last
NeilBrown [Wed, 3 Nov 2021 01:52:08 +0000 (12:52 +1100)]
oceani: var storage needs to be free last

As type may store initializers in storage, but these might not get into
the var list in an error, we need to free that storage last.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: continue to improve test coverage
NeilBrown [Wed, 3 Nov 2021 01:29:34 +0000 (12:29 +1100)]
oceani-tests: continue to improve test coverage

Add a couple of error tests, and mark some code as NOTEST

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: add some NOTEST markings.
NeilBrown [Wed, 3 Nov 2021 01:05:51 +0000 (12:05 +1100)]
oceani-tests: add some NOTEST markings.

These lines don't need to be tested.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agomark-untested: improve filter
NeilBrown [Wed, 3 Nov 2021 01:01:17 +0000 (12:01 +1100)]
mark-untested: improve filter

Don't add the mark for any section lines.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add test for duplicate main functions
NeilBrown [Wed, 3 Nov 2021 00:57:01 +0000 (11:57 +1100)]
oceani: add test for duplicate main functions

Add a test so the check for duplicate main functions gets exercised.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: drop "program" in favour of "func"
NeilBrown [Wed, 3 Nov 2021 00:46:54 +0000 (11:46 +1100)]
oceani: drop "program" in favour of "func"

Being to introduce functions.  Currently only the 'main' function which
receives an array of strings.
This array has a variable size.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: add test for declaring a CondScope variable
NeilBrown [Sat, 30 Oct 2021 04:49:08 +0000 (15:49 +1100)]
oceani-tests: add test for declaring a CondScope variable

If a variable was declared in all branches of a structures command, it
may or may not be declared as something else afterwards.
We need to test both options.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: add test for unknown field name.
NeilBrown [Sat, 30 Oct 2021 04:25:40 +0000 (15:25 +1100)]
oceani-tests: add test for unknown field name.

Test that we get error if unknown field is requested.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: improve test coverage
NeilBrown [Sat, 30 Oct 2021 04:19:39 +0000 (15:19 +1100)]
oceani: improve test coverage

Add a tool 'mark-untest' which adds comments to untested lines.
Then resolve some of them, either adding more tests, or marking
lines as NOTEST

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani-tests: make it possible to skip valgrind tests.
NeilBrown [Sat, 30 Oct 2021 04:00:03 +0000 (15:00 +1100)]
oceani-tests: make it possible to skip valgrind tests.

valgrind tests are slow and not always wanted, particilarly when
examining coverage.  So make it easy to skip them.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoocean: change program to receive argc and argv
NeilBrown [Sat, 30 Oct 2021 03:23:46 +0000 (14:23 +1100)]
ocean: change program to receive argc and argv

Rather than a list of strings, a "program" now receives and arg count,
and an array of strings with that size.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move variable values to a stack frame.
NeilBrown [Sun, 17 Oct 2021 10:03:01 +0000 (21:03 +1100)]
oceani: move variable values to a stack frame.

We have two frames - one for global values (currently always constant)
and one for local variables.
When we get functions, the local variable frame will be managed with a
stack of frames.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: fix some incorrect section headers.
NeilBrown [Sun, 17 Oct 2021 09:29:16 +0000 (20:29 +1100)]
oceani: fix some incorrect section headers.

section header that just introduce code are 6 deep, not 2.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: clean up interp_prog()
NeilBrown [Sun, 17 Oct 2021 02:45:18 +0000 (13:45 +1100)]
oceani: clean up interp_prog()

In particular, use dup_value() to save the command arguments.
But also re-arrange code to make steps a bit cleaner.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: add parse_context arg to all interp functions, and a few others.
NeilBrown [Sun, 17 Oct 2021 02:35:58 +0000 (13:35 +1100)]
oceani: add parse_context arg to all interp functions, and a few others.

When I switch variables to use a stack frame, I'll need the
parse_context available more broadly (as it will hold the stack).
So add it to a selection of functions now.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: differentiate static-sized arrays from others.
NeilBrown [Sat, 16 Oct 2021 05:58:42 +0000 (16:58 +1100)]
oceani: differentiate static-sized arrays from others.

Some arrays will always have the same size - a static size.
Others might have a different size each time their scope is entered, if
the size is calculates from a variable.

The latter need to be reallocated whenever scope is entered, the former
do not.

This will matter when we create call frames to be able to handle
recursion.

So detect and handle the difference now.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: don't allocate init value for non-initialized fields.
NeilBrown [Sat, 16 Oct 2021 05:27:41 +0000 (16:27 +1100)]
oceani: don't allocate init value for non-initialized fields.

Struct fields that aren't explicitly initialised must be initialized to
a 'null' value.  This can happen at interp-time.  There is no need to
allocate a null value when parsing.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: implement struct field initialisation properly.
NeilBrown [Sat, 16 Oct 2021 05:09:59 +0000 (16:09 +1100)]
oceani: implement struct field initialisation properly.

I wasn't testing default initial values for struct fields, so of course
it didn't work.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: move ->prepare_type call (back) into val_alloc()
NeilBrown [Thu, 14 Oct 2021 02:59:34 +0000 (13:59 +1100)]
oceani: move ->prepare_type call (back) into val_alloc()

This ensures it is called for struct fields as well.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: handle variable-sized arrays better.
NeilBrown [Thu, 14 Oct 2021 02:43:02 +0000 (13:43 +1100)]
oceani: handle variable-sized arrays better.

An array with size set by a constant variable(!) might have a different
size each time the declaration is encountered.  So we need to
re-evaluate the size each time.
We currently re-evaluate the size only if it is zero.

So for numerical-constant sized arrays, evaluate size during parsing.
For other arrays, re-evaulate each time using a new prepare_type method.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: fix a couple of issues
NeilBrown [Tue, 12 Oct 2021 10:28:47 +0000 (21:28 +1100)]
oceani: fix a couple of issues

1/ when a variable declared in a loop was re-initialized, we didn't free
   the old value before allocating a new one.
2/ When assigning to an out-of-bounds array index, created an rval,
   but never freed it.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani - discard anon_typelist
NeilBrown [Sat, 9 Oct 2021 21:14:04 +0000 (08:14 +1100)]
oceani - discard anon_typelist

Don't keep anon types on a separate list, use the same list but given
them an empty name.

This allows us to use add_type() for adding all types.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: drop 'array' field from the 'value' union.
NeilBrown [Sat, 9 Oct 2021 01:05:51 +0000 (12:05 +1100)]
oceani: drop 'array' field from the 'value' union.

This field was never used - we use the generic 'ptr'.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoparsergen: require all terms to be declared if any are.
NeilBrown [Thu, 7 Oct 2021 00:13:44 +0000 (11:13 +1100)]
parsergen: require all terms to be declared if any are.

The previous implementation only required all terms used for the first
time after a $TERM declaration to be declared.  That isn't really
useful.

So change it to only set the default symbol type of Term after all the
grammar is parsed, and then only if not $TERM declarations were found.

This highlights that various terminals in ocean weren't declared, so
declare them now.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: drop parse_value method for types.
NeilBrown [Sat, 2 Oct 2021 22:57:40 +0000 (09:57 +1100)]
oceani: drop parse_value method for types.

The args to 'program' are now all strings.  The program itself needs to
convert to numbers etc as needed.
So we don't need 'parse_value' any more.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agoocean: introduce prefix op for string->number conversion.
NeilBrown [Sat, 2 Oct 2021 22:36:50 +0000 (09:36 +1100)]
ocean: introduce prefix op for string->number conversion.

Rather than having magic conversion of command line args to numbers as
needed, introduce '$' as a prefix op to to the conversion.
This is a step towards changing 'program' to be a 'main' function.

Signed-off-by: NeilBrown <neil@brown.name>
2 years agooceani: separate types out from values
NeilBrown [Wed, 29 Sep 2021 22:21:15 +0000 (08:21 +1000)]
oceani: separate types out from values

Rather than embed the type in ever value, keep it separate.
This allows arrays without duplicating the member-type information.

Also review and clean up the commentary.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: add missing {}
NeilBrown [Tue, 6 Apr 2021 22:02:20 +0000 (08:02 +1000)]
parsergen: add missing {}

These have ALWAYS been missing, yet the code mostly worked.  Weird.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: doco updates
NeilBrown [Wed, 10 Mar 2021 05:14:20 +0000 (16:14 +1100)]
parsergen: doco updates

Minor revision to descriptive text following all the recent changes.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: don't bother with indent_depth
NeilBrown [Wed, 10 Mar 2021 04:26:59 +0000 (15:26 +1100)]
parsergen: don't bother with indent_depth

We don't need to store the indent_depth if we just shift the bit-stack
up and down.  <<1 pushes a zero, >>1 pops, |=1 changes the zero to one.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agooceani: updates for new approach to parsing indents.
NeilBrown [Wed, 10 Mar 2021 01:37:46 +0000 (12:37 +1100)]
oceani: updates for new approach to parsing indents.

Now that IN is a valid stand-alone token, it makes sense to change the
grammar for ocean.
We don't need the ':' before an indent if there is some other terminal
there.  So:

  while
     statements
  do
     statements

doesn't require any ':'.
We use the ':' to separate an expression from following statements,
in 'if' and 'while' and 'case'.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoUpdate indent_test grammer to align with new approach
NeilBrown [Wed, 10 Mar 2021 01:13:05 +0000 (12:13 +1100)]
Update indent_test grammer to align with new approach

Indents are now now handled very differently.  Update itest
grammar to match.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: add support for EOL token
NeilBrown [Wed, 10 Mar 2021 00:49:24 +0000 (11:49 +1100)]
parsergen: add support for EOL token

And EOL token is generated when a NEWLINE is found and an EOL can be
shifted.  This allows a product to declare that it must finish at the
end of a line, without consuming the NEWLINE.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: implement new handling of IN/OUT and NEWLINE
NeilBrown [Wed, 10 Mar 2021 00:38:55 +0000 (11:38 +1100)]
parsergen: implement new handling of IN/OUT and NEWLINE

IN/OUT are now expected in the grammar.
In a state where an IN can be shifted, IN symbols are significant to the
grammar.  IN symbols appearing anywhere else are ignored (except for how
they affect NEWLINEs).

OUT symbols are ignored precisely when the matching IN was ignored.

NEWLINEs are ignored if the most recent IN was ignored, otherwise they
are significant for the grammar.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: split out heart-of-the-parser code
NeilBrown [Wed, 10 Mar 2021 00:12:50 +0000 (11:12 +1100)]
parsergen: split out heart-of-the-parser code

This finishes the break up of the core parser code.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: split out the "shift or ignore" section of parsing.
NeilBrown [Wed, 10 Mar 2021 00:00:23 +0000 (11:00 +1100)]
parsergen: split out the "shift or ignore" section of parsing.

This will make it easier to document.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: split out reduce step of parser
NeilBrown [Tue, 9 Mar 2021 23:56:15 +0000 (10:56 +1100)]
parsergen: split out reduce step of parser

Split out the "reduce" code so it can be more easily documented.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: split out error handling.
NeilBrown [Tue, 9 Mar 2021 23:51:19 +0000 (10:51 +1100)]
parsergen: split out error handling.

I want to split up the core parsing into the different parts so they can
be documented better.
Firstly: split out error handling.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: add support for "special" terminals.
NeilBrown [Fri, 5 Mar 2021 10:24:14 +0000 (21:24 +1100)]
parsergen: add support for "special" terminals.

We will want a new terminal "EOL", which is like "NEWLINE", but
different.  There is currently no room in the numbering for something
like that, so make some room.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: remove special case of newline conflicts
NeilBrown [Fri, 5 Mar 2021 10:26:55 +0000 (21:26 +1100)]
parsergen: remove special case of newline conflicts

newlines are no longer interesting in avoiding conflicts, so remove the
special case handling.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: remove tracking of indents and line starts etc.
NeilBrown [Fri, 5 Mar 2021 10:01:17 +0000 (21:01 +1100)]
parsergen: remove tracking of indents and line starts etc.

We will want some of this back, but in a very different form.
So remove it all for now.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: remove newline_only
NeilBrown [Fri, 5 Mar 2021 09:41:47 +0000 (20:41 +1100)]
parsergen: remove newline_only

newline_only is not wanted any more.  It wasn't being set anyway.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: remove starts_line and min_prefix
NeilBrown [Fri, 5 Mar 2021 09:37:34 +0000 (20:37 +1100)]
parsergen: remove starts_line and min_prefix

Neither of these are wanted any more.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: remove line_like information.
NeilBrown [Fri, 5 Mar 2021 09:31:32 +0000 (20:31 +1100)]
parsergen: remove line_like information.

I'm going to change the 2D nature of the parser over several patches.
First I remove what I don't want, then I add what I do.
During this series, tests won't work!

First: line_like nad relate code is removed.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: don't use static buffer for result value.
NeilBrown [Fri, 26 Feb 2021 06:33:43 +0000 (17:33 +1100)]
parsergen: don't use static buffer for result value.

Add the size of the result value to the per-state information, so it can
be allocated before calling do_reduce(), thus removing the need for a
overly large static buffer.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: do not create empty goto arrays
NeilBrown [Wed, 24 Feb 2021 08:57:08 +0000 (19:57 +1100)]
parsergen: do not create empty goto arrays

These empty arrays are a waste of space ...  assuming they take up
any(?).

Using NULL is more ideomatic.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparergen: fix bug in deriving itemsets
NeilBrown [Fri, 5 Mar 2021 10:17:51 +0000 (21:17 +1100)]
parergen: fix bug in deriving itemsets

The code to check if an item had already been added, was wrong.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: make "code" arg to "gen_reduce" more obvious.
NeilBrown [Fri, 5 Mar 2021 10:29:56 +0000 (21:29 +1100)]
parsergen: make "code" arg to "gen_reduce" more obvious.

Call it "pre_reduce" so we know where the code goes.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: improve usage message
NeilBrown [Fri, 5 Mar 2021 10:30:54 +0000 (21:30 +1100)]
parsergen: improve usage message

Now usage message is slightly better.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agooceani: add missing space in usage message.
NeilBrown [Fri, 5 Mar 2021 22:15:06 +0000 (09:15 +1100)]
oceani: add missing space in usage message.

Wrapping long strings is a bad idea anyway.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: fix some problems with choose_sym()
NeilBrown [Fri, 5 Mar 2021 09:20:36 +0000 (20:20 +1100)]
parsergen: fix some problems with choose_sym()

This would sometimes give wrong result, particularly bad when it is
larger than body_size.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: move the 'follow' declaration
NeilBrown [Fri, 5 Mar 2021 09:18:14 +0000 (20:18 +1100)]
parsergen: move the 'follow' declaration

The 'follow' field is currently used before declared, which is poor
form.  Move it.

Also remove a stray '## functions' section that is redundant.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: move "Memory allocation" section.
NeilBrown [Fri, 5 Mar 2021 09:16:22 +0000 (20:16 +1100)]
parsergen: move "Memory allocation" section.

This movement isn't really significant yet, but it will help a bit
later, and I want to get it out of the way.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: some missing 'free' calls.
NeilBrown [Fri, 5 Mar 2021 09:14:29 +0000 (20:14 +1100)]
parsergen: some missing 'free' calls.

Well... one missing call, and some places were we need to do something a
bit more.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: change 'again' to 'check_again'.
NeilBrown [Fri, 5 Mar 2021 09:11:04 +0000 (20:11 +1100)]
parsergen: change 'again' to 'check_again'.

Sometimes I use 'again', sometimes 'check_again'.
Change all to use 'check_again'.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: assorted updates to descriptive text.
NeilBrown [Fri, 5 Mar 2021 09:07:55 +0000 (20:07 +1100)]
parsergen: assorted updates to descriptive text.

Some of these are fixed for typos or poor grammar.  Others update the
text to more closely match the code.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen.mdc: remove tracking of left-recursive symbols.
NeilBrown [Fri, 5 Mar 2021 08:24:11 +0000 (19:24 +1100)]
parsergen.mdc: remove tracking of left-recursive symbols.

left-recursive symbols are no longer interesting, so remove the code and
descriptions.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: guard against tos going negative.
NeilBrown [Wed, 10 Mar 2021 00:58:08 +0000 (11:58 +1100)]
parsergen: guard against tos going negative.

Don't continue the parse loop if tos hits zero.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: change how reserved_words are stored
NeilBrown [Fri, 5 Mar 2021 08:20:22 +0000 (19:20 +1100)]
parsergen: change how reserved_words are stored

Rather than a simple array with holes, have a dense array mapping number
to name.  This will enable a future change which adds names that don't
have numbers assigned.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: rename item_index() to item_dot()
NeilBrown [Fri, 5 Mar 2021 08:17:27 +0000 (19:17 +1100)]
parsergen: rename item_index() to item_dot()

The name "dot" fits better with documentation which described the nature
of an "item" when generating LR parsing tables.

Also change the arg to item_num() from 'index' to 'dot'.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agotests: restore coverage testing.
NeilBrown [Fri, 5 Mar 2021 08:04:45 +0000 (19:04 +1100)]
tests: restore coverage testing.

I don't know what changed, but coverage testing stopped working.
Fixed now.

Also add some "|| exit 1" to fail quickly when needed.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoindent-test: enhance the tests a bit.
NeilBrown [Fri, 5 Mar 2021 08:00:52 +0000 (19:00 +1100)]
indent-test: enhance the tests a bit.

In particular, test for "else" both indented and unindented.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoindent-test: minor improvements:
NeilBrown [Fri, 5 Mar 2021 07:58:10 +0000 (18:58 +1100)]
indent-test: minor improvements:

1/ add rule to build itest.code

2/ diffs now display correct as "old" and generated as "new"

3/ remove some noise that should never have been there.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: add more power to symbol references in generated code
NeilBrown [Sun, 11 Oct 2020 03:49:07 +0000 (14:49 +1100)]
parsergen: add more power to symbol references in generated code

As well as symbol references like "$2", you can now use references
with letters like "$Ss".  This will find the shortest symbol in the
production that contains all the given letters in the given order.
There must be a unique shortest symbol.

If that same symbol occurs multiple times, later instances can be given
with a numeric suffix such as "$Ss2".

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: update description of $<N
NeilBrown [Sun, 11 Oct 2020 01:18:57 +0000 (12:18 +1100)]
parsergen: update description of $<N

This applies to structures as well as pointers.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: allow terminals to be declared.
NeilBrown [Sat, 10 Oct 2020 23:34:06 +0000 (10:34 +1100)]
parsergen: allow terminals to be declared.

By default, any non-virtual symbol that does not appear in the head of a
product is assumed to be a Terminal.
For larger grammars, this misses out of an opportunity to detect errors.
So allow a "$TERM" line to list terminals (that do no appear in
precedence lines).  If any $TERM line is given, then generate error
if any symbol appears in a production but is not declared, either
as terminal or non-terminal.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: avoid infinite loop on error.
NeilBrown [Sat, 10 Oct 2020 22:50:12 +0000 (09:50 +1100)]
parsergen: avoid infinite loop on error.

If the grammar allows "ERROR" in a recursive location, error handling
can loop for every.
e.g.

 foo -> foo bar
 foo -> ERROR

Rather than detect and reject such grammars, detect the infinite loop
as it start, and discard an extra token.

i.e.  if error handling doesn't discard any tokens from the input
stream, and another error is triggered before anything is shifted, then
we force the next error handling phase to discard at least one token,
or to abort if that token is EOF.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsergen: sort virtual symbols to send of list
NeilBrown [Tue, 6 Oct 2020 07:11:15 +0000 (18:11 +1100)]
parsergen: sort virtual symbols to send of list

virtual symbols are used internally to parsergen
and of no interest to the parser.  So they shouldn't
appear in the non_term[] array.

So assign them higher numbers so the nonterminals are dense, and only
include non-virtual non-terminals in the non_term[] array.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoparsegen: detect left-recursive symbols in non-final position.
NeilBrown [Tue, 6 Oct 2020 06:02:22 +0000 (17:02 +1100)]
parsegen: detect left-recursive symbols in non-final position.

A left-recursive symbol that appear other than at the end of a
production causes problem for indent-based parsing, as describe in the
document.  So teach parsergen to be able to report them.

Ocean currently has several of these, which I'll need to look into at a
later date.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoscanner: change the meaning of ignoring comment tokens.
NeilBrown [Tue, 6 Oct 2020 04:44:46 +0000 (15:44 +1100)]
scanner: change the meaning of ignoring comment tokens.

Previously ignoring comment tokens meant they were still parsed, but not
returned.  The only way to stop them being parsed was to declare
known marks for the start symbols.

This made is not possible for parsergen to define a language that had
a known mark that would otherwise start a comment.

So change the ignoring of comment tokens to mean they aren't parsed.  If
you want to parse comments but not return them, leave the new
"return_comments" field as so.  In the unusual case that you want to
return comments set return_comments to 1.

Confirm that this has the desired effect by added in "//" as an
integer-division operator to the sample calculator.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoindent_test: fix makefile
NeilBrown [Mon, 5 Oct 2020 23:00:31 +0000 (10:00 +1100)]
indent_test: fix makefile

Maybe 'make' has changed a little to be less forgiving, but 'make itest'
isn't working now.  All of LDLIBS are included in the 'cc' line, but
there are no dependencies to make sure they have been built.

The problem is that I'm using LDLIBS for different programs which need
different libs.  This isn't such a good idea.
So change indent_test to use itestLDLIBS and itestCFLAGS.

Signed-off-by: NeilBrown <neil@brown.name>
3 years agoRename string.h and number.h headers
NeilBrown [Fri, 11 Sep 2020 07:53:49 +0000 (17:53 +1000)]
Rename string.h and number.h headers

Having a "string.h" is potentially confusing as there
is a standard <string.h>
So rename it and for consistency, rename number.h too.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoparsergen: add token location to tracing
NeilBrown [Fri, 28 Jun 2019 09:40:11 +0000 (19:40 +1000)]
parsergen: add token location to tracing

When we print the look-ahead token for tracing, add the line/column
location so it can be easily cross-references to the source code.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoparsergen: only non-terminals should make a state "starts_line"
NeilBrown [Fri, 28 Jun 2019 09:36:49 +0000 (19:36 +1000)]
parsergen: only non-terminals should make a state "starts_line"

If a state is followed by NEWLINE, then it isn't starts_line - more like
ends_line.
It is only non-terminals containing NEWLINEs that cause a state
to be starts_line.
So move the test to after we stop looking at terminals.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agooceani: allow 'then' in simple if statements.
NeilBrown [Sun, 23 Jun 2019 05:37:50 +0000 (15:37 +1000)]
oceani: allow 'then' in simple if statements.

Allow 'then' after "if expression", and don't require a ':' if
it is followed by simple statements.
Similarly "else" doesn't need a colon for simple statements

Signed-off-by: NeilBrown <neil@brown.name>
4 years agooceani: change parsing for ; at end
NeilBrown [Sun, 23 Jun 2019 04:41:47 +0000 (14:41 +1000)]
oceani: change parsing for ; at end

When we have 'for' and 'then' on the same line, I want to
require a ';' for the 'for' (and 'while').
So change SimpleStatemnts to never end with ';', and require
a ; or Newline after each instance of SimpleStatements.

Hmm... I guess that could be abstracted.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agooceani: modify grammar to not waste stack on newlines
NeilBrown [Sun, 23 Jun 2019 04:29:13 +0000 (14:29 +1000)]
oceani: modify grammar to not waste stack on newlines

Current grammar uses one stack frame per newline for leading
newlines as these productions are right-recursive.  This is
unnecessary and inelegant. Change to use a left-recursive Newlines
production.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoindent_test: reduce stack usage for preceding NEWLINEs
NeilBrown [Sun, 23 Jun 2019 03:51:46 +0000 (13:51 +1000)]
indent_test: reduce stack usage for preceding NEWLINEs

In the cases where we allow preceding newlines (Statementlist Open Close)
we current use one parse-stack from for each newline.  While there are
unlikely to be many, this is inelegant.
Change the right-recursive form to use a left-recursive Newlines rule
that absorbs one or more NEWLINEs using at most 2 stack frames.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoparsergen: allow $$OUT to be satisfied are start-of-line.
NeilBrown [Sun, 23 Jun 2019 00:21:14 +0000 (10:21 +1000)]
parsergen: allow $$OUT to be satisfied are start-of-line.

If a $$OUT (or $$NEWLINE) production is being reduced at
start-of-line (with no indents), then that is satisfactory,
we don't need NEWLINE etc as look-ahead.

This means that in cases where this is relevant, the computed
lookahead is wrong - we shouldn't have striped it.
I don't think this matters as it only affects conflict warnings,
and I think these will be reported at a higher level if relevant.
If essense, the $$OUT marking is like a precendence marking which
suppresses shift/reduce warnings as it say that decision is being made
on some basis other than look-ahead.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoparsergen: allow $$OUT as well as $$NEWLINE
NeilBrown [Sat, 22 Jun 2019 23:00:06 +0000 (09:00 +1000)]
parsergen: allow $$OUT as well as $$NEWLINE

Both of these mean the same thing: the product must end
in a 2-d visible way

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoparsergen: don't assume TK_newline in look-ahead for lineline
NeilBrown [Sat, 22 Jun 2019 22:56:15 +0000 (08:56 +1000)]
parsergen: don't assume TK_newline in look-ahead for lineline

A linelike production might not have TK_newline in the look-ahead,
so don't assume it.  If it isn't there, make the look-ahead
set empty.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoparsergen: revert the allowance for "non-critical" conflicts.
NeilBrown [Sun, 16 Jun 2019 02:37:23 +0000 (12:37 +1000)]
parsergen: revert the allowance for "non-critical" conflicts.

Having improved the parsing approach, I don't get any
"non-critical" conflicts any more, and I no longer think
they aren't critical.

Conflicts can often be resolved with precendence if they cannot
be resolved any other way.

So treat all conflict, except shift/reduce on NEWLINE, as genuine
conflicts.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agooceani-tests: add tests with lots of blank lines.
NeilBrown [Sun, 16 Jun 2019 02:34:40 +0000 (12:34 +1000)]
oceani-tests: add tests with lots of blank lines.

This found some problems with the grammer, which I fixed.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agooceani: convert declarations to new approach to newlines
NeilBrown [Sun, 16 Jun 2019 02:16:44 +0000 (12:16 +1000)]
oceani: convert declarations to new approach to newlines

There are now no conflicts.  Yay!!

Signed-off-by: NeilBrown <neil@brown.name>
4 years agooceani: re-indent DeclareStruct
NeilBrown [Sun, 16 Jun 2019 01:37:03 +0000 (11:37 +1000)]
oceani: re-indent DeclareStruct

It wasn't indented to easily allow alternate productions.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agogitignore - add coverage_scanner
NeilBrown [Sun, 16 Jun 2019 01:35:00 +0000 (11:35 +1000)]
gitignore - add coverage_scanner

This is a tmp file - should have been ignored before.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoparsegen: fix up look-ahead for $$NEWLINE items.
NeilBrown [Sun, 16 Jun 2019 01:31:54 +0000 (11:31 +1000)]
parsegen: fix up look-ahead for $$NEWLINE items.

I was discarding all non-newlines from the lookahead
in the wrong place.
I need to do it based on the productions added, not
the item the are generated by.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agooceani: change NEWLINE parsing in statements to new model.
NeilBrown [Sun, 16 Jun 2019 00:16:07 +0000 (10:16 +1000)]
oceani: change NEWLINE parsing in statements to new model.

The new module is:

 A list of line-like things must access a newline first:
  Statementlist -> Statements
                | NEWLINE Statementlist

 Any line-like thing must reduce to a single symbol:
   SimpleStatementLine IfPart WhilePart CasePart etc
 An individual line-like thing must allow following newlines
 e.g.
   IfHead -> if Expression Block
           | IfHead NEWLINE

 A block that can be multi-line or single-line should be marked with
   $$NEWLINE
 This will require a NEWLINE to reduce it, but won't swollow the newline.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoindent_test: adjust grammer to handle blank lines better.
NeilBrown [Sat, 15 Jun 2019 23:47:58 +0000 (09:47 +1000)]
indent_test: adjust grammer to handle blank lines better.

This uses the new $$NEWLINE are other techniques to ensure
blank lines are handled well.
We also test that adding blank lines everywhere doesn't break
anything.

Signed-off-by: NeilBrown <neil@brown.name>
4 years agoident_test: declare precedence for 'else'
NeilBrown [Sat, 15 Jun 2019 23:20:30 +0000 (09:20 +1000)]
ident_test: declare precedence for 'else'

By declaring precedence for 'else', we suppress conflict warnings
Normally newlines and indents will resolve any conflict, but
if not, else associates to the right - it should be shifted, not cause
a reduce (which is the default anyway)

Signed-off-by: NeilBrown <neil@brown.name>