Reputation: 177
I am searching for c grammar and found this link https://www.lysator.liu.se/c/ANSI-C-grammar-y.html#cast-expression the issue is there is grammar for c and lex code but i don't see any semantics like addition ,multiplication implemented i know that yacc is used for only syntax check but we can also write semantics in it where are the semantics implemented are they implemented in other tool.
I am trying to implement a small compiler where do i write semantics ,is it good to write them in yacc using functions.
Upvotes: 0
Views: 568
Reputation: 241721
That example grammar (which is for a very old version of C) does not contain any particular semantics. You could certainly add them; the semantic rules would depend on what sort of tool you were building.
Bison/yacc is certainly a possible tool to build a compiler with. Many people have done so. Whether you refactor the semantic code into reusable functions or just put code directly into each action is a design choice which is up to you; I think most of us would recommend some use of functions to avoid code repetition.
Upvotes: 2