MontiCore - Literals
Literals are the basis to parse numbers, strings and other atomic language
elements. The language module MCLiteralBasis
defines the root nonterminal
Literal
but no other terminals representing literal terms.
MCCommonLiterals,
MCJavaLiterals, and
SIUnitLiterals
define concrete literal terms that can
be included in a MontiCore-based language as desired.
Grammar MCCommonLiterals.mc4
This grammar includes the following parser rules:
NullLiteral
: Recognizesnull
.BooleanLiteral
: Recognizestrue
andfalse
.CharLiteral
: Recognizesa
, ... ,Z
.StringLiteral
: Recognizes"..."
.NatLiteral
: Recognizes literals like123
.SignedNatLiteral
: Recognizes literals like-13
.BasicLongLiteral
: Recognizes literals like6L
and6l
.SignedBasicLongLiteral
: Recognizes literals like-6L
,-6l
,6L?
, and6l
.BasicFloatLiteral
: Recognizes literals like1.2F
and1.2f
.SignedBasicFloatLiteral
: Recognizes literals like-1.2F
,-1.2f
,1.2F
, and1.2f
.
Grammar MCJavaLiterals.mc4
This grammar extends MCCommonLiterals
and includes the following parser
rules:
IntLiteral
: Recognizes literals like123
,0734
,1001001
, and0x1a
.LongLiteral
: Recognizes literals like2L
,0734l
,1001001L
, and0x1al
.FloatLiteral
: Recognizes literals like1.23F
and1.23E4f
.DoubleLiteral
: Recognizes literals like1.23
,1.23d
,1.23E4D
.
Grammar SIUnitLiterals.mc4
This grammar allows recognition of SI unit literals like 1km/h
.
This is documented in SIUnits
.