-
Notifications
You must be signed in to change notification settings - Fork 0
0.1.0 Grammar
Update 2/26/19: While this is a work in progress, it is closer to freezing for a point release as I move from the parser to semantic analyzer.
Update 3/3/19: Still WIP as it becomes clear that, in attempt to write the TypeChecker, some of the previous grammar was nonsensical.
Update 3/11/19: Seriously major changes since implementing semantic analysis. Going into code generation, I believe this should be very close to finalized for 0.1.0.
Update 3/13/19: Adding some new features that logically make sense for 0.1.0, but whose absence was not realized until the actually writing of some sailfish code.
Update 3/14/19: Simplified grammar to wrap head around a smaller subset to clean up codebase and ensure all is properly working before moving on.
Update 3/17/19: Version freeze. 0.1.0 Dorsalfin released.
Start := Source
Source := SourcePart*
SourcePart := FunctionDefinition | GeneralDecleration | InitialExecutionBody | UserDefinedTypeDefinition
FunctionDefinition := FunctionName FunctionInput FunctionOutput FunctionBody
FunctionName := 'fun' Identifier
FunctionInput := '<-' InputList
FunctionOutput := '->' Output
FunctionBody := Block
InputList := Input (',' Input)*
Input := Variable
Output := Typename
GeneralDecleration := 'dec' GeneralDefinition
GeneralDefinition := NewUDTDefinition | PrimitiveDefinition
NewUDTDefinition := Variable '=' NewExpression
PrimitiveDefinition := Variable '=' BinaryExpression
Variable := TypeName Identifier
Typename := Identifier
InitialExecutionBody := 'start' 'Block
UserDefinedTypeDefinition := 'Cat' UserDefinedTypeAttributes UserDefinedTypeMethods
UserDefinedTypeAttributes := Identifier '{' Variable '}'
UserDefinedTypeMethods := 'Cfn' Identifier '{' FunctionDefinition '}'
Block := '{' Statement* '}'
Statement := IfStatement | Block | ReturnStatement | GeneralDecleration | BinaryExpression
IfStatement := 'if' GroupingExpression Block 'else' Statement **Statement can only be a return, block, or if**
ReturnStatement := 'return' Expression
BinaryExpression := Exponentiation | MultDivMod | Arithmetic | Comparison | Equivalence | LogicalComparison | Assignment | ExpressionOnlyStatement
Exponentiation := Expression '**' Expression
MultDivMod := Expression ['*' | '/' | '%'] Expression
Arithmetic := Expression ['+' | '-'] Expression
Comparison := Expression ['<', '<=', '>', '>='] Expression
Equivalence := Expression ['!=', '=='] Expression
LogicalComparison := Expression ['and' | 'or'] Expression
Assignment := Expression '=' Expression
FunctionCall := Expression '(' [Identifier] (',' Identifier)*')'
ExpressionOnlyStatement := Expression
Expression := NewExpression |
GroupingExpression |
UnaryExpression |
PrimaryExpression
NewExpression := 'new' New
New := UserDefinedType
GroupingExpression := '|' BinaryExpression '|'
MemberAccess := AttributeAccess | AttributeMethodAccess | MethodAccess
AttributeAccess := Identifier '.' Identifier
AttributeMethodAccess := AttributeAccess '...' Identifier FunctionCall
MethodAccess := Identifier '...' Identifier FunctionCall
UnaryExpression := Negation
Negation := '!' Expression
PrimaryExpression := Primary
Primary := BooleanLiteral | NumberLiteral | StringLiteral | Identifier | MethodAccess | AttributeAccess | FunctionCall
BooleanLiteral := 'true' | 'false'
UserDefinedType := Identifier '{' [UDTitem (',' UDTitem)*] '}'
UDTitem := Identifier : Primary
NumberLiteral := Integer | Decimal
Integer := [0-9]+
Decimal := [0-9]+.[0-9]+
StringLiteral := "' ([^"\r\n\] | '\' .)* '"'
Identifier := [a-zA-Z] [a-zA-Z_0-9]*