chharvey / counterpoint

A robust programming language.
GNU Affero General Public License v3.0
2 stars 0 forks source link

Tokenize, Parse, & Decorate: Primitive Literal Keywords #18

Closed chharvey closed 4 years ago

chharvey commented 4 years ago

Tokenize the primitive literals null, false, and true.

Simply add them to the reserved keywords list in the lexical grammar.

Keyword :::=
    | "null"
    | "false"
    | "true"
;

The TokenWorth attribute grammar adds these keywords.

TokenWorth(Keyword :::= "null" ) -> RealNumber := \x82;
TokenWorth(Keyword :::= "false") -> RealNumber := \x83;
TokenWorth(Keyword :::= "true" ) -> RealNumber := \x84;

In the syntactic grammar, allow these keywords as primitive literals.

PrimitiveLiteral ::=
    | "null"
    | "false"
    | "true"
    | NUMBER
    | STRING
;

The decoration attribute grammar:

Decorate(PrimitiveLiteral ::= "null") -> SemanticConstant
    := SemanticConstant {value: null} [];
Decorate(PrimitiveLiteral ::= "false") -> SemanticConstant
    := SemanticConstant {value: false} [];
Decorate(PrimitiveLiteral ::= "true") -> SemanticConstant
    := SemanticConstant {value: true} [];