Expr
Rules
program
header
block
declaration
varList
varId
typeId
functionId
function
functionDefinition
functionCall
identifiers
parameters
stmt
stmtList
declareStmt
assignmentStmt
printStmt
ifStrStmt
ifStmt
forStmt
formatString
printArg
variable
expr
mulDivOp
addSubOp
relOp
signedNumber
sign
number
boolType
PROGRAM
BEGIN
END
PRINTF
IF
ELSE
FOR
RETURN
INTEGER
DECIMAL
BOOL
MUL_OP
DIV_OP
ADD_OP
SUB_OP
EQ_OP
NE_OP
LT_OP
LE_OP
GT_OP
GE_OP
NEWLINE
WS
QUOTE
STRING
STRING_CHAR
IDENTIFIER
program
Top
Text notation:
program
:
header
(
stmtList
)
?
block
;
Visual notation:
header
Top
Text notation:
header
:
PROGRAM
IDENTIFIER
;
Visual notation:
block
Top
Text notation:
block
:
BEGIN
(
functionDefinition
|
stmtList
)
*
END
;
Visual notation:
declaration
Top
Text notation:
declaration
:
typeId
varId
#
variableDeclaration
;
Visual notation:
varList
Top
Text notation:
varList
:
varId
(
','
varId
)
*
;
Visual notation:
varId
Top
Text notation:
varId
:
IDENTIFIER
;
Visual notation:
typeId
Top
Text notation:
typeId
:
IDENTIFIER
;
Visual notation:
functionId
Top
Text notation:
functionId
:
IDENTIFIER
;
Visual notation:
function
Top
Text notation:
function
:
IDENTIFIER
;
Visual notation:
functionDefinition
Top
Text notation:
functionDefinition
:
typeId
functionId
'('
parameters
?
')'
'{'
stmtList
?
RETURN
(
expr
)
?
';'
'}'
;
Visual notation:
functionCall
Top
Text notation:
functionCall
:
function
'('
identifiers
?
')'
;
Visual notation:
identifiers
Top
Text notation:
identifiers
:
expr
(
','
expr
)
*
;
Visual notation:
parameters
Top
Text notation:
parameters
:
declaration
(
','
declaration
)
*
;
Visual notation:
stmt
Top
Text notation:
stmt
:
declareStmt
|
assignmentStmt
|
printStmt
|
ifStmt
|
ifStrStmt
|
forStmt
|
;
Visual notation:
stmtList
Top
Text notation:
stmtList
:
(
stmt
';'
)
+
;
Visual notation:
declareStmt
Top
Text notation:
declareStmt
:
typeId
varList
;
Visual notation:
assignmentStmt
Top
Text notation:
assignmentStmt
:
variable
'='
expr
;
Visual notation:
printStmt
Top
Text notation:
printStmt
:
PRINTF
'('
formatString
printArg
*
')'
;
Visual notation:
ifStrStmt
Top
Text notation:
ifStrStmt
:
IF
STRING
relOp
STRING
','
'{'
stmtList
'}'
;
Visual notation:
ifStmt
Top
Text notation:
ifStmt
:
IF
expr
','
'{'
stmtList
'}'
(
ELSE
'{'
stmtList
'}'
)
?
;
Visual notation:
forStmt
Top
Text notation:
forStmt
:
FOR
'('
number
'x'
')'
'{'
stmtList
'}'
;
Visual notation:
formatString
Top
Text notation:
formatString
:
STRING
;
Visual notation:
printArg
Top
Text notation:
printArg
:
','
expr
;
Visual notation:
variable
Top
Text notation:
variable
:
IDENTIFIER
;
Visual notation:
expr
Top
Text notation:
expr
:
expr
relOp
expr
#
relExpr
|
expr
mulDivOp
expr
#
mulDivExpr
|
expr
addSubOp
expr
#
addSubExpr
|
number
#
unsignedNumberExpr
|
signedNumber
#
signedNumberExpr
|
boolType
#
boolExpr
|
variable
#
variableExpr
|
'('
expr
')'
#
parenExpr
|
functionCall
#
funcCallExpr
;
Visual notation:
mulDivOp
Top
Text notation:
mulDivOp
:
MUL_OP
|
DIV_OP
;
Visual notation:
addSubOp
Top
Text notation:
addSubOp
:
ADD_OP
|
SUB_OP
;
Visual notation:
relOp
Top
Text notation:
relOp
:
EQ_OP
|
NE_OP
|
LT_OP
|
LE_OP
|
GT_OP
|
GE_OP
;
Visual notation:
signedNumber
Top
Text notation:
signedNumber
:
sign
number
;
Visual notation:
sign
Top
Text notation:
sign
:
ADD_OP
|
SUB_OP
;
Visual notation:
number
Top
Text notation:
number
:
INTEGER
#
integerConst
|
DECIMAL
#
floatConst
;
Visual notation:
boolType
Top
Text notation:
boolType
:
BOOL
#
boolConst
;
Visual notation:
PROGRAM
Top
Text notation:
PROGRAM
:
'start'
;
Visual notation:
BEGIN
Top
Text notation:
BEGIN
:
'{.'
;
Visual notation:
END
Top
Text notation:
END
:
'.}'
;
Visual notation:
PRINTF
Top
Text notation:
PRINTF
:
'print'
;
Visual notation:
IF
Top
Text notation:
IF
:
'if'
;
Visual notation:
ELSE
Top
Text notation:
ELSE
:
'else'
;
Visual notation:
FOR
Top
Text notation:
FOR
:
'for'
;
Visual notation:
RETURN
Top
Text notation:
RETURN
:
'return'
;
Visual notation:
INTEGER
Top
Text notation:
INTEGER
: [
0-9
]
+
;
Visual notation:
DECIMAL
Top
Text notation:
DECIMAL
: [
0-9
]
+
'.'
[
0-9
]
+
;
Visual notation:
BOOL
Top
Text notation:
BOOL
:
'true'
|
'false'
;
Visual notation:
MUL_OP
Top
Text notation:
MUL_OP
:
'*'
;
Visual notation:
DIV_OP
Top
Text notation:
DIV_OP
:
'/'
;
Visual notation:
ADD_OP
Top
Text notation:
ADD_OP
:
'+'
;
Visual notation:
SUB_OP
Top
Text notation:
SUB_OP
:
'-'
;
Visual notation:
EQ_OP
Top
Text notation:
EQ_OP
:
'=='
|
'is'
|
'are'
;
Visual notation:
NE_OP
Top
Text notation:
NE_OP
:
'=/='
|
'is not'
|
'are not'
;
Visual notation:
LT_OP
Top
Text notation:
LT_OP
:
'<'
;
Visual notation:
LE_OP
Top
Text notation:
LE_OP
:
'<='
;
Visual notation:
GT_OP
Top
Text notation:
GT_OP
:
'>'
;
Visual notation:
GE_OP
Top
Text notation:
GE_OP
:
'>='
;
Visual notation:
NEWLINE
Top
Text notation:
NEWLINE
:
'\r'
?
'\n'
->
skip
;
Visual notation:
WS
Top
Text notation:
WS
: [
\t
]
+
->
skip
;
Visual notation:
QUOTE
Top
Text notation:
QUOTE
:
'"'
;
Visual notation:
STRING
Top
Text notation:
STRING
:
QUOTE
STRING_CHAR
*
QUOTE
;
Visual notation:
STRING_CHAR
Top
Text notation:
STRING_CHAR
:
QUOTE
QUOTE
|
~
(
'"'
)
;
Visual notation:
IDENTIFIER
Top
Text notation:
IDENTIFIER
: [
a-zA-Z
][
a-zA-Z0-9
]
*
;
Visual notation: