Adding New Syntax in P4C

Hi all,

I want to add new syntax to p4. I have added a new type like struct in p4parser.ypp and p4lexer.ll. but I have some errors about defining IR::Type_New like IR::Type_Struct and I tried to define it in ir_genrated.h and other codes but I have an error yet. Please let me know when we want to add new syntax in p4, we need to change which codes except for p4parser.ypp and p4lexer.ll.

Thank you so much.
Mohsen

This is done quite frequently as the language evolves. You can see an example in a recent pull request: Experimental support for typeof keyword by mbudiu-vmw · Pull Request #3017 · p4lang/p4c · GitHub which adds a new keyword typeof.
In general you will need to change the parser, perhaps add new IR classes, and then, most difficult, change all analyses in the compiler that may need to know about the new IR nodes.This last PR needs to add type inference for the new keyword added.

1 Like