Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax error, got an unexpected keyword when use -transpile #132

Closed
k1gs opened this issue Dec 30, 2024 · 6 comments
Closed

Syntax error, got an unexpected keyword when use -transpile #132

k1gs opened this issue Dec 30, 2024 · 6 comments

Comments

@k1gs
Copy link

k1gs commented Dec 30, 2024

When i try to use "-transpile" to my .HC file i got that message:

➜ ~hcc -transpile main.HC

info: Previous line was
 --> /usr/local/include/tos.HH:1
     |
   1 |    * All prototypes and classes for all functions and classes provided
     |
 --> /usr/local/include/tos.HH:34:1
     |
  34 |    public class List;
     |    ^^^^^^
     

@Jamesbarford
Copy link
Owner

I'm not able to recreate this, what version are you using (run hcc --version)?

@k1gs
Copy link
Author

k1gs commented Jan 1, 2025

I'm not able to recreate this, what version are you using (run hcc --version)?

HolyC Compiler 2024. beta-v0.0.7 UNSTABLE

@Jamesbarford
Copy link
Owner

May you please try with the latest version? I suspect it possibly has been fixed, and due to the compiler being unstable, rightly or wrongly, I am not supporting any previous versions

@k1gs
Copy link
Author

k1gs commented Jan 2, 2025

the problem remained even after I built the new version.

cmake -S ./src \ -B ./build \ -G 'Unix Makefiles' \ -DCMAKE_C_COMPILER=gcc \ -DCMAKE_BUILD_TYPE=Release \ -DCMAKE_INSTALL_PREFIX=/usr/local \ -DCMAKE_C_FLAGS='-Wextra -Wall -Wno-implicit-fallthrough' \ && make -C ./build -j2 -- The C compiler identification is GNU 14.2.1 -- The CXX compiler identification is GNU 14.2.1 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/sbin/gcc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/sbin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done (3.0s) -- Generating done (0.0s) -- Build files have been written to: /home//holyc-lang/build make[1]: Entering directory '/home/k1gs/holyc-lang/build' [ 11%] Building C object CMakeFiles/hcc.dir/aostr.c.o [ 11%] Building C object CMakeFiles/hcc.dir/ast.c.o [ 16%] Building C object CMakeFiles/hcc.dir/cctrl.c.o [ 22%] Building C object CMakeFiles/hcc.dir/cfg-print.c.o [ 27%] Building C object CMakeFiles/hcc.dir/cfg.c.o [ 33%] Building C object CMakeFiles/hcc.dir/compile.c.o [ 38%] Building C object CMakeFiles/hcc.dir/lexer.c.o [ 44%] Building C object CMakeFiles/hcc.dir/list.c.o [ 50%] Building C object CMakeFiles/hcc.dir/main.c.o [ 55%] Building C object CMakeFiles/hcc.dir/map.c.o [ 61%] Building C object CMakeFiles/hcc.dir/memory.c.o [ 66%] Building C object CMakeFiles/hcc.dir/parser.c.o [ 72%] Building C object CMakeFiles/hcc.dir/prsasm.c.o [ 77%] Building C object CMakeFiles/hcc.dir/prslib.c.o [ 83%] Building C object CMakeFiles/hcc.dir/prsutil.c.o [ 88%] Building C object CMakeFiles/hcc.dir/transpiler.c.o [ 94%] Building C object CMakeFiles/hcc.dir/x86.c.o [100%] Linking C executable /home//holyc-lang/hcc [100%] Built target hcc

info: Previous line was --> /usr/local/include/tos.HH:1 | 1 | * All prototypes and classes for all functions and classes provided | error: Syntax error, got an unexpected keyword public, perhaps you meant ;? --> /usr/local/include/tos.HH:34:1 | 34 | public class List; | ^^^^^^

@Jamesbarford
Copy link
Owner

Jamesbarford commented Jan 2, 2025

Interesting. I think the error handling when transpiling is broken, I've observed something similar with the below example (which I'm putting here as a note to self so I can re-create it) that reports something completely incorrect.

Does your code compile with hcc ./main.HC ? I ask as that error reporting does look to be working correctly when compiling and I'm not sure when I can dive into this problem.

Example

Re-creatable problem:

code

U0 Main()
{
  "hello world\n" // < missed off ';'
}

error:

Wrong file reported:

info: Function call `printf` not terminated correctly
 --> /usr/local/include/tos.HH:4
     |
   4 |    * JSON might be easier to maintain than this ever growing header file */
     |
error: Invalid character `}` while parsing function call, perhaps you meant to terminate the arguments with `)` or keep going with `,`?
 --> /usr/local/include/tos.HH:4
     |
   4 |    * JSON might be easier to maintain than this ever growing header file */
     |

@k1gs
Copy link
Author

k1gs commented Jan 2, 2025

Thanks a lot for support. Now -transpile and compiling are works!
I couldn't figure out what the problem was, so I decided to rebuild the hcc again and everything worked. Thanks again for the support!

  • ~cat main.HC
    U0 Main()
    {
    "hello world\n";
    }

  • ~hcc -transpile main.HC
    /* This code has been automatically generated by running:

  • hcc -transpile main.HC

`#include <arpa/inet.h>
#include <dirent.h>
#include <fcntl.h>
#include <math.h>
#include <netdb.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h>

typedef union __atomic_wide_counter {
unsigned long __value64;
struct {
unsigned int __low;
unsigned int __high;
};
} __atomic_wide_counter;

int
main(void)
{
printf("hello world\n");
}

*~ hcc -o main main.HC
./main
hello world

@k1gs k1gs closed this as completed Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants