Git Product home page Git Product logo

glua's Introduction

Glua

A toy programming language based on Lua and built with Go.

Building and running programs

To lint the project I use:

golangci-lint run

And to run the code I use

go run . <filename>

Missing Features List

  • Weak tables
  • next builtin function

Grammar

This is really out of date but I don't want to bother fixing it right now.

I based this grammar on the Lox Grammar1

Program := Declaration +

# I can't remember semicolon rules in Lua but for now I'm going to
# use them to deliniate the end of an expression
Declaration := GlobalDeclaration
    | LocalDeclaration
    | FunctionDeclaration
    | Statement ( ';' )?

Statement := AssertStatement
    | WhileStatement
    | Expression

AssertStatement := 'assert' Expression

Expression := Assignment

Assignment := ( Call '.' )? Identifier ( '=' Assignment )
    | LogicOr

# Logic and is higher precedence than or; or is the lowest
# precedence operator
#
# x or y and z will evaluate as x or (y and z)
LogicOr := LogicAnd ( 'or' LogicAnd ) *

LogicAnd := Comparison ( 'and' Comparison ) *

# Skip concatenation operator for now
Comparison := Term ( ('<' | '>' | '<=' | '>=' | '~=' | '==' ) Term ) *

Term := Factor ( ('+' | '-') Factor ) *

Factor := Unary ( ('*' | '/') Unary ) *

# The way I'd represent is...
# Unary := ('-' | '!') * Exponent
# but that would require an explicit stack to implement as written.
#
# Instead use a recursive definition
Unary := ('-' | '!') Unary | Exponent

Exponent := Call ( '^' Call )

# Name is call because this is where the precedence for function
# calls will go, highest precedence except for literals and
# identifiers
Call := Primary ( '.' Identifier ) *

Primary := Number | String | Identifier | 'nil' | Table

Number := [0-9] +

String := '"' StringChar * '"'

# Note: you can backslash escape quotes, more may be added
# Lua uses backslashes, but I haven't bothered to look up all
# the escaped characters
StringChar := ! ( '\' | '"') | '\"'

Identifier := [a-zA-Z] [a-zA-Z0-9_-] *

Table := '{' Pair * '}'

Pair := StringPair | LiteralPair | Value

StringPair := Identifier '=' Value

LiteralPair := LiteralKey '=' Value

Value := Expression

LiteralKey := '[' Expression ']'

glua's People

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.