Skip to content
This repository has been archived by the owner on May 16, 2022. It is now read-only.

Which parser to use for non-terminal to non-terminal rule?? #16

Closed
Shulito opened this issue May 2, 2019 · 1 comment
Closed

Which parser to use for non-terminal to non-terminal rule?? #16

Shulito opened this issue May 2, 2019 · 1 comment

Comments

@Shulito
Copy link

Shulito commented May 2, 2019

Which class do you use to represent a non-terminal to a non-terminal rule??

<script>          ::= <statements>
<statements> ::= <statements> <statement> | <statement>
<statement>   ::= <assignment-stm> | <return-stm>
...

new Ferno\Loco\Grammar(
	"<script>",
	array(
		"<script>" => ???                  <- to <statements>
	),
	function($script)
	{
		return $script;
	}
);

@Shulito Shulito changed the title Which parser to use Which parser to use for non-terminal to non-terminal rule?? May 2, 2019
@qntm
Copy link
Owner

qntm commented May 2, 2019

Hi there, I haven't used this in forever, but can't you do

new Ferno\Loco\Grammar(
	"<script>",
	array(
		"<script>" => "<statements>",
		# ...
	),
	function($script)
	{
		return $script;
	}
);

?

Failing that, you could just simplify your grammar a little:

<script> ::= <script> <statement> | <statement>
<statement>   ::= <assignment-stm> | <return-stm>
...

Although, having said that, your grammar seems to be left-recursive, which I believe Loco does not support.

@Shulito Shulito closed this as completed May 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants