Hi all,
I'm wondering if lexing style regular expressions can be used within
ocamlyac. for example, take a simple if-else statement, we may have
1. if ( a )
do_something
2. if ( a ){
do_something
}
3. if ( a )
do_something
else
do_something_else
4. if ( a ){
do_something
} else {
do_something_else
}
... and so on you get the point
with my (very) limited ocaml knowledge so far, when writing the
parse, i;ve has to specify each case and its cooresponding AST type, i.e
-----------------------------
ifStatement
: IF PARENTH_OPEN expr PARENTH_CLOSE statement
{IfStatement(If, Expr($3), $5, None)}
| IF PARENTH_OPEN expr PARENTH_CLOSE statement ELSE statement
{
IfStatement(If, Expr($3), $5, Some($7))}
| ....
| ....
-----------------------------
Now i wondered whether we could subtitude all of those cases for a
simple regexp like
---------
if_stmt
: IF PARENTH_OPEN! exp PARENTH_CLOSE! ((statement)* (return_expr )
?) (else_stmt)* {...}
;
else_stmt
: ELSE IF PARENTH_OPEN! exp RPREN! ((statement)* (return_expr ) ?)
( else_stmt) {....}
| ELSE PARENTH_OPEN! (statement)* (return_expr )? PARENTH_CLOSE!
{...} ;
------------
whereby if a given token is empty we can just set its corresponding
AST value to None... possible using pattern matching .
if anyne has any ideas on how i could do this/ if its possible or
would like to point me to some fundamental and obvious thing i have
missed, it would really be appreciated
cheers
deeq
.