Skip to content

Latest commit

 

History

8 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

e

Is is a cut down version of evy.

This repository demonstrates how to build a minimal lexer and parser from scratch without using any external libraries.

Try the e command with:

go run main.go test.e

Syntax grammar

prog = { stmt } .
stmt = decl | assign .

decl  = ident ":" type .
ident = LETTER { LETTER | DIGIT } .
type  = "num" | "string" | "bool" .

assign = ident "=" expr .

expr    = operand | unary_expr |
          binary_expr .
operand = literal | ident | group .
literal = /* e.g. "abc", 1, 2.34, true, false */ .
group   = "(" expr ")" .

unary_expr = UNARY_OP expr .
UNARY_OP   = "-" | "!" .

binary_expr = expr BINARY_OP expr .
BINARY_OP = "*" | "/" | "%" |
            "+" | "-" |
            "<" | "<=" | ">" | ">=" |
            "==" | "!=" |
            "and" |
            "or" .

pratt command

The pratt command is a stripped-down expression parser based on the Pratt parser. To help users understand Pratt parsing, the command also provides a naive, recursive, right-associative expression parser and a naive, iterative, left-associative expression parser.

Try it with:

go run ./cmd/pratt/main.go '1 + 2 * 3'

svg command

The svg command is meant to be used with the pratt command. It generates and opens an SVG image of the expression tree in the default SVG viewer.

Try it with:

go install ./cmd/...
pratt '1 * 2 + 3 * 4' | svg

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages