Computer Science Asked by phamsodiep on October 21, 2021
I would like to write a grammar to convert EBNF description to a list of CFG production rules, instead of an algorithm.
Can CFG production rules is generated from an EBNF description by a rewrite system rewrite EBNF description to halt state that final string is composed by CFG production rules and separate character for that list (for example character ‘/’)?
For example: From intuition view, I could convert as below:
EBNF Description:
letter = "A" | "B" | "C" ;
digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
identifier = letter , { letter | digit | "_" } ;
Generated production rules:
letter ⟶ "A"
letter ⟶ "B"
letter ⟶ "C"
digit ⟶ "0"
digit ⟶ "1"
digit ⟶ "2"
digit ⟶ "3"
digit ⟶ "4"
digit ⟶ "5"
digit ⟶ "6"
digit ⟶ "7"
digit ⟶ "8"
digit ⟶ "9"
identifier ⟶ letter
identifier ⟶ letter noname_nonterminal
noname_nonterminal ⟶ letter noname_nonterminal
noname_nonterminal ⟶ digit noname_nonterminal
noname_nonterminal ⟶ "_" noname_nonterminal
noname_nonterminal ⟶ letter
noname_nonterminal ⟶ digit
noname_nonterminal ⟶ "_"
Thank you for your reading,
I have a solution as below:
G = (N, Σ, P, S) is EBNF description to production rules conversation grammar which is defined as below:
Production rules:
A = α, (γ), β ⟶ A = α, YA, β / YA = γ
Where:
A = α ∣ β ⟶ A = α / A = β
Where:
A = α[γ]β ⟶ A = α, (γ), β / A = α, β
Where:
A = α{γ}β ⟶ A = α , YA, β / YA = γYA / YA = ε
Where:
A = B,C ⟶ A = BC
Where:
A = B ⟶ A → B
Where:
Start rule:
S ⟶ a
This grammar will re-write EBNF description to a terminal string like: A → B / B → C / B → D which means that the generated production rules are the set {A → B, B → C, B → D}. The token '/' is list seperator.
Answered by phamsodiep on October 21, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP