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

The library does not handle action (call the function in part 3 of the bison file) #31

Open
leviettung200 opened this issue Apr 18, 2022 · 4 comments

Comments

@leviettung200
Copy link

My bison file contains the action in Grammar rules.
This action will call the functions declared at the end of the bison.
However your library doesn't handle it, what can I do to fix it?
Functions declared at the end of the bison file are necessary for business logic.

Sample Grammar rule:

CMD_LINE_RR :
    CMD_TOKEN_RR LT_INTVAL LT_COMMA LT_TEXT_EX LT_RETURN
	{
		_CMD_START("CMD_LINE_RR(0)");
		cmd_rr(cmd_line , $2, $4, "", "", "", "", "", "", "", "", "" );
	
		next_cmd();
	}
	|CMD_TOKEN_RR LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_RETURN
	{
		_CMD_START("CMD_LINE_RR(1)");
		cmd_rr(cmd_line , $2, $4, $6, $8, $10, $12, $14, $16, $18, $20, $22 );
	
		next_cmd();
	}
	|CMD_TOKEN_RR LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_COMMA LT_INTVAL LT_RETURN
	{
		_CMD_START("CMD_LINE_RR(2)");
		cmd_rr(cmd_line , $2, $4, $6, $8, $10, $12, $14, $16, $18, "", "" );
	
		next_cmd();
	}
;

Sample c code(function):

int _CMD_START(char *s){
	#ifdef DEBUG
	printf("[%s][Line:%04d](+_+)%s\n",__FUNCTION__,__LINE__,s);
	#endif
	
	return 0;
}

@da-h
Copy link

da-h commented Apr 19, 2022

Hi @leviettung200,

the goal of pybison ist to combine bison and python.
It does so by implementing the grammar syntax into the docstrings of a "parser" python file.
Thus, while it is possible to use C code in the lexer, pybison does not allow C code in the grammar actions. The actions of the grammar rules can however be programmatically used using python.
(See the examples folder for some used cases.)

Best
da-h

@leviettung200
Copy link
Author

I'm seeking a Python, Java, JS, or C# solution that allows C code in the grammar actions.
Creating a parser file enables me in parsing the input and getting the output.

Can you give me any other suggestions?
Thanks @da-h !!

@da-h
Copy link

da-h commented Apr 19, 2022

Python-wise, it is relatively easy to write C-extensions.

So, if C-code in the grammar actions is necessary for your solution, with an python-api I would try plain bison (instead of pybison) to generate the parser itself and write an python C-extension as an entrypoint for the resulting parser.

@leviettung200
Copy link
Author

Can you please describe the process in greater detail?

If at all possible, I'd prefer my solution to avoid having to modify the parser file (using flex and bison files directly).
e.g., writing a wrapper for C code (which helps me to compile flex and bison).

My specific problem was migrating input file parsing from on-premise to the Azure Function App

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