135 lines
2.7 KiB
Text
135 lines
2.7 KiB
Text
==========================================
|
|
ambiguous declarations
|
|
==========================================
|
|
|
|
int main() {
|
|
// declare a function pointer
|
|
A * b(int a);
|
|
|
|
// evaluate an expression
|
|
c * d(5);
|
|
}
|
|
|
|
---
|
|
|
|
(translation_unit (function_definition
|
|
(identifier)
|
|
(function_declarator (identifier))
|
|
(compound_statement
|
|
(comment)
|
|
(declaration
|
|
(identifier)
|
|
(pointer_declarator (function_declarator (identifier) (parameter_declaration (identifier) (identifier)))))
|
|
(comment)
|
|
(expression_statement (math_expression
|
|
(identifier)
|
|
(call_expression (identifier) (number)))))))
|
|
|
|
==========================================
|
|
ambiguous expressions
|
|
==========================================
|
|
|
|
/*
|
|
* ambiguities
|
|
*/
|
|
|
|
int main() {
|
|
// cast
|
|
a((B *)c);
|
|
|
|
// parenthesized product
|
|
d((e * f));
|
|
}
|
|
|
|
---
|
|
|
|
(translation_unit
|
|
(comment)
|
|
(function_definition
|
|
(identifier)
|
|
(function_declarator (identifier))
|
|
(compound_statement
|
|
(comment)
|
|
(expression_statement (call_expression
|
|
(identifier)
|
|
(cast_expression (type_name (identifier) (abstract_pointer_declarator)) (identifier))))
|
|
(comment)
|
|
(expression_statement (call_expression
|
|
(identifier)
|
|
(math_expression (identifier) (identifier)))))))
|
|
|
|
==========================================
|
|
function-like macros that produce types
|
|
==========================================
|
|
|
|
// this is a macro
|
|
GIT_INLINE(int) x = 5;
|
|
|
|
---
|
|
|
|
(translation_unit
|
|
(comment)
|
|
(declaration
|
|
(macro_type (identifier) (identifier))
|
|
(identifier)
|
|
(initializer (number))))
|
|
|
|
============================================
|
|
3-way ambiguities (regression)
|
|
============================================
|
|
|
|
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
|
|
(identifier)
|
|
(function_declarator (identifier))
|
|
(compound_statement
|
|
(comment)
|
|
(declaration (identifier) (identifier))
|
|
(comment)
|
|
(declaration (identifier) (identifier)))))
|
|
|
|
=========================================
|
|
Comments after for loops with ambiguities
|
|
===========================================
|
|
|
|
int main() {
|
|
for (a *b = c; d; e) {
|
|
aff;
|
|
}
|
|
|
|
// a-comment
|
|
|
|
g;
|
|
}
|
|
|
|
---
|
|
|
|
(translation_unit (function_definition
|
|
(identifier)
|
|
(function_declarator (identifier))
|
|
(compound_statement
|
|
(for_statement
|
|
(declaration (identifier) (pointer_declarator (identifier)) (initializer (identifier)))
|
|
(identifier)
|
|
(identifier)
|
|
(compound_statement
|
|
(expression_statement (identifier))))
|
|
(comment)
|
|
(expression_statement (identifier)))))
|