Skip to content

Commit

Permalink
refactor(c): reorg preprocessor #24
Browse files Browse the repository at this point in the history
  • Loading branch information
phodal committed Feb 1, 2024
1 parent 5ab0852 commit 4ce50bb
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 107 deletions.
39 changes: 19 additions & 20 deletions chapi-ast-c/src/main/antlr/CLexer.g4
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ FALSE : 'false' ;
// macro
//Ifdef: 'ifdef';
//Ifndef: 'ifndef';
Include: 'include';
Define: 'define';
//Include: 'include';
//Define: 'define';

// gcc
Extenion : '__extension__';
Expand Down Expand Up @@ -142,6 +142,20 @@ Identifier
: IdentifierNondigit (IdentifierNondigit | Digit)*
;

DigitSequence
: Digit+
;

STRING
: EncodingPrefix? '"' SCharSequence? '"'
;
Constant
: IntegerConstant
| FloatingConstant
//| EnumerationConstant
| CharacterConstant
;

// ignore the following asm blocks:
/*
asm
Expand Down Expand Up @@ -174,10 +188,10 @@ LineComment
mode DIRECTIVE_MODE;

DIRECTIVE_WHITESPACES: Whitespace+ -> channel(HIDDEN);
DIGITS: [0-9]+ -> channel(DIRECTIVE);
//DIGITS: [0-9]+ -> channel(DIRECTIVE);
DIRECTIVE_TRUE: 'true' -> channel(DIRECTIVE), type(TRUE);
DIRECTIVE_FALSE: 'false' -> channel(DIRECTIVE), type(FALSE);
INCLUDE: 'include' -> channel(DIRECTIVE), type(Include);
INCLUDE: 'include' -> channel(DIRECTIVE);
DEFINE: 'define' -> channel(DIRECTIVE);
UNDEF: 'undef' -> channel(DIRECTIVE);
IFDEF: 'ifdef' -> channel(DIRECTIVE), type(If);
Expand All @@ -202,7 +216,7 @@ DIRECTIVE_OP_EQ: '==' -> channel(DIREC
DIRECTIVE_OP_NE: '!=' -> channel(DIRECTIVE), type(OP_NE);
DIRECTIVE_OP_AND: '&&' -> channel(DIRECTIVE), type(OP_AND);
DIRECTIVE_OP_OR: '||' -> channel(DIRECTIVE), type(OP_OR);
DIRECTIVE_STRING: '"' ~('"' | [\r\n\u0085\u2028\u2029])* '"' -> channel(DIRECTIVE), type(StringLiteral);
DIRECTIVE_STRING: '"' ~('"' | [\r\n\u0085\u2028\u2029])* '"' -> channel(DIRECTIVE), type(STRING);
CONDITIONAL_SYMBOL: Identifier -> channel(DIRECTIVE);
DIRECTIVE_SINGLE_LINE_COMMENT: '//' ~[\r\n\u0085\u2028\u2029]* -> channel(COMMENTS_CHANNEL), type(SINGLE_LINE_COMMENT);
DIRECTIVE_NEW_LINE: Newline -> channel(DIRECTIVE), mode(DEFAULT_MODE);
Expand Down Expand Up @@ -239,13 +253,6 @@ fragment HexQuad
: HexadecimalDigit HexadecimalDigit HexadecimalDigit HexadecimalDigit
;

Constant
: IntegerConstant
| FloatingConstant
//| EnumerationConstant
| CharacterConstant
;

fragment IntegerConstant
: DecimalConstant IntegerSuffix?
| OctalConstant IntegerSuffix?
Expand Down Expand Up @@ -332,10 +339,6 @@ fragment Sign
: [+-]
;

DigitSequence
: Digit+
;

fragment HexadecimalFractionalConstant
: HexadecimalDigitSequence? '.' HexadecimalDigitSequence
| HexadecimalDigitSequence '.'
Expand Down Expand Up @@ -388,10 +391,6 @@ fragment HexadecimalEscapeSequence
: '\\x' HexadecimalDigit+
;
StringLiteral
: EncodingPrefix? '"' SCharSequence? '"'
;
fragment EncodingPrefix
: 'u8'
| 'u'
Expand Down
Loading

0 comments on commit 4ce50bb

Please sign in to comment.