📄 sg_pascal.cpp
字号:
constantIdentifier
= identifier
;
string
= STRING_LITERAL
;
typeDefinitionPart
= TYPE >> typeDefinition >> *( SEMI >> typeDefinition ) >> SEMI
;
typeDefinition
= identifier >> EQUAL >> type
;
type
= simpleType
| structuredType
| pointerType
;
simpleType
= scalarType
| subrangeType
| typeIdentifier
;
scalarType
= LPAREN >> identifier >> *( COMMA >> identifier ) >> RPAREN
;
subrangeType
= constant >> DOTDOT >> constant
;
typeIdentifier
= identifier
| CHAR
| BOOLEAN
| INTEGER
| REAL
;
structuredType
= ( PACKED
| empty
) >>
unpackedStructuredType
;
unpackedStructuredType
= arrayType
| recordType
| setType
| fileType
;
arrayType
= ARRAY >> LBRACK >> indexType >> *( COMMA >> indexType ) >> RBRACK >> OF >>
componentType
;
indexType
= simpleType
;
componentType
= type
;
recordType
= RECORD >> fieldList >> END
;
fieldList
= fixedPart >>
( SEMI >> variantPart
| empty
)
| variantPart
;
fixedPart
= recordSection >> *( SEMI >> recordSection )
;
recordSection
= fieldIdentifier >> *( COMMA >> fieldIdentifier ) >> COLON >> type
| empty
;
variantPart
= CASE >> tagField >> typeIdentifier >> OF >>
variant >> *( SEMI >> variant )
;
tagField
= fieldIdentifier >> COLON
| empty
;
variant
= caseLabelList >> COLON >> LPAREN >> fieldList >> RPAREN
| empty
;
caseLabelList
= caseLabel >> *( COMMA >> caseLabel )
;
caseLabel
= constant
;
setType
= SET >> OF >> baseType
;
baseType
= simpleType
;
fileType
= FILE >> OF >> type
;
pointerType
= POINTER >> typeIdentifier
;
variableDeclarationPart
= VAR >> variableDeclaration >> *( SEMI >> variableDeclaration ) >> SEMI
;
variableDeclaration
= identifier >> *( COMMA >> identifier ) >> COLON >> type
;
procedureAndFunctionDeclarationPart
= procedureOrFunctionDeclaration >> SEMI
;
procedureOrFunctionDeclaration
= procedureDeclaration
| functionDeclaration
;
procedureDeclaration
= procedureHeading
>> block
;
procedureHeading
= PROCEDURE >> identifier >> parameterList >> SEMI
;
parameterList
= empty
| LPAREN >> formalParameterSection >> *( SEMI >> formalParameterSection ) >> RPAREN
;
formalParameterSection
= parameterGroup
| VAR >> parameterGroup
| FUNCTION >> parameterGroup
| PROCEDURE >> identifier >> *( COMMA >> identifier )
;
parameterGroup
= identifier >> *( COMMA >> identifier ) >> COLON >> typeIdentifier
;
functionDeclaration
= functionHeading >>
block
;
functionHeading
= FUNCTION >> identifier >> parameterList >> COLON >> resultType >> SEMI
;
resultType
= typeIdentifier
;
statementPart
= compoundStatement
;
statement
= ( label >> COLON
| empty
) >>
unlabelledStatement
;
unlabelledStatement
= structuredStatement
| simpleStatement
;
simpleStatement
= assignmentStatement
| procedureStatement
| gotoStatement
| emptyStatement
;
assignmentStatement
= variable >> ASSIGN >> expression
| functionIdentifier >> ASSIGN >> expression
;
variable
= componentVariable
| referencedVariable
| entireVariable
;
entireVariable
= variableIdentifier
;
variableIdentifier
= identifier
;
componentVariable
= indexedVariable
| fieldDesignator
| fileBuffer
;
indexedVariable
= arrayVariable >> LBRACK >> expression >> *( COMMA >> expression) >> RBRACK
;
arrayVariable
= identifier
;
fieldDesignator
= recordVariable >> DOT >> fieldIdentifier
;
recordVariable
= identifier
;
fieldIdentifier
= identifier
;
fileBuffer
= fileVariable >> POINTER
;
fileVariable
= identifier
;
referencedVariable
= pointerVariable >> POINTER
;
pointerVariable
= identifier
;
expression
= simpleExpression >>
( relationalOperator >> simpleExpression
| empty
)
;
relationalOperator
= EQUAL | NOT_EQUAL | GE | LE | LT | GT | IN
;
simpleExpression
= ( sign
| empty
) >>
term >> *( addingOperator >> term )
;
addingOperator
= PLUS | MINUS | OR
;
term
= factor >> *( multiplyingOperator >> factor )
;
multiplyingOperator
= STAR | SLASH | DIV | MOD | AND
;
factor
= LPAREN >> expression >> RPAREN
| set
| longest[
variable
| unsignedConstant
| functionDesignator
]
| NOT >> factor
;
unsignedConstant
= unsignedNumber
| string
| constantIdentifier
| NIL
;
functionDesignator
= functionIdentifier >>
( LPAREN >> actualParameter >> *( COMMA >> actualParameter ) >> RPAREN
| empty
)
;
functionIdentifier
= identifier
;
set
= LBRACK >> elementList >> RBRACK
;
elementList
= element >> *( COMMA >> element )
| empty
;
element
= expression >>
( DOTDOT >> expression
| empty
)
;
procedureStatement
= procedureIdentifier >>
( LPAREN >> actualParameter >> *( COMMA >> actualParameter ) >> RPAREN
| empty
)
;
procedureIdentifier
= identifier
;
actualParameter
= expression
| variable
| procedureIdentifier
| functionIdentifier
;
gotoStatement
= GOTO >> label
;
emptyStatement
= empty
;
empty
= epsilon
;
structuredStatement
= compoundStatement
| conditionalStatement
| repetetiveStatement
| withStatement
;
compoundStatement
= BEGIN >>
statement >> *( SEMI >> statement ) >>
END
;
conditionalStatement
= ifStatement
| caseStatement
;
ifStatement
= IF >> expression >> THEN >> statement >>
( ELSE >> statement
| empty
)
;
caseStatement
= CASE >> expression >> OF >>
caseListElement >> *( SEMI >> caseListElement ) >>
END
;
caseListElement
= caseLabelList >> COLON >> statement
| empty
;
repetetiveStatement
= whileStatement
| repeatStatement
| forStatement
;
whileStatement
= WHILE >> expression >> DO >>
statement
;
repeatStatement
= REPEAT >>
statement >> *( SEMI >> statement ) >>
UNTIL >> expression
;
forStatement
= FOR >> controlVariable >> ASSIGN >> forList >> DO >>
statement
;
forList
= initialValue >> ( TO | DOWNTO ) >> finalValue
;
controlVariable
= identifier
;
initialValue
= expression
;
finalValue
= expression
;
withStatement
= WITH >> recordVariableList >> DO >>
statement
;
recordVariableList
= recordVariable >> *( COMMA >> recordVariable )
;
//----------------------------------------------------------------------------
// End grammar definition
//----------------------------------------------------------------------------
if (argc == 2)
{
parse(program, argv[1]);
}
else
{
cout << "no filename given" << endl;
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -