0

assume we have a context free grammar , if it is in LL[1] , then it has only right Associative ! but let's say i want to make this context free grammar have a left Associative , then it will not stay in LL[1] , (which is okay) i figured that in order to make a context free grammar have a left Associative i should make it have left recursion . is there is a way to include left recursion to a context free grammar without changing the language of the grammar ? for example if we have this context free grammar :

1: S -> sum ( ELIST )
2: ELIST -> E , ELIST
3: ELIST -> E
4: E -> num
5: E -> id
6: E -> S

how to make this include a left recursion so the operator "," will now be left Associative ?

mmolaan
  • 1
  • 3
  • 1
    Associativity is related to the meaning (semantics) of a language, while grammars are related to the syntax. So they are really independent. – Chris Dodd Mar 12 '21 at 00:58
  • if a context free grammar is in LL[1] , then it support only right Associativity ! i checked it ! what i mean with right Associativity , is that for every series of rules applied i only get a tree that is going to the right – mmolaan Mar 12 '21 at 01:09

1 Answers1

0

Change your second production to:

2: ELIST -> ELIST , E

This does not change the language, only the way the language is parsed.

This modification should work with any expression grammar written in cascading precedence style. But it is not a transformation which can be applied to any grammar whatsoever.

rici
  • 234,347
  • 28
  • 237
  • 341