thelink2012 / cminus

A simple compiler for a simple language
MIT License
1 stars 1 forks source link

Syntax Analysis #1

Closed thelink2012 closed 6 years ago

thelink2012 commented 6 years ago

This is a tracking issue for the progress of syntax analysis.

A small guide for adding a syntactic feature is as follow:

  1. Add a parser for the desired production(s) at parser.cpp.
  2. When necessary, create its AST node(s) at ast.hpp.
  3. ...creation of nodes shall happen in semantics.cpp.
  4. ...implement AST dump functionality at ast-dump.cpp.
  5. Test it. Add those tests to test/sintatico/. Think about corner cases as well as successful ones.

Do not consider semantic analysis yet, let's focus on syntax.

To run the analyses manually, taking a source file as input and giving an AST dump as output, run ./sintatico <input> <output>.

Syntax Analysis Progress

Productions which are related to each other are grouped together.

Basic Program Structure

Variable Declaration

Function Declaration

Selection Statement

Iteration Statement

Return Statement

Expression Statement

Expressions

Variable

Function Call

thelink2012 commented 6 years ago

Tests for syntax are not declaring variables.

This will cause problems when we introduce semantic validation.

To fix this we'll need to (at some point) print random trash to stdout whenever a undeclared variable is used. This way we can track those "wrong" tests and fix them.

thelink2012 commented 6 years ago

When this is done look at the bottom of parser.cpp to verify (and test) if the grammar challenges were accomplished.

tysm commented 6 years ago

With the last commit only the tests remain ^~^.

thelink2012 commented 6 years ago

~Will not include tests for complete programs in sintatico, will leave that for semantico tests.~