-
Notifications
You must be signed in to change notification settings - Fork 0
Grammar Syntax
Conqu3red edited this page Jun 11, 2021
·
1 revision
This document outlines how to write .gram files. It useful to refer to parsergen/metagrammar.gram for the exact specification, or look at the readme file for an example.
Rules must follow the form of identifier : <terminals / non terminals> <optional action>;
The current implementation is almost as complete as seen here.
| Expression | Description |
|---|---|
A B |
Sequence A followed by token B
|
A* |
token A is repeated zero or more times |
A+ |
token A is repeated one or more times |
A? |
token A is optional |
A | B |
there is either token A or B
|
(A B) |
there is a group A B, these tokens are grouped into a list |
v=A |
the token A is assigned to variable v
|
x |
Points to statement x
|
expr : v=A { v }; |
see previous, the return expression is v
|
Note: actions must contain a valid python expression which can go after a return statement.
expr
: A B;
: B A;
The expr rule can be either A B or the alternative rule B A.