Coder Social home page Coder Social logo

punkt's Introduction

Punkt

Punkt (pronounced pυηkt) means dot, point or period in German.

Tokens

Token type REGEX
keyword bool call char const else for function if int main print return string var void
identifier [ _ a-z A-Z ] [ _ a-z A-Z 0-9 ]*
booleanLiteral true false
characterLiteral ' <printable-char> '
integerLiteral [ 0-9 ]+
stringLiteral "[ ^ " \n ]*"
Arithmetic operators + - * /
Comparison operators == != > >= < <=
Punctuators { } ( ) = . , < > ->

Grammar

This is a description of Punkt grammar, simplified slightly for better readability. The grammar that the Punkt parser actually implements is entirely unambiguous.

$$\begin{aligned} Program \rightarrow & \enspace FunctionDefinition^* \enspace \texttt{main} \enspace CodeBlock \\[16pt] FunctionDefinition \rightarrow & \enspace \texttt{function} \enspace identifier \enspace Lambda \\[16pt] Lambda \rightarrow & \enspace \texttt{<} \enspace ParameterList^? \enspace \texttt{>} \enspace \texttt{->} \enspace Type \enspace CodeBlock \\[16pt] ParameterList \rightarrow & \enspace Type \enspace identifier \enspace (\texttt{,} \enspace Type \enspace identifier)^* \\[16pt] CodeBlock \rightarrow & \enspace \texttt{\{} \enspace Statement^* \enspace \texttt{\}} \\[16pt] Statement \rightarrow & \enspace CodeBlock \\\ | & \enspace DeclarationStatement \\\ | & \enspace ExpressionStatement \\\ | & \enspace IfStatement \\\ | & \enspace WhileStatement \\\ | & \enspace ForStatement \\\ | & \enspace ReturnStatement \\\ | & \enspace PrintStatement \\[16pt] DeclarationStatement \rightarrow & \enspace \texttt{const} \enspace identifier \enspace \texttt{=} \enspace Expression \enspace \texttt{.} \\\ | & \enspace \texttt{var} \enspace identifier \enspace \texttt{=} \enspace Expression \enspace \texttt{.} \\[16pt] ExpressionStatement \rightarrow & \enspace Expression \enspace \texttt{.} \\[16pt] IfStatement \rightarrow & \enspace \texttt{if} \enspace Expression \enspace (Statement \enspace | \enspace CodeBlock) \enspace (\texttt{else} \enspace (Statement \enspace | \enspace CodeBlock))^? \\[16pt] WhileStatement \rightarrow & \enspace \texttt{while} \enspace Expression \enspace (Statement \enspace | \enspace CodeBlock) \\[16pt] ForStatement \rightarrow & \enspace \texttt{for} \enspace (DeclarationStatement \enspace | \enspace Expression) \enspace \texttt{,} \enspace Expression \enspace \texttt{,} \enspace Expression \enspace CodeBlock \\[16pt] ReturnStatement \rightarrow & \enspace \texttt{return} \enspace Expression^? \enspace \texttt{.} \\[16pt] PrintStatement \rightarrow & \enspace \texttt{print} \enspace PrintExpressionList \enspace \texttt{.} \\\ | & \enspace \texttt{println} \enspace PrintExpressionList \enspace \texttt{.} \\[16pt] PrintExpressionList \rightarrow & \enspace Expression \enspace (\texttt{,} \enspace Expression)^* \\[16pt] Type \rightarrow & \enspace BaseType \\\ | & \enspace ArrayType \\\ | & \enspace LambdaType \\[16pt] BaseType \rightarrow & \enspace \texttt{void} \\\ | & \enspace \texttt{bool} \\\ | & \enspace \texttt{char} \\\ | & \enspace \texttt{int} \\\ | & \enspace \texttt{string} \\[16pt] ArrayType \rightarrow & \enspace \texttt{[} \enspace Type \enspace \texttt{]} \\[16pt] LambdaType \rightarrow & \enspace \texttt{<} \enspace TypeList^? \enspace \texttt{>} \enspace \texttt{->} \enspace Type \\[16pt] TypeList \rightarrow & \enspace Type \enspace (\texttt{,} \enspace Type)^* \end{aligned}$$

Notes

  • Comments start with # and continue until either the next # or the end of the line.
  • Maximum identifier length is 32 characters.
  • Non-void functions with no return statement cause a runtime error.
  • Declaration statements that are part of a for-loop should not end with a terminator (.).

punkt's People

Contributors

vmishelcs avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.