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

Segfault when executing the testsuite #1

Open
mingodad opened this issue Apr 12, 2021 · 5 comments
Open

Segfault when executing the testsuite #1

mingodad opened this issue Apr 12, 2021 · 5 comments

Comments

@mingodad
Copy link

When trying to execute the testsuite CocoR segfault due to have fwprintf format expecting wchar_t* but the parameter is char* see a hack/patch that allow it to execute the testsuite:

--------------------------------- src/Tab.cpp ---------------------------------
index 731ec12..3ae0116 100644
@@ -100,7 +100,7 @@ int Tab::Num(Node *p) {
 
 void Tab::PrintSym(Symbol *sym) {
 	wchar_t *paddedName = Name(sym->name);
-	fwprintf(trace, L"%3d %14s %ls", sym->n, paddedName, nTyp[sym->typ]);
+	fwprintf(trace, L"%3d %14s %s", sym->n, paddedName, nTyp[sym->typ]);
 	coco_string_delete(paddedName);
 
 	if (sym->attrPos==NULL) fwprintf(trace, L" false "); else fwprintf(trace, L" true  ");
@@ -110,7 +110,7 @@ void Tab::PrintSym(Symbol *sym) {
 	} else
 		fwprintf(trace, L"            ");
 
-	fwprintf(trace, L"%5d %ls\n", sym->line, tKind[sym->tokenKind]);
+	fwprintf(trace, L"%5d %s\n", sym->line, tKind[sym->tokenKind]);
 }
 
 void Tab::PrintSymbolTable() {
@@ -343,7 +343,7 @@ void Tab::PrintNodes() {
 	Node *p;
 	for (int i=0; i<nodes->Count; i++) {
 		p = (Node*)((*nodes)[i]);
-		fwprintf(trace, L"%4d %ls ", p->n, (nTyp[p->typ]));
+		fwprintf(trace, L"%4d %s ", p->n, (nTyp[p->typ]));
 		if (p->sym != NULL) {
 			wchar_t *paddedName = Name(p->sym->name);
 			fwprintf(trace, L"%12s ", paddedName);
@mingodad
Copy link
Author

Also there is several memory leaks when executing CocoR see attached the output of valgrind
checkall.sh.valgrind.out.txt.zip
that shows then.

@billyquith
Copy link

WRT wide chars here is a version of Coco-R converted to use char*. Are wide chars really necessary? UTF-8 can be used for localisation?

@mingodad
Copy link
Author

Some grammars like CSharp allow utf-8 identifiers, how would you parser then ?

@billyquith
Copy link

Some grammars like CSharp allow utf-8 identifiers, how would you parser then ?

Yes, the parser would need modifying for that. - I have only used Coco-R in multibyte/char* applications with "ASCII".

Does the parser work for UTF-16 with >1 code per encoding? If not it doesn't support the UTF-16 properly anyway?

@mingodad
Copy link
Author

mingodad commented Jun 3, 2021

I've add a simple AST generation and fixes several memory leaks (still there is others) and would be nice if someone could try it and give feedback, it's based on the implementation done here https://github.com/rochus-keller/EbnfStudio.

Here is the skeleton to try it:

../Coco -frames .. gmpl2sql.atg
g++ -g -Wall -DPARSER_WITH_AST -o gmpl2sql Parser.cpp Scanner.cpp gmpl2sql.cpp
#include "Parser.h"
#include "Scanner.h"

using namespace Gmpl2Sql;

int main (int argc, char *argv[]) {

	if (argc == 2) {
		wchar_t *fileName = coco_string_create(argv[1]);
		Gmpl2Sql::Scanner scanner(fileName);
		Gmpl2Sql::Parser parser(&scanner);
		parser.Parse();
                if(parser.errors.count == 0) {
#ifdef PARSER_WITH_AST
                    if(parser.ast_root) {
                        parser.ast_root->dump();
                        //parser.ast_root->dump2(parser.maxT);
                    }
#endif
                }

		coco_string_delete(fileName);
	} else
		wprintf(L"-- No source file specified\n");

	return 0;

}

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