Top  Previous  Next

Examples > C-typedef > Typedef


A type definition is started in C with the keyword typedef. For example:


typedef const char* cpchar;


cpchar can be used instead of "const char*" in the C code after this definition.

The simplified production type_definition for parsing the definition is:



declaration_specifiers? "*"* 


{{ AddToken(xState.str(), "TYPE", ScopeStr()); }} 



The second line contains the rule for the expression, which has to be abbreviated. ID in the third line recognizes  the name of the definition.

With the following semantic action the found name is added to the dynamic token "TYPE" as an additional alternative now. TYPE is defined on the token page as:




TYPE is used in the  type_specifier production:



| "char"

| "short"

| "int"

| "long"

| "float"

| "double"

| "signed"

| "unsigned"





cpchar p;


p is correctly recognized as a declaration of a variable with the user defined type cpchar.






This page belongs to the TextTransformer Documentation

Home  Content  German