Нема описа

runningwater edb5e7a9b7 Parsing variables -- Variable Scope пре 2 година
.idea 5ac782a190 execution пре 2 година
doc 73ff604276 first interpreter framework пре 2 година
src edb5e7a9b7 Parsing variables -- Variable Scope пре 2 година
.gitignore 3d2508ae84 first commit пре 2 година
README.md edb5e7a9b7 Parsing variables -- Variable Scope пре 2 година
pom.xml 3d2508ae84 first commit пре 2 година

README.md

Lox

 // Your first Lox program!
 print "Hello, world!";
  • Dynamic typing
  • Automatic memory management
  • Data Types
    • Booleans
    • Numbers
    • Strings
    • Nil
  • Expressions
    • Arithmetic
    • Comparison and equality
    • Logical operators
    • Precedence and grouping
  • Statements
  • Variables
  • Control Flow
  • Functions
  • Closures
  • Classes

A Grammar for Lox expressions

  • Literals. Numbers,strings,Booleans, and nil
  • Unary expressions. A prefix ! to perform a logical not, and - to negate a number.
  • Binary expressions. The infix arithmetic(+,-,*,/) and logic operators (==, !=, <, <=,>,>=)

    • Parentheses. A pair of ( and ) wrapped around and expression.

      • Syntax tree - Expression

          expression     → literal
          | unary
          | binary
          | grouping ;
        
          literal        → NUMBER | STRING | "true" | "false" | "nil" ;
          grouping       → "(" expression ")" ;
          unary          → ( "-" | "!" ) expression ;
          binary         → expression operator expression ;
          operator       → "==" | "!=" | "<" | "<=" | ">" | ">="
          | "+"  | "-"  | "*" | "/" ;
        
        

      | Name | Operators | Associates |

              |------------|-----------|------------|
      

      | Equality | == != | Left | | Comparison | > >= < <= | Left | | Term | - + | Left | | Factor | / * | Left | | Unary | ! - | Right |

      ```
      expression     → equality ;
      equality       → comparison ( ( "!=" | "==" ) comparison )* ;
      comparison     → term ( ( ">" | ">=" | "<" | "<=" ) term )* ;
      term           → factor ( ( "-" | "+" ) factor )* ;
      factor         → unary ( ( "/" | "*" ) unary )* ;
      unary          → ( "!" | "-" ) unary
                     | primary ;
      primary        → NUMBER | STRING | "true" | "false" | "nil"
                     | "(" expression ")" | IDENTIFIER ;
      
      
        - Syntax tree - Statement
      
            ```
            program        → statement* EOF ;
            
            statement      → exprStmt
                           | printStmt 
                           | block;
                  
            block         → "{" declaration* "}"
            
            exprStmt       → expression ";" ;
            printStmt      → "print" expression ";" ;
            ```
      
          A program is a list of statements followed by the special "end of file" token.
          The mandatory end token ensures the parse consumes the entire input and don't
          silently ignore erroneous unconsumed tokens at the end of a script.
      - Syntax tree - add Variable syntax
      
      program   → declaration* EOF ;
      
      declaration  → varDecl
                   | statement ;
      
       statement      → exprStmt
                       | printStmt 
                       | block;
      
       block         → "{" declaration* "}"
      
      varDecl  → "var" IDENTIFIER ( "=" expression )? ";" ;
      

      ```