Bläddra i källkod

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

master
Ian Piumarta 2 år sedan
förälder
incheckning
7b881478fd
1 ändrade filer med 44 tillägg och 1 borttagningar
  1. +44
    -1
      src/ccmeta.leg

+ 44
- 1
src/ccmeta.leg Visa fil

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

Laddar…
Avbryt
Spara