Skip to content

Commit

Permalink
Real literal grammar and token are added.
Browse files Browse the repository at this point in the history
Also, Operators and Punctuators are added.
  • Loading branch information
dongjoon1251 committed Oct 16, 2014
1 parent 2b40fb7 commit 10278ce
Show file tree
Hide file tree
Showing 4 changed files with 255 additions and 38 deletions.
20 changes: 16 additions & 4 deletions grammar/csharp.jison
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@

%token Unicode_escape_sequence

%token REAL_LITERAL
%token INTEGER_LITERAL

%token IDENTIFIER

%token OPEN_BRACE CLOSE_BRACE OPEN_BRACKET CLOSE_BRACKET OPEN_PARENS CLOSE_PARENS DOT COMMA COLON SEMICOLON PLUS MINUS STAR DIV PERCENT AMP BITWISE_OR CARET BANG TILDE ASSIGNMENT LT GT INTERR DOUBLE_COLON OP_COALESCING OP_INC OP_DEC OP_AND OP_OR OP_PTR OP_EQ OP_NE OP_LE OP_GE OP_ADD_ASSIGNMENT OP_SUB_ASSIGNMENT OP_MULT_ASSIGNMENT OP_DIV_ASSIGNMENT OP_MOD_ASSIGNMENT OP_AND_ASSIGNMENT OP_OR_ASSIGNMENT OP_XOR_ASSIGNMENT OP_LEFT_SHIFT OP_LEFT_SHIFT_ASSIGNMENT RIGHT_SHIFT RIGHT_SHIFT_ASSIGNMENT

%token IDENTIFIER

%token EOF

Expand Down Expand Up @@ -40,12 +42,22 @@ e
{
console.log('Unicode_escape_sequence: '+$1);
}

| REAL_LITERAL
{
console.log('REAL_LITERAL: '+$1);
}
| INTEGER_LITERAL
{
console.log('INTEGER_LITERAL: '+$1);
}

| OPEN_BRACE
{
console.log('OPEN_BRACE');
}
| DOT
{
console.log('DOT');
}
| IDENTIFIER
{
console.log('IDENTIFIER: '+$1);
Expand Down
71 changes: 63 additions & 8 deletions grammar/csharp.jisonlex
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,27 @@ Connecting_character {UNICODE_CLASS_Pc}
Formatting_character {UNICODE_CLASS_Cf}


/* Integer Literals */
/* Real Literals */
REAL_LITERAL {Decimal_digits}{DOT}{Decimal_digits}{Exponent_part}?{Real_type_suffix}?|{DOT}{Decimal_digits}{Exponent_part}?{Real_type_suffix}?|{Decimal_digits}{Exponent_part}{Real_type_suffix}?|{Decimal_digits}{Real_type_suffix}
Exponent_part 'e'{Sign}?{Decimal_digits}|'E'{Sign}?{Decimal_digits}
Sign '+'|'-'
Real_type_suffix 'F'|'f'|'D'|'d'|'M'|'m'
DOT '.'

INTEGER_LITERAL {Hexadecimal_integer_literal}|{Decimal_integer_literal}


/* Integer Literals */
INTEGER_LITERAL {Hexadecimal_integer_literal}|{Decimal_integer_literal}
Decimal_integer_literal {Decimal_digits}{Integer_type_suffix}?

Decimal_digits {DECIMAL_DIGIT}+

DECIMAL_DIGIT [0-9]

Integer_type_suffix 'UL'|'Ul'|'uL'|'ul'|'LU'|'Lu'|'lU'|'lu'|'U'|'u'|'L'|'l'

Hexadecimal_integer_literal ('0x'{Hex_digits}{Integer_type_suffix}?) | ('0X'{Hex_digits}{Integer_type_suffix}?)

Hex_digits {HEX_DIGIT}+

HEX_DIGIT [0-9a-fA-F]




%%

Expand Down Expand Up @@ -189,8 +192,60 @@ HEX_DIGIT [0-9a-fA-F]

{Unicode_escape_sequence} return 'Unicode_escape_sequence';

{REAL_LITERAL} return 'REAL_LITERAL';
{INTEGER_LITERAL} return 'INTEGER_LITERAL';


/* Operators And Punctuators*/
"{" return 'OPEN_BRACE';
"}" return 'CLOSE_BRACE';
"[" return 'OPEN_BRACKET';
"]" return 'CLOSE_BRACKET';
"(" return 'OPEN_PARENS';
")" return 'CLOSE_PARENS';
{DOT} return 'DOT';
"," return 'COMMA';
":" return 'COLON';
";" return 'SEMICOLON';
"+" return 'PLUS';
"-" return 'MINUS';
"*" return 'STAR';
"/" return 'DIV';
"%" return 'PERCENT';
"&" return 'AMP';
"|" return 'BITWISE_OR';
"^" return 'CARET';
"!" return 'BANG';
"~" return 'TILDE';
"=" return 'ASSIGNMENT';
"<" return 'LT';
">" return 'GT';
"?" return 'INTERR';
"::" return 'DOUBLE_COLON';
"??" return 'OP_COALESCING';
"++" return 'OP_INC';
"--" return 'OP_DEC';
"&&" return 'OP_AND';
"||" return 'OP_OR';
"->" return 'OP_PTR';
"==" return 'OP_EQ';
"!=" return 'OP_NE';
"<=" return 'OP_LE';
">=" return 'OP_GE';
"+=" return 'OP_ADD_ASSIGNMENT';
"-=" return 'OP_SUB_ASSIGNMENT';
"*=" return 'OP_MULT_ASSIGNMENT';
"/=" return 'OP_DIV_ASSIGNMENT';
"%=" return 'OP_MOD_ASSIGNMENT';
"&=" return 'OP_AND_ASSIGNMENT';
"|=" return 'OP_OR_ASSIGNMENT';
"^=" return 'OP_XOR_ASSIGNMENT';
"<<" return 'OP_LEFT_SHIFT';
"<<=" return 'OP_LEFT_SHIFT_ASSIGNMENT';
">>" return 'RIGHT_SHIFT';
">>=" return 'RIGHT_SHIFT_ASSIGNMENT';


{IDENTIFIER} return 'IDENTIFIER';


Expand Down
139 changes: 125 additions & 14 deletions grammar/csharp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 10278ce

Please sign in to comment.