-
Notifications
You must be signed in to change notification settings - Fork 2
Syntax
Ronald Franco edited this page Dec 26, 2018
·
3 revisions
The syntax of an Attribute-Flow Grammar is similar to that of Attribute Grammars written in Extended Backus-Naur Form (EBNF).
Key Differences:
- Grammar productions are specified with an equal sign (=) instead of an arrow
(->) and end with a semicolon (;).
- EBNF:
S -> A
- AFG:
S = A;
- EBNF:
- Sequential grammar symbols are separated by the binary AND operator (&)
- EBNF:
S -> A B
- AFG:
S = A & B;
- EBNF:
- Grammar symbol operators appear on the left of the grammar symbol operand as opposed to EBNF notation where the operator appears to the right of the grammar symbol operand
- EBNF:
S -> A*;
- AFG:
S = *A;
- EBNF:
The following table illustrates all the operations available to be performed on grammar symbols in an AFG.
X & Y concatenation
X | Y alternation
*X repeat
+X nonzero repeat
-X optional
~X lookahead (match and backtrack)
!X negative lookahead (non-match and backtrack)
N * X repeat N times
N-M * X repeat N to M times
[&]{ ... } semantic action
Token('A') a token with code 65 (ASCII value of 'A')
Token(65) a token with code 65