Grammar
Learning a programming language in the grammar-point of view helps you to achieve it faster.
This is No's grammar — the rules of the language and the guide of parser implementing. Completely knew it, you can learn any scripting language in the world easily.
We are presenting in pseudo code like regex.
Program
program := (decl | stmt)*A program or a single file contains multiple declarations and statements.
Declarations
A declaration always starts with a keyword: use, class, func, or var.
decl := use_decl
| class_decl
| func_decl
| var_declStatements
stmt := block_stmt
| break_stmt
| continue_stmt
| for_stmt
| if_stmt
| puts_stmt
| return_stmt
| switch_stmt
| throw_stmt
| try_stmt
| while_stmt
| (assign | increment | decrement | call)The last group is also called "expression statement". In JavaScript, it allows any expression, make sure you do not cause a syntax conflict.
Here, we limit to only active-expressions: assign, increment, decrement and call. That makes the language be clear and no redundant things.
StatementsExpressions
ExpressionsValues (primary)
This is the smallest unit in the program.
IDENTIFIER
In our language, the keywords are not reserved words, they are just identifiders. So you can use them everywhere, except variable names.
This is the pattern of parsing is:
An identifier is not a string, it present a "name".
STRING
A string always inside single-quotes or double-quotes.
We also supports slash-escape.
To write string in multi-line, just use two ` ` (grave accent).
It looks like JavaScript, but we do not support string templating or string interpolation.
NUMBER
We supports 3 kinds of number: decimal, binary and hexadecimal.
Be care while calling methods of a number. 123.str() is incorrect syntax, please group it: (123).str().
LITERAL
We have 3 keywords present literal values: null, true and false.
Last updated
Was this helpful?