========================================================================
|
|
pointer declarations vs multiplications
|
|
========================================================================
|
|
|
|
int main() {
|
|
// declare a function pointer
|
|
T1 * b(T2 a);
|
|
|
|
// evaluate an expression
|
|
c * d(5);
|
|
}
|
|
|
|
---
|
|
|
|
(translation_unit (function_definition
|
|
(primitive_type)
|
|
(function_declarator (identifier) (parameter_list))
|
|
(compound_statement
|
|
(comment)
|
|
(declaration
|
|
(type_identifier)
|
|
(pointer_declarator (function_declarator
|
|
(identifier)
|
|
(parameter_list (parameter_declaration (type_identifier) (identifier))))))
|
|
(comment)
|
|
(expression_statement (math_expression
|
|
(identifier)
|
|
(call_expression (identifier) (argument_list (number_literal))))))))
|
|
|
|
========================================================================
|
|
casts vs multiplications
|
|
========================================================================
|
|
|
|
/*
|
|
* ambiguities
|
|
*/
|
|
|
|
int main() {
|
|
// cast
|
|
a((B *)c);
|
|
|
|
// parenthesized product
|
|
d((e * f));
|
|
}
|
|
|
|
---
|
|
|
|
(translation_unit
|
|
(comment)
|
|
(function_definition
|
|
(primitive_type)
|
|
(function_declarator (identifier) (parameter_list))
|
|
(compound_statement
|
|
(comment)
|
|
(expression_statement (call_expression
|
|
(identifier)
|
|
(argument_list (cast_expression (type_descriptor (type_identifier) (abstract_pointer_declarator)) (identifier)))))
|
|
(comment)
|
|
(expression_statement (call_expression
|
|
(identifier)
|
|
(argument_list (parenthesized_expression (math_expression (identifier) (identifier)))))))))
|
|
|
|
========================================================================
|
|
function-like type macros vs function calls
|
|
========================================================================
|
|
|
|
// this is a macro
|
|
GIT_INLINE(int *) x = 5;
|
|
|
|
---
|
|
|
|
(translation_unit
|
|
(comment)
|
|
(declaration
|
|
(macro_type_specifier (identifier) (type_descriptor (primitive_type) (abstract_pointer_declarator)))
|
|
(init_declarator (identifier) (number_literal))))
|
|
|
|
========================================================================
|
|
function calls vs parenthesized declarators vs macro types
|
|
========================================================================
|
|
|
|
int main() {
|
|
/*
|
|
* Could be either:
|
|
* - function call
|
|
* - declaration w/ parenthesized declarator
|
|
* - declaration w/ macro type, no declarator
|
|
*/
|
|
ABC(d);
|
|
|
|
/*
|
|
* Normal declaration
|
|
*/
|
|
efg hij;
|
|
}
|
|
|
|
---
|
|
|
|
(translation_unit
|
|
(function_definition
|
|
(primitive_type)
|
|
(function_declarator (identifier) (parameter_list))
|
|
(compound_statement
|
|
(comment)
|
|
(expression_statement (call_expression (identifier) (argument_list (identifier))))
|
|
(comment)
|
|
(declaration (type_identifier) (identifier)))))
|
|
|
|
========================================================================
|
|
Comments after for loops with ambiguities
|
|
========================================================================
|
|
|
|
int main() {
|
|
for (a *b = c; d; e) {
|
|
aff;
|
|
}
|
|
|
|
// a-comment
|
|
|
|
g;
|
|
}
|
|
|
|
---
|
|
|
|
(translation_unit (function_definition
|
|
(primitive_type)
|
|
(function_declarator (identifier) (parameter_list))
|
|
(compound_statement
|
|
(for_statement
|
|
(declaration (type_identifier) (init_declarator
|
|
(pointer_declarator (identifier))
|
|
(identifier)))
|
|
(identifier)
|
|
(identifier)
|
|
(compound_statement
|
|
(expression_statement (identifier))))
|
|
(comment)
|
|
(expression_statement (identifier)))))
|