yenru0 9c94663045 minor implementation
basic expr parsing (not complex like compound, lambda)
2025-11-25 23:29:57 +09:00
2025-11-25 23:29:57 +09:00
2025-11-25 23:29:57 +09:00
2025-11-15 08:01:34 +09:00
2025-11-17 15:48:37 +09:00
2025-11-23 22:07:04 +09:00
2025-11-25 23:29:57 +09:00
2025-11-17 15:48:51 +09:00

C-val Compiler

Lexical Spec

  • LBRACK [
  • RBRACK ]
  • LCURLY {
  • RCURLY }
  • LPAREN (
  • RPAREN )
  • ID [any character without whitespace]+
  • SEMI ;
  • COMMA ,
  • ARROW ->
  • STAR *
  • ANDREF &
  • DOLLAR $
  • COMMENT //
  • NUM [0-9]*
  • VAL
  • STRING "{any}"

Syntax Spec

program     := defn*

defn        := VAL type ID ;
             | VAL type ID expr ;

type        := ID | type STAR
             | LBRACK RBRACK | LBRACK type RBRACK
             | LBRACK type* ARROW type? RBRACK

expr        := atom atom*

atom        := ID
             | NUM
             | STR
             | lambda
             | compound
             | STAR
             | ANDREF

stmt        := defn
             | expr ;        // expr statement
             | return expr ; // return statement
             | DOLLAR ID expr ;   // assignment statement
             | if expr compound ;               // if statement
             | if expr compound else compound ; // if-else statement

param_list  := LPAREN (type ID)* RPAREN

lambda      := param_list compound

compound    := LCURLY (stmt)* expr? RCURLY

AST Spec

NODE_PROGRAM:
    token: PROGRAM
    children: NODE_DEFN*

NODE_DEFN:
    token: VAL
    children: NODE_TYPE, TOKEN_ID, (NODE_EXPR)?
    children_count: 2 | 3

NODE_TYPE_SIMPLE:
    token: ID  
    children: NODE_ID NODE_TYPE_STAR*
    children_count: 1+
NODE_TYPE_COMPLEX:
    token: COMPLEX_TYPE
    children: NODE_TYPE_PARAM NODE_TYPE_OUT
NODE_TYPE_PARAM
    token: TYPE_PARAM
    children: (NODE_TYPE | NODE_TYPE_COMPLEX)*
    children_count: 0+
NODE_TYPE_OUT
    token: TYPE_OUT
    children: (NODE_TYPE | NODE_TYPE_COMPLEX)?

NODE_EXPR:
    token: EXPR
    children: (atom)+
// atom definition
NODE_NUM:
    token: NUM
NODE_STR:
    token: STR
NODE_LAMBDA:
    token: LAMBDA
    children: NODE_PARAM_LIST NODE_COMPOUND
NODE_COMPOUND:
    token: COMPOUND
    children: (NODE_STMT)* (NODE_EXPR)?
    children_count: 0+
    

NODE_PARAM_LIST:
    token: PARAM_LIST
    children: NODE_PARAM*
NODE_PARAM:
    token: PARAM
    children: NODE_TYPE, TOKEN_ID

Description
cval compiler
Readme 56 KiB
Languages
C 97.1%
Makefile 2.9%