Skip to main content

module Syntax

rascal-0.28.2
typepal-0.8.3

Usage

import examples::structParameters::Syntax;

syntax Program

start syntax Program = Declaration*;

syntax Type

syntax Type = "int" | "str" | Id TypeActuals;

syntax TypeActuals

syntax TypeActuals
= noActuals: ()
| withTypeActuals: "[" {Type ","}+ actuals "]"
;

syntax TypeHeader

syntax TypeHeader
= Id TypeFormals
;

syntax TypeFormals

syntax TypeFormals
= noTypeFormals: ()
| withTypeFormals: "[" {TypeFormal ","}+ formals"]"
;

syntax TypeFormal

syntax TypeFormal
= Id
;

syntax Declaration

syntax Declaration
= Type typ Id id "=" Expression exp ";"
| "struct" TypeHeader "{" {Field ","}* fields "}" ";"
;

syntax Field

syntax Field = Type typ Id name ;

syntax Expression

syntax Expression 
= Integer i
| String s
| Id use
| Expression lhs "." Id fieldName
| "new" Id name TypeActuals
;

syntax Keywords

keyword Keywords = "int" | "str" | "struct" | "new";