Arithmetics¶
Source: examples/arithmetics
arithmetics is the smallest example that still shows the full Pegium loop: parser, language services, validation, formatting, CLI, LSP server, and VS Code client.
What it shows¶
- a parser for
.calc - a small evaluator
- a formatter
- a stdio LSP server
- a VS Code client
Entry points¶
- CLI:
./build/examples/arithmetics/pegium-example-arithmetics-cli - LSP:
./build/examples/arithmetics/pegium-example-arithmetics-lsp
What to read first¶
examples/arithmetics/src/arithmetics/core/ArithmeticParser.hppfor the grammar and rule definitionsexamples/arithmetics/src/arithmetics/core/ast.hppfor the AST shapeexamples/arithmetics/src/arithmetics/core/CoreModule.cppfor service wiringexamples/arithmetics/src/arithmetics/core/Language.cppfor evaluating the parsed ASTexamples/arithmetics/src/arithmetics/core/validation/ArithmeticsValidator.cppfor semantic checksexamples/arithmetics/src/arithmetics/lsp/ArithmeticsFormatter.cppfor formatter rules
Use this example when¶
- your language is expression-heavy
- you need precedence and associativity
- you want to study
InfixRule(precedence-climbing infix expressions) - you want the smallest full formatter example