Skip to content

Conversation

@ydah
Copy link
Member

@ydah ydah commented Dec 29, 2025

This PR makes Lrama's inline feature compliant with the Menhir specification.

Key Changes

Menhir-style Variable Binding for Action Merging

Changed from macro-like substitution (simple string replacement of $n) to a temporary variable binding approach.

Before:

// Simple substitution of $2 with inline_action_string
$$ = $1 inline_action_string $3;

After:

// Variable binding ensures single evaluation
YYSTYPE _inline_2; { _inline_2 = '+'; } $$ = $1 _inline_2 $3;

This resolves the issue where inline actions with side effects could be evaluated multiple times.

Added Recursion Detection Validator

Added a Validator that detects the following errors per Menhir specification:

  • Direct recursion (inline rule references itself)
  • Mutual recursion (multiple inline rules form a reference cycle)
  • Start symbol declared as inline

Added --no-inline Option

Added an option to ignore all %inline keywords in the grammar specification. Useful for verifying whether inlining contributes to conflict resolution.

Added Sample Files

Added samples demonstrating the core use case of %inline (resolving precedence conflicts):

  • sample/calc_inline.y: Resolves precedence issue with %inline
  • sample/calc_no_inline.y: Shows conflicts without %inline

References

This PR makes Lrama's inline feature compliant with the [Menhir](https://gallium.inria.fr/~fpottier/menhir/) specification.

Changed from macro-like substitution (simple string replacement of `$n`) to a temporary variable binding approach.

Before:
```c
// Simple substitution of $2 with inline_action_string
$$ = $1 inline_action_string $3;
```

After:
```c
// Variable binding ensures single evaluation
YYSTYPE _inline_2; { _inline_2 = '+'; } $$ = $1 _inline_2 $3;
```

This resolves the issue where inline actions with side effects could be evaluated multiple times.

Added a Validator that detects the following errors per Menhir specification:
- Direct recursion (inline rule references itself)
- Mutual recursion (multiple inline rules form a reference cycle)
- Start symbol declared as inline

Added an option to ignore all `%inline` keywords in the grammar specification. Useful for verifying whether inlining contributes to conflict resolution.

Added samples demonstrating the core use case of `%inline` (resolving precedence conflicts):
- `sample/calc_inline.y`: Resolves precedence issue with `%inline`
- `sample/calc_no_inline.y`: Shows conflicts without `%inline`

- [Menhir Reference Manual - Inlining](https://gallium.inria.fr/~fpottier/menhir/manual.html#sec%3Ainlining)
- [Menhir GitHub Repository](https://github.com/LexiFi/menhir)
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

Successfully merging this pull request may close these issues.

1 participant