I’m trying to write a parser for a language (maxscript) that has several ambiguous statements.
Example grammar:
program : expr* EOF ;
expr: simple_expr | case_expr ;
// fn_call must be first, if not program matches a sequence of operands...
simple_expr : fn_call | operand | ...;
// case val of (1:true; 2:false; 3:someVal, default:false)
case_expr :
'('
case_clause (Nl case_clause)*
')'
;
case_clause : factor {this.noWShere()}? ':' expr ;
// calle arg arg param:val param:val....
// grammar reference says 'until an eol or lower precedence token'
fn_call
: caller = (var_name | accesor) ({this.noNLhere()}? (operand | param))+
| caller = (var_name | accesor) {this.noNLhere()}? '()'
;
param: var_name {this.noWShere()}? ':' expr;
operand : factor | accessor;
factor
: var_name
| number
| ...
;
...
Nl : {this.lineTerminatorAhead()}?
;
I’m unable to correctly handle the ‘NO NEW LINES’ requeriment (becasue predicates are not at the left and gets ignored? or they does not work with the quantifiers?) resulting in an ambiguos grammar between <fn_call> and <case_clause>
test code:
case mode of (
1: 5
2: someVal
default: 10
)
Expected result
case expr: case mode of (1:5; 2: someVal; default:10)
Actual result:
case expr: case mode of (1:5; 2:someVal; default:10); fn_call: someVal default:10
Atelier Bump is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.