|
1 answer
Not.
Grammar C is not context free. For example, the expression
a((b)*c); may be
- if
ais a function,bis a type,cis a pointer: dereferencing the pointerc, casting the result to typeb, passing the resulting value as a parameter to the functiona; - if
ais a function,bis a numeric variable / constant,cis a numeric variable / constant: multiplying the values ofbandc, passing the value obtained as a parameter to the functiona.
Thus, the correct analysis is impossible without context. LL parsers are intended only for context-free grammars.
- And what kind of parser would you recommend using? - PaulD
- I would take lex / yacc (flex / bison), enter explicit context, resolve ambiguities manually. - VladD
- @SoloMio Here is the grammar for ANTLR 4 github.com/antlr/grammars-v4/blob/master/c/C.g4 - andrybak
- one@Andrey: typedefName: Identifier; Something I do not think this grammar is unambiguous. How does she distinguish two cases from my answer? - VladD
- @VladD, and what is meant by an explicit context? - PaulD
|