241 lines
6.7 KiB
Plaintext
241 lines
6.7 KiB
Plaintext
"Name" = 'C Preprocessor'
|
|
"Version" = '0.1'
|
|
"Author" = 'DarkStar'
|
|
"About" = 'Ops5 project'
|
|
|
|
"Case Sensitive" = True
|
|
|
|
"Start Symbol" = <preprocessor_program>
|
|
|
|
Comment Start = '/*'
|
|
Comment End = '*/'
|
|
Comment Line = '//'
|
|
|
|
!*
|
|
[TERMINALTEMPLATE]
|
|
{
|
|
%NAME% _%NAME%=new %NAME%(%PARAMS%);
|
|
_%NAME%.source_context=parsertools.GetTokenSourceContext();
|
|
%CODE%
|
|
return _%NAME%;
|
|
}
|
|
*!
|
|
|
|
!*
|
|
[NONTERMINALTEMPLATE0]
|
|
{
|
|
%NAME% _%NAME%=new %NAME%(%PARAMS%);
|
|
parsertools.create_source_context(_%NAME%,%LEFTTOKEN%,%RIGHTTOKEN%);
|
|
%CODE%
|
|
return _%NAME%;
|
|
}
|
|
*!
|
|
|
|
!add to list
|
|
!*
|
|
[NONTERMINALTEMPLATE1]
|
|
{
|
|
%NAME% _%NAME%=(%NAME%)%CODE%
|
|
return _%NAME%;
|
|
}
|
|
*!
|
|
|
|
!*
|
|
[NONTERMINALTEMPLATE2]
|
|
{
|
|
%NAME% _%NAME%;
|
|
%CODE%
|
|
return _%NAME%;
|
|
}
|
|
*!
|
|
|
|
|
|
!*
|
|
[NONTERMINALTEMPLATE3]
|
|
{
|
|
%NAME% _%NAME%=new %NAME%(%PARAMS%);
|
|
%CODE%
|
|
return _%NAME%;
|
|
}
|
|
*!
|
|
|
|
!for list:
|
|
!<el>
|
|
!<list> token <el>
|
|
!*
|
|
[NONTERMINALTEMPLATE6]
|
|
//TemplateList for %NAME% (create)
|
|
{
|
|
%NAME% _%NAME%=new %NAME%();
|
|
_%NAME%.source_context=((%CODE%)$1).source_context;
|
|
_%NAME%.%PARAMS%.Add((%CODE%)$1);
|
|
return _%NAME%;
|
|
}
|
|
*!
|
|
!*
|
|
[NONTERMINALTEMPLATE7]
|
|
//TemplateList for %NAME% (add)
|
|
{
|
|
%NAME% _%NAME%=(%NAME%)$1;
|
|
parsertools.create_source_context(_%NAME%,$$,$3);
|
|
_%NAME%.%PARAMS%.Add($3 as %CODE%);
|
|
return _%NAME%;
|
|
}
|
|
*!
|
|
|
|
!{CR} = {#13}
|
|
!{LF} = {#10}
|
|
{Id Head} = {Letter} + [_]
|
|
{Id Tail} = {Id Head} + {Digit}
|
|
{All ASCII} = {#1..#255}+{Cyrillic}+{#8100..#8800}
|
|
{New Line} = ['\']
|
|
|
|
{WS} = {Whitespace} - {CR} - {LF}
|
|
{WWSS} = {WS}
|
|
|
|
{Token Part1} = {All ASCII} - {CR} - {LF} - ['#']
|
|
{Program line part} = {All ASCII} - {CR} - {LF} - ['#'] - {WS}
|
|
Whitespace = {WS}+
|
|
|
|
{TextPart} = {All ASCII} - {Control Codes}
|
|
{String Ch} = {TextPart} - ["]
|
|
{Char Ch} = {TextPart} - ['']
|
|
|
|
|
|
TKPNDUNKNOW = '#' {Id Head}{Id Tail}* !*<token_info>*!
|
|
TKPNDIF = '#if' !*<token_info>*!
|
|
TKPNDIFDEF = '#ifdef' !*<token_info>*!
|
|
TKPNDIFNDEF = '#ifndef' !*<token_info>*!
|
|
TKPNDELIF = '#elif' !*<token_info>*!
|
|
TKPNDELSE = '#else' !*<token_info>*!
|
|
TKPNDENDIF = '#endif' !*<token_info>*!
|
|
TKPROGRAM_LINE = (( (({Token Part1})|('"'( {String Ch} | '\'{Printable} )* '"')|('' ( {Char Ch} | '\'{Printable} )''))* {New Line} ({CR}{LF}|{CR}))* (({Token Part1})|('"'( {String Ch} | '\'{Printable} )* '"')|('' ( {Char Ch} | '\'{Printable} )''))* )? ({CR}{LF}|{CR}) !*<token_info>*!
|
|
TKPROGRAM_LINE_PART = {Program line part}+ !*<token_info>*!
|
|
|
|
|
|
<preprocessor_program>
|
|
::= <directive_groups> !*3compilation_unit<>
|
|
$$.Language=LanguageId.C;
|
|
if($1!=null){
|
|
parsertools.create_source_context($$,$1,$1);
|
|
CompilerDirectives.AddRange(((compiler_directive_list)$1).directives);
|
|
}
|
|
*!
|
|
| <directive_groups> TKPROGRAM_LINE_PART !*3compilation_unit<>
|
|
$$.Language=LanguageId.C;
|
|
parsertools.create_source_context($$,parsertools.sc_not_null($1,$2),$2);
|
|
if($1!=null)
|
|
CompilerDirectives.AddRange(((compiler_directive_list)$1).directives);
|
|
*!
|
|
|
|
<directive_groups>
|
|
::= <_directive_groups>
|
|
|
|
|
|
|
<_directive_groups>
|
|
::= <directive_group> !*3compiler_directive_list<>
|
|
if($1 is compiler_directive)
|
|
$$.directives.Add((compiler_directive)$1);
|
|
parsertools.create_source_context($$,$1,$1);*!
|
|
| <directive_groups> <directive_group> !*1compiler_directive_list<>$1;
|
|
if($2 is compiler_directive)
|
|
$$.directives.Add((compiler_directive)$2);
|
|
parsertools.create_source_context($$,$1,$2);*!
|
|
|
|
<directive_group>
|
|
::= <control_line>
|
|
| <conditional_group>
|
|
| TKPROGRAM_LINE
|
|
|
|
!Conditionals
|
|
|
|
!<conditional_group>
|
|
! ::= <if_stmt>
|
|
|
|
!<if_stmt>
|
|
! ::= <if_part> <directive_groups> <endif_part>
|
|
|
|
<conditional_group>
|
|
::= <if_part> <directive_groups> <endif_part> !*1compiler_directive_if<>$1;
|
|
$$.if_part=(compiler_directive_list)$2;
|
|
parsertools.create_source_context($$,$1,$3);*!
|
|
| <if_part> <elif_part> <directive_groups> <endif_part> !*1compiler_directive_if<>$1;
|
|
$$.if_part=if_part.Pop();
|
|
($2 as compiler_directive_if).if_part=(compiler_directive)$3;
|
|
$$.elseif_part=first_if.Pop();
|
|
parsertools.create_source_context($$,$1,$4);*!
|
|
| <if_part> <else_part> <directive_groups> <endif_part> !*1compiler_directive_if<>$1;
|
|
$$.if_part=if_part.Pop();
|
|
if($2 is compiler_directive_if)
|
|
{
|
|
($2 as compiler_directive_if).elseif_part=(compiler_directive)$3;
|
|
$$.elseif_part=first_if.Pop();
|
|
}else{
|
|
first_if.Pop();
|
|
$$.elseif_part=(compiler_directive)$3;
|
|
}
|
|
parsertools.create_source_context($$,$1,$4);*!
|
|
|
|
<if_part>
|
|
::= <if_line>
|
|
| <ifdef_line>
|
|
| <ifndef_line>
|
|
|
|
<else_part>
|
|
::= <directive_groups> <else_line> !*if_part.Push((compiler_directive)$1);
|
|
first_if.Push(null); $$=$1;*!
|
|
| <elif_part> <directive_groups> <else_line> !*1compiler_directive_if<>$1;
|
|
$$.if_part=(compiler_directive)$2;
|
|
parsertools.create_source_context($$,$1,$2);*!
|
|
|
|
<elif_part>
|
|
::= <directive_groups> <elif_line> !*if_part.Push((compiler_directive)$1);
|
|
first_if.Push((compiler_directive)$2); $$=$2;*!
|
|
| <elif_part> <directive_groups> <elif_line> !*1compiler_directive_if<>$1;
|
|
$$.if_part=(compiler_directive)$2;
|
|
$$.elseif_part=(compiler_directive)$3;
|
|
parsertools.create_source_context($$,$1,$2);
|
|
$$=(compiler_directive_if)$3;*!
|
|
|
|
<endif_part>
|
|
::= <endif_line>
|
|
|
|
<if_line>
|
|
::= TKPNDIF TKPROGRAM_LINE !*3compiler_directive_if<>
|
|
$$.Name=(token_info)$1;
|
|
$$.Directive=(token_info)$2;
|
|
parsertools.create_source_context($$,$1,$2); *!
|
|
|
|
<ifdef_line>
|
|
::= TKPNDIFDEF TKPROGRAM_LINE !*3compiler_directive_if<>
|
|
$$.Name=(token_info)$1;
|
|
$$.Directive=(token_info)$2;
|
|
parsertools.create_source_context($$,$1,$2); *!
|
|
|
|
<ifndef_line>
|
|
::= TKPNDIFNDEF TKPROGRAM_LINE !*3compiler_directive_if<>
|
|
$$.Name=(token_info)$1;
|
|
$$.Directive=(token_info)$2;
|
|
parsertools.create_source_context($$,$1,$2); *!
|
|
|
|
<elif_line>
|
|
::= TKPNDELIF TKPROGRAM_LINE !*3compiler_directive_if<>
|
|
$$.Name=(token_info)$1;
|
|
$$.Directive=(token_info)$2;
|
|
parsertools.create_source_context($$,$1,$2); *!
|
|
|
|
<else_line>
|
|
::= TKPNDELSE
|
|
|
|
<endif_line>
|
|
::= TKPNDENDIF
|
|
|
|
!Control lines
|
|
|
|
<control_line>
|
|
::= <unknow_line>
|
|
|
|
<unknow_line>
|
|
::= TKPNDUNKNOW TKPROGRAM_LINE !*3compiler_directive<(token_info)$1,(token_info)$2>
|
|
parsertools.create_source_context($$,$1,$2); *!
|