Skip to content

Instantly share code, notes, and snippets.

View korzio's full-sized avatar

Alex Korzhikov korzio

View GitHub Profile

Microservices with GRPC/Go by Andrew

  • Overview

    • Use case - notify slack with time management
  • Project idea

    • Time management with no extra costs
    • On-premise project
  • Alternatives

// iota enumerator gives an effective way in go language
// to use constants in enum-like constructs
const (
none = iota
plus
mul
)
// enum-like map of operator token keys and iota values defined above
var precendences = map[string]int{
token.PLUS: plus,
func led(left ast.Node, operator token.Token, right ast.Node) *ast.Node {
return &ast.Node{Left: &left, Token: &operator, Right: &right}
}
@korzio
korzio / node.go
Last active March 17, 2021 20:34
type Node struct {
Token *token.Token
Left *Node
Right *Node
}
// string representation
// 1 * 2 + 3 -> {+,{*,{1},{2}},{3}}
func (n *Node) ToString() string {
res := "{" + n.Token.Literal
if n.Left != nil {
@korzio
korzio / tree.go
Last active March 17, 2021 20:38
tree := p.lexer.Tokens().
Scan(func(_ context.Context, acc interface{}, elem interface{}) (interface{}, error) {
it, isIterator := acc.(iterator)
next := elem.(token.Token)
if !isIterator || it.left == nil {
// null denotation
return nud(acc, next), nil
}
if it.operator != nil {
var prevIt *iterator
@korzio
korzio / nud.go
Last active March 17, 2021 20:40
func nud(acc interface{}, next token.Token) iterator {
// Node{Token: token.Token{Type: token.PLUS, Literal: "+"}, Left: &Node{Token: token.Token{Type: token.INT, Literal: "2"}}}
node := ast.Node{Token: &next}
it := iterator{nud: &node}
accIt, isIt := acc.(iterator)
if isIt {
// { , {... }
node.Left = accIt.nud
// save current stack
it.stack = accIt.stack
@korzio
korzio / main.go
Last active February 6, 2021 18:12
package main
import (
"fmt"
"os"
"os/user"
"pizzascript/repl"
)
func main() {
@korzio
korzio / repl.go
Last active February 6, 2021 18:12
package repl
import (
"bufio"
"fmt"
"io"
"pizzascript/eval"
"pizzascript/lexer"
"pizzascript/parser"
)
@korzio
korzio / token.go
Last active February 6, 2021 18:11
package token
type TokenType string
type Token struct {
Type TokenType
Literal string
}
const (
// Literals
@korzio
korzio / lexer.go
Last active February 6, 2021 18:09
package lexer
import (
"fmt"
"strings"
"pizzascript/token"
"github.com/reactivex/rxgo/v2"
)
type Lexer struct {
input string