Author: kjs
Date: Fri Feb 22 02:35:59 2008
New Revision: 25982
Modified:
trunk/languages/c99/src/parser/grammar.pg
Log:
[c99] add rules for pre-processor. I think this should become a different
grammar altogether to keep things simple.
Modified: trunk/languages/c99/src/parser/grammar.pg
==============================================================================
--- trunk/languages/c99/src/parser/grammar.pg (original)
+++ trunk/languages/c99/src/parser/grammar.pg Fri Feb 22 02:35:59 2008
@@ -361,13 +361,10 @@
token identifier {
- <!reserved_word> <alpha>+
+ <!reserved_word>
+ <identifier_nondigit> [ <identifier_nondigit> | <digit> ]*
}
-#
-# <identifier_nondigit> [ <identifier_nondigit> | <digit> ]*
-#}
-
token identifier_nondigit {
<alpha> | <[_]> | <universal_character_name>
}
@@ -594,27 +591,115 @@
]*
}
-## copied from old c99 grammar.
-##
## A.1.7 Punctuators
-##token punctuator {
-## | \[ | \] | <[(){}.]> | <'->'>
-## | <'++'> | <'--'> | <[&*+\-~!/%]>
-## | <'<<'> | <'>>'> | <[<>]>
-## | <'<='> | <'>='> | <'=='> | <'!='>
-## | <[^|]> | <'&&'> | <'||'>
-## | <[?:;]> | <'...'>
-## | [ <[*/%+\-&^|]> | <'<<'> | <'>>'> ] <'='>
-## | <[,#]> | <'##'>
-## | <'<:'> | <':>'> | <'<%'> | <'%>'> | <'%:'> | <'%:%:'>
-##}
##
-#### A.1.8 Header names
-##token header_name {
-## | \< $<name:>=<?h_char>+ \>
-## | " $<name>:=<?q_char>+ "
-##}
+
+token punctuator {
+ | \[ | \] | <[(){}.]> | '->'
+ | '++' | '--' | <[&*+\-~!/%]>
+ | '<<' | '>>' | '<' | '>'
+ | '<=' | '>=' | '==' | '!='
+ | <[^|]> | '&&' | '||'
+ | <[?:;]> | '...'
+ | <[*/%+\-&^|]> | '<<' | '>>' | '='
+ | <[,#]> | '##'
+ | '<:' | ':>' | '<%' | '%>' | '%:' | '%:%:'
+}
+
+
+## A.3 Preprocessing directives
##
-##token h_char { <-[\n>]> }
-##token q_char { <-[\n"]> }
-##
\ No newline at end of file
+
+rule pre_processing_file {
+ <group>?
+}
+
+rule group {
+ <group_part>+
+}
+
+rule group_part {
+ | <pp_tokens>? <newline>
+ | <if_section>
+ | <control_line>
+}
+
+rule if_section {
+ <if_group> <elif_group>* <else_group>? <endif_line>
+}
+
+rule if_group {
+ | '#' 'if' <constant_expression> <newline> <group>?
+ | '#' 'ifdef' <identifier> <newline> <group>?
+ | '#' 'ifndef' <identifier> <newline> <group>?
+}
+
+rule elif_group {
+ '#' 'elif' <constant_expression> <newline> <group>?
+}
+
+rule else_group {
+ '#' 'else' <newline> <group>?
+}
+
+rule endif_line {
+ '#' 'endif' <newline>
+}
+
+rule control_line {
+ | '#' 'include' <pp_tokens> <newline>
+ | '#' 'define' <identifier> <replacement_list> <newline>
+ | '#' 'define' <identifier> <lparen> <identifier_list>? ')'
<replacement_list> <newline>
+ | '#' 'define' <identifier> <lparen> '...' ')' <replacement_list> <newline>
+ | '#' 'define' <identifier> <lparen> <identifier_list> ',' '...' ')'
<replacement_list> <newline>
+ | '#' 'undef' <identifier> <newline>
+ | '#' 'line' <pp_tokens> <newline>
+ | '#' 'error' <pp_tokens>? <newline>
+ | '#' 'pragma' <pp_tokens>? <newline>
+ | '#' <newline>
+}
+
+rule pp_tokens {
+ <preprocessing_token>+
+}
+
+rule preprocessing_token {
+ | <header_name>
+ | <identifier>
+ | <pp_number>
+ | <character_constant>
+ | <c_string_literal>
+ | <punctuator>
+}
+
+rule pp_number {
+ ['.']? <digit> <pp_number_suffix>*
+}
+
+rule pp_number_suffix {
+ | '.'
+ | <identifier_nondigit>
+ | <digit>
+ | <[eEpP]> ['+'|'-']
+}
+
+rule replacement_list {
+ <pp_tokens>?
+}
+
+token lparen {
+ '('
+}
+
+token newline {
+ \n
+}
+
+## A.1.8 Header names
+token header_name {
+ | \< <h_char>+ \>
+ | \" <q_char>+ \"
+}
+
+token h_char { <-[\n>]> }
+token q_char { <-[\n"]> }