How compare grammars?

10 views
Skip to first unread message

Andy

unread,
Jan 3, 2019, 6:27:56 PM1/3/19
to antlr-discussion

Is possible compare grammars (EBNF or g4 or similar forms). While comparing it must ignore rules order and rules names, ignore names of nonterminals, only terminals is important.

How synchronize and emit only real difference?

Is any algorithm to compare different for example C grammar files?

Second level – ignore also terminals and compare only structure and philosophy of language – for example comparing grammar Java and C#.

Loring Craymer

unread,
Jan 4, 2019, 2:02:00 AM1/4/19
to antlr-discussion
Yes, if the productions have equivalent structure--you serialize graph representations of the two grammars and compare the token streams.  However, what you really want to ask is whether two grammars recognize the same language (two grammars can recognize the same language but have different sets of syntactic ambiguities and/or recursion relationships), which is a difficult problem, quite possibly NP-hard.  As to the second level question, if we had the necessary theory for comparing formal languages, that would be a core topic of study for "Theory of Computing" courses.

--Loring

Andy

unread,
Jan 4, 2019, 4:22:46 AM1/4/19
to antlr-discussion
Grammar is cyclic graph with one top(start) node and several bottom nodes = tokens.
I think, we must start from tokens and go up.
But it is bad approach because grammar must not have "levels" and terminal can be produced from start.
Maybe identify nonterminals by sets First and Follows? The same bith sets -> the same nonterminals?
Reply all
Reply to author
Forward
0 new messages