c3lang / c3c

Compiler for the C3 language
https://c3-lang.org
GNU Lesser General Public License v3.0
2.95k stars 181 forks source link

Some fixes/improvements to grammar.y/c3.l and a test script #1443

Closed mingodad closed 1 month ago

mingodad commented 1 month ago

It seems that the grammar.y is out of sync again.

See attached my fixes/changes/improvements (mainly making it reentrant and fixing import_paths rule) and a script to test it over all .c3 files in this repository. Here are some of the failures:

...
../../../c3c/build/lib/std/core/builtin.c3:146:48:
                                               ^
     syntax error, unexpected '(', expecting '['
 -> yyparse return 1
../../../c3c/build/lib/std/core/builtin_comparison.c3:100:23:
                      ^
syntax error, unexpected '(', expecting '['
 -> yyparse return 1
...
../../../c3c/build/lib/std/core/string.c3:37:26:
                         ^
syntax error, unexpected '(', expecting '['
 -> yyparse return 1
...
../../../c3c/build/lib/std/core/types.c3:192:21:
                    ^
syntax error, unexpected '(', expecting '['
 -> yyparse return 1
...
../../../c3c/build/lib/std/math/math.c3:357:22:
                     ^
syntax error, unexpected '(', expecting '['
 -> yyparse return 1
...
../../../c3c/build/lib/std/net/inetaddr.c3:7:13:
            ^
syntax error, unexpected '(', expecting '}'
 -> yyparse return 1
...
../../../c3c/build/lib/std/net/socket.c3:87:11:
          ^
syntax error, unexpected '(', expecting '}'
 -> yyparse return 1
...
../../../c3c/lib/std/core/builtin.c3:110:48:
                                               ^
     syntax error, unexpected ')', expecting '['
 -> yyparse return 1
...
../../../c3c/lib/std/core/string.c3:4:36:
                                   ^
syntax error, unexpected ')', expecting IDENT or CT_IDENT
 -> yyparse return 1
...
../../../c3c/resources/examples/contextfree/dynscope.c3:22:25:
                        ^
syntax error, unexpected ')', expecting '['
 -> yyparse return 1
...

mygrammar.zip

lerno commented 1 month ago

Hello, see if it works now.

mingodad commented 1 month ago

Thank you for reply ! Would be nice if you could add the script to test attached above and also the changes to make re-entrant and easier to use with the test script. It's still failing in some files (see bellow I've added the offending line) but probably it's code that need to be updated:

../../../c3c/build/lib/std/core/builtin.c3:146:48:
                                               ^
     syntax error, unexpected '(', expecting ')'
 -> yyparse return 1
==  panicf(string, $$FILE, $$FUNC, $$LINE, $vasplat());
...
../../../c3c/build/lib/std/core/builtin_comparison.c3:100:23:
                      ^
syntax error, unexpected '(', expecting '['
 -> yyparse return 1
==      return less(x, $vaarg(0)) ? x : $vaarg(0);
...
../../../c3c/build/lib/std/core/string.c3:37:26:
                         ^
syntax error, unexpected '(', expecting ')'
 -> yyparse return 1
==  str.appendf(fmt, $vasplat());
...
../../../c3c/build/lib/std/core/types.c3:192:21:
                    ^
syntax error, unexpected '(', expecting '['
 -> yyparse return 1
==      $if @typeid($vaexpr($i)) != $type_a:
...
../../../c3c/build/lib/std/math/math.c3:357:22:
                     ^
syntax error, unexpected '(', expecting '['
 -> yyparse return 1
==          m = $$max(m, $vaarg($i));
...
../../../c3c/build/lib/std/net/inetaddr.c3:7:13:
            ^
syntax error, unexpected '(', expecting '}'
 -> yyparse return 1
==  UNSPECIFIED (os::AF_UNSPEC),
...
../../../c3c/build/lib/std/net/socket.c3:87:11:
          ^
syntax error, unexpected '(', expecting '}'
 -> yyparse return 1
==  REUSEADDR (os::SO_REUSEADDR),
...
mingodad commented 1 month ago

Also it seems that CT_CONCAT_OP doesn't have a defined rule:

../../../c3c/test/test_suite/compile_time/concat_test_cases.c3:3:25:
                        ^
syntax error, unexpected CT_CONCAT_OP, expecting ';'
 -> yyparse return 1
==  var $x = int[2]{ 1, 2 } +++ int[2]{ 4, 5 };
lerno commented 1 month ago

Fixed and I integrated the script as well.

mingodad commented 1 month ago

Thank you again ! Now fix/update the code that is shown with errors when running the script that parse all .c3 files is the remaining issue here.

mingodad commented 1 month ago

Also why don't expose the c3c lexer/parser in the lib.std.core ? Like go does here https://pkg.go.dev/go/parser@go1.23.1 https://pkg.go.dev/go/scanner@go1.23.1

lerno commented 1 month ago

The only errors I found were the ones from tests that were supposed to fail. Did you find any other?

mingodad commented 1 month ago

When you run the script that parses .c3 files using the c3.l/grammar.y don't you get the errors shown here https://github.com/c3lang/c3c/issues/1443#issuecomment-2351079735 ?

lerno commented 1 month ago

No, those look like they're failing on the old stdlib. The latest grammar will not accept deprecated syntax.

mingodad commented 1 month ago

Oops ! My fault I didn't noticed that ../../../c3c/build/lib/std/core/ was an old local folder created by me, sorry !

lerno commented 1 month ago

Is everything looking good now then?

mingodad commented 1 month ago

Yes, it's working as expected ! Thank you ! Please consider exposing the lexer/parser in lib/std.

lerno commented 1 month ago

The c3c lexer is written in C so that's why it's not in the stdlib.

mingodad commented 1 month ago

But it can be exposed as a wrapper around It.

lerno commented 1 month ago

It's not a library, it's tightly integrated with the compiler when it comes to memory management in particular.