소스 검색

Add names of rules as comments after section numbers for navigation.

master
Ian Piumarta 2 년 전
부모
커밋
7b881478fd
1개의 변경된 파일44개의 추가작업 그리고 1개의 파일을 삭제
  1. +44
    -1
      src/ccmeta.leg

+ 44
- 1
src/ccmeta.leg 파일 보기

@ -3,7 +3,7 @@
# Copyright (c) 2016-2021 Ian Piumarta and other contributors (see AUTHORS)
# All rights reserved (see LICENSE)
#
# Last edited: 2023-03-22 16:11:40 by piumarta on zora-10.local
# Last edited: 2023-03-22 16:30:14 by piumarta on zora-10.local
%{
/* compile: leg -o ccmeta.c ccmeta.leg
@ -1314,6 +1314,7 @@ mexp = META_AT META_LPAREN ( @{ lang = META } s:meta_exp META_RPAREN @{ lan
error = EOL* < (!EOL .)* EOL* (!EOL .)* > &{ error(yytext), 1 }
### A.1.3 Identifiers
# Identifiers rules
# 6.4.2.1
@ -1331,6 +1332,7 @@ IDREST = IDFIRST | [0-9]
digit = [0-9]
### A.1.4 Universal character names
# universalCharacterName rule
# 6.4.3
@ -1341,6 +1343,7 @@ hexQuad = hexadecimalDigit hexadecimalDigit hexadecimalDigit hexadecimalDigit
###
### A.1.5 Constants
# constant rule
# 6.4.4
@ -1351,6 +1354,7 @@ constant = characterConstant
# 6.4.4.1
# integerConstant rule
integerConstant = < ( hexadecimalConstant
| octalConstant
@ -1377,6 +1381,7 @@ integerSuffix = ( [uU][lL]?[lL]? | [lL][lL]?[uU]? ) ( imaginarySuffix &{gnu} )?
imaginarySuffix = [ij]
# 6.4.4.2
# floatingConstant rule
floatingConstant = <( decimalFloatingConstant | hexadecimalFloatingConstant )> { $$ = new_C_float(yytext); } -
@ -1404,6 +1409,7 @@ hexadecimalDigitSequence = hexadecimalDigit+
floatingSuffix = [fFlL] imaginarySuffix?
# 6.4.4.4
# characterConstant rule
characterConstant = < "'" cCharSequence "'" > { $$ = new_C_char(yytext) } -
| < "L'" cCharSequence "'" > { $$ = new_C_char(yytext) } -
@ -1425,6 +1431,7 @@ octalEscapeSequence = '\\' octalDigit octalDigit? octalDigit?
hexadecimalEscapeSequence = '\\x' hexadecimalDigit+
### A.1.6 String literals
# stringLiteral rule
# 6.4.5
@ -1438,6 +1445,7 @@ stringLiteralPart = < '"' sCharSequence '"' > { $$= new_C_char(yytext) }
sCharSequence = ( escapeSequence | !EOL [^\"\\] )*
### A.2.1 Expressions
# primaryExpression rule
# 6.5.1
@ -1447,6 +1455,7 @@ primaryExpression = stringLiteral | constant | id
| l:LPAREN x:compoundStatement r:RPAREN &{gnu} { $$= new_C_subexpr(l, x, r) }
# 6.5.2
# postfixExpression rule
postfixExpression = o:LPAREN l:typeName p:RPAREN
a:LCURLY r:initializerList ( c:COMMA | {c=newNullObject()} ) b:RCURLY { $$= new_C_aggregate(o, l, p, a, r, c, b) }
@ -1466,6 +1475,7 @@ argumentExpressionList = { listBegin() }
)? { $$= listEnd() }
# 6.5.3
# unaryExpression rule
unaryExpression = o:INC x:unaryExpression { $$= new_C_prefix(o, x) }
| o:DEC x:unaryExpression { $$= new_C_prefix(o, x) }
@ -1485,11 +1495,13 @@ unaryOperator = BAND | STAR | PLUS | MINUS | BNOT | LNOT
| IMAG &{gnu}
# 6.5.4
# castExpression rule
castExpression = l:LPAREN t:typeName r:RPAREN x:castExpression { $$= new_C_cast(l, t, r, x) }
| unaryExpression
# 6.5.5
# multiplicativeExpression rule
multiplicativeExpression = l:castExpression
( o:multiplicativeOperator r:castExpression { l= new_C_binary(l, o, r) }
@ -1498,6 +1510,7 @@ multiplicativeExpression = l:castExpression
multiplicativeOperator = STAR | DIV | MOD
# 6.5.6
# additiveExpression rule
additiveExpression = l:multiplicativeExpression
( o:additiveOperator r:multiplicativeExpression { l= new_C_binary(l, o, r) }
@ -1506,6 +1519,7 @@ additiveExpression = l:multiplicativeExpression
additiveOperator = PLUS | MINUS
# 6.5.7
# shiftExpression rule
shiftExpression = l:additiveExpression
( o:shiftOperator r:additiveExpression { l= new_C_binary(l, o, r) }
@ -1514,6 +1528,7 @@ shiftExpression = l:additiveExpression
shiftOperator = LSHIFT | RSHIFT
# 6.5.8
# relationalExpression rule
relationalExpression = l:shiftExpression
( o:relationalOperator r:shiftExpression { l= new_C_binary(l, o, r) }
@ -1522,6 +1537,7 @@ relationalExpression = l:shiftExpression
relationalOperator = LT | LTE | GT | GTE
# 6.5.9
# equalityExpression rule
equalityExpression = l:relationalExpression
( o:equalityOperator r:relationalExpression { l= new_C_binary(l, o, r) }
@ -1530,36 +1546,42 @@ equalityExpression = l:relationalExpression
equalityOperator = EQUAL | NOT_EQUAL
# 6.5.10
# andExpression rule
andExpression = l:equalityExpression
( o:BAND r:equalityExpression { l= new_C_binary(l, o, r) }
)* { $$= l }
# 6.5.11
# exclusiveOrExpression rule
exclusiveOrExpression = l:andExpression
( o:BXOR r:andExpression { l= new_C_binary(l, o, r) }
)* { $$= l }
# 6.5.12
# inclusiveOrExpression rule
inclusiveOrExpression = l:exclusiveOrExpression
( o:BOR r:exclusiveOrExpression { l= new_C_binary(l, o, r) }
)* { $$= l }
# 6.5.13
# logicalAndExpression rule
logicalAndExpression = l:inclusiveOrExpression
( o:LAND r:inclusiveOrExpression { l= new_C_binary(l, o, r) }
)* { $$= l }
# 6.5.14
# logicalOrExpression rule
logicalOrExpression = l:logicalAndExpression
( o:LOR r:logicalAndExpression { l= new_C_binary(l, o, r) }
)* { $$= l }
# 6.5.15
# conditionalExpression rule
conditionalExpression = l:logicalOrExpression
( q:QUESTION m:expression c:COLON r:conditionalExpression { $$= new_C_conditional(l, q, m, c, r) }
@ -1568,6 +1590,7 @@ conditionalExpression = l:logicalOrExpression
)
# 6.5.16
# assignmentExpressionOpt rule
assignmentExpressionOpt = assignmentExpression | {$$=newNullObject()}
@ -1579,6 +1602,7 @@ assignmentOperator = ASSIGN
| LSHIFT_ASSIGN | RSHIFT_ASSIGN | BAND_ASSIGN | BXOR_ASSIGN | BOR_ASSIGN
# 6.5.17
# expression rule
expression = l:assignmentExpression
( o:COMMA r:assignmentExpression { l= new_C_binary(l, o, r) }
@ -1589,6 +1613,7 @@ expressionOpt = expression | { $$= newNullObject() }
constantExpression = conditionalExpression
### A.2.2 Declarations
# declaration rule
# 6.7
@ -1623,6 +1648,7 @@ initDeclarator = d:declarator
)? { $$= d }
# 6.7.1
# storageClassSpecifier rule
storageClassSpecifier = TYPEDEF @{ declarationTypedef() }
| AUTO
@ -1634,6 +1660,7 @@ parameterStorageClassSpecifier = REGISTER
functionStorageClassSpecifier = EXTERN | STATIC
# 6.7.2
# typeSpecifier rule
typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UNSIGNED | BOOL | COMPLEX
| ( BUILTIN_VA_LIST | _FLOAT128 )
@ -1641,6 +1668,7 @@ typeSpecifier = VOID | CHAR | SHORT | INT | LONG | FLOAT | DOUBLE | SIGNED | UN
| enumSpecifier
# 6.7.2.1
# structOrUnionSpecifier rule
structOrUnionSpecifier = s:structOrUnion
# An attribute specifier list may appear as part of a struct, union or enum specifier. It may go
@ -1689,6 +1717,7 @@ structDeclarator = ( c:COLON e:constantExpression { d= new_C_st
)? { $$= d }
# 6.7.2.2
# enumSpecifier rule
enumSpecifier = e:ENUM
( i:idOpt l:LCURLY m:enumeratorList r:RCURLY { $$= new_C_enumSpec(e, i, l, m, r) }
@ -1709,16 +1738,19 @@ enumerator = i:id
( a:ASSIGN e:constantExpression | {a=e=newNullObject()} ) { $$= new_C_enumerator(i, a, e) }
# 6.7.3
# typeQualifier rule
typeQualifier = CONST | RESTRICT | VOLATILE
| __RESTRICT
# 6.7.4
# functionSpecifier rule
functionSpecifier = INLINE
| __INLINE
# 6.7.5
# declarator rule
declarator = # An attribute specifier list may appear immediately before a declarator
a:attributeSpecifier d:declarator &{gnu} { $$= new_C_attribution(a, d) }
@ -1785,6 +1817,7 @@ identifierList = i:id { listWith(i) }
)* { $$= listEnd() }
# 6.7.6
# typeName rule
typeName = s:specifierQualifierList d:abstractDeclaratorOpt { $$= new_C_declaration(s, d, newNullObject()) }
@ -1807,6 +1840,7 @@ directAbstractDeclarator= @{int nonEmpty= 0}
)* &{nonEmpty} { $$= d }
# 6.7.7
# typedefName rule
typedefName = <ID> &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } -
| t:TYPEOF l:LPAREN
@ -1815,6 +1849,7 @@ typedefName = &{ isTypedefName(yytext) } { $$= new_C_id(yytext) } -
) &{gnu}
# 6.7.8
# initializer rule
initializer = l:LCURLY i:initializerList ( c:COMMA | {c=newNullObject()} ) r:RCURLY { $$= new_C_initializer(l, i, c, r) }
| assignmentExpression
@ -1839,6 +1874,7 @@ designatorList = { listBegin() }
)+ { $$= listEnd() }
### A.2.3 Statements
# statement rule
# 6.8
@ -1850,6 +1886,7 @@ statement = expressionStatement
| jumpStatement
# 6.8.1
# labeledStatement rule
labeledStatement = i:id c:COLON
# an attribute specifier list may appear after the colon following a label, other than a case or default label
@ -1860,6 +1897,7 @@ labeledStatement = i:id c:COLON
| d:DEFAULT c:COLON s:statement { $$= new_C_default(d, c, s) }
# 6.8.2
# compoundStatement rule
compoundStatement = @{ C_scopeBegin() }
l:LCURLY { listBegin() }
@ -1875,17 +1913,20 @@ compoundStatement = @{ C_scopeBegin() }
| &{ C_scopeAbort() }
# 6.8.3
# expressionStatement rule
expressionStatement = SEMI
| x:expression s:SEMI { $$= new_C_exprStatement(x, s) }
# 6.8.4
# selectionStatement rule
selectionStatement = i:IF l:LPAREN x:expression r:RPAREN s:statement
( e:ELSE t:statement | {e=t=newNullObject()} ) { $$= new_C_if(i, l, x, r, s, e, t) }
| s:SWITCH l:LPAREN x:expression r:RPAREN t:statement { $$= new_C_switch(s, l, x, r, t) }
# 6.8.5
# iterationStatement rule
iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement { $$= new_C_while(w, l, x, r, s) }
| d:DO s:statement w:WHILE l:LPAREN x:expression r:RPAREN t:SEMI { $$= new_C_do(d, s, w, l, x, r, t) }
@ -1895,6 +1936,7 @@ iterationStatement = w:WHILE l:LPAREN x:expression r:RPAREN s:statement { $$=
c:expressionOpt r:RPAREN s:statement { $$= new_C_for(f, l, a, newNullObject(), b, u, c, r, s) }
# 6.8.6
# jumpStatement rule
jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, newNullObject(), i, t) }
| c:CONTINUE t:SEMI { $$= new_C_continue(c, t) }
@ -1903,6 +1945,7 @@ jumpStatement = g:GOTO i:id t:SEMI { $$= new_C_goto(g, newNullObject(), i
| g:GOTO s:STAR x:expression t:SEMI &{gnu} { $$= new_C_goto(g, s, x, t) }
### A.2.4 External definitions
# externalDeclaration rule
# 6.9

불러오는 중...
취소
저장