- Notifications
You must be signed in to change notification settings - Fork0
License
lazy-fortran/standard
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
A comprehensive, modular ANTLR4-based implementation of FORTRAN/Fortran language standards from 1957 to LazyFortran2025.
This repository implements an ANTLR4 grammar hierarchy for many FORTRAN/Fortran standards, designed with:
- Modular inheritance - Each standard builds upon its predecessor
- Reuse - Later grammars import and extend earlier ones
- Historical orientation - Grammars are organized by language standard
- Clean architecture - Source/build separation, proper dependencies
FORTRAN (1957) → FORTRAN II (1958) → FORTRAN 66 (1966) → FORTRAN 77 (1977) ↓ Fortran 90 (1990) ↓ Fortran 95 → 2003 → 2008 → 2018 → 2023This repository currently implements grammars for:
- FORTRAN (1957, IBM 704)
- FORTRAN II (1958)
- FORTRAN 66 (ANSI X3.9‑1966)
- FORTRAN 77 (1977)
- Fortran 90, 95, 2003, 2008, 2018 and 2023
FORTRAN IV (1962) is not implemented as a separate grammar; its functionality is represented in the FORTRAN 66 grammar, reflecting the fact that FORTRAN 66 largely standardized the then‑current FORTRAN IV practice.
standard/├── grammars/ # Grammar source files (.g4)├── tests/ # Test suites grouped by standard├── scripts/ # Helper / validation scripts├── tools/ # Extra utilities└── validation/ # External grammar validation tools- Python 3.8+
- ANTLR4 (Java version)
- Git
# Clone the repositorygit clone https://github.com/lazy-fortran/standard.gitcd standard# Install ANTLR4 (Arch Linux)sudo pacman -S antlr4# Install Python dependenciespip install antlr4-python3-runtime pytest
The project includes a comprehensive Makefile for building all grammars:
# Build all grammars in dependency ordermake all# Build specific standardmake Fortran2003# Clean generated filesmake clean# Show available targets and helpmakehelp# Run tests after buildingmaketest
# Run all testspython -m pytest tests/ -vThis project provides grammars and tests for many Fortran standards, but it doesnot implement every feature from each ISO standard and doesnot contain a separate FORTRAN IV grammar. The table below describes the state of the implementation in this repository (not the full language specifications):
| Standard | Implemented here? | Tests present? | Notes |
|---|---|---|---|
| FORTRAN (1957, IBM 704) | Yes (historical core subset) | Yes (tests/FORTRAN) | Fixed‑form syntax; arithmetic IF; DO loops; GOTO; I/O. Grammar is an explicitly documented historical stub rather than a full reconstruction of the original compiler. |
| FORTRAN II (1958) | Yes | Yes (tests/FORTRANII) | Adds user‑written subroutines and functions (SUBROUTINE,FUNCTION,CALL,RETURN) andCOMMON blocks, matching the historical FORTRAN II enhancements. |
| FORTRAN 66 (1966) | Yes | Yes (tests/FORTRAN66) | Represents the first ANSI Fortran standard, incorporating the FORTRAN IV features such as LOGICAL, DOUBLE PRECISION and COMPLEX into a machine‑independent standard. |
| FORTRAN 77 (1977) | Yes | Yes (tests/FORTRAN77) | Adds the CHARACTER type, blockIF ... THEN ... ELSE ... ENDIF, PARAMETER, SAVE and other features; coverage is representative but not exhaustive. |
| Fortran 90 (1990) | Yes | Extensive (tests/Fortran90) | Modern foundation: free‑form source, modules, derived types, array operations, dynamic arrays, enhanced control constructs (SELECT CASE,WHERE), etc. |
| Fortran 95 (1995) | Yes | No dedicated suite yet | Grammar extends F90 with FORALL, enhancements to WHERE and additional intrinsics; tests are still to be written. |
| Fortran 2003 (2003) | Yes | Extensive (tests/Fortran2003) | Adds object‑oriented features, C interoperability, procedure pointers, IEEE arithmetic support, etc. Remaining gaps are tracked indocs/fortran_2003_audit.md and spec‑grounded issues such as #90. |
| Fortran 2008 (2008) | Yes | Present (tests/Fortran2008) | Introduces coarrays, submodules,DO CONCURRENT, new intrinsics and kinds. Remaining gaps are tracked in spec‑grounded Fortran 2008 issues such as #83. |
| Fortran 2018 (2018) | Yes | Present (tests/Fortran2018) | Extends coarray parallelism with teams, events and related features. Remaining gaps are tracked in spec‑grounded Fortran 2018 issues such as #88. |
| Fortran 2023 (2023) | Yes | Present (tests/Fortran2023) | Adds features such as improved enumerations, conditional expressions and further intrinsic enhancements. Current support is intentionally minimal and evolving. |
At the moment the test suite consists of roughly 270 tests across these standards, and all of them pass after generating the grammars with ANTLR.
Historically, the original IBM 704 FORTRAN provided fixed‑form source code, arithmetic expressions, DO loops, conditional branching with arithmetic IF, computed GOTOs, FORMAT‑driven I/O and related features. In this repository the FORTRAN grammar focuses on that core statement set and serves as the base of the inheritance chain.
FORTRAN II added user‑written subprograms and shared storage:
SUBROUTINE/FUNCTION/CALL/RETURNstatements for separately compiled proceduresCOMMONblocks for sharing storage between program units- Hollerith constants (
nHtext) for representing character data
All features implemented using TDD:
- RED - Write failing test
- GREEN - Implement to pass
- REFACTOR - Clean up
SeeCONTRIBUTING.md for guidelines.
- Each grammar only defines NEW features
- Import from predecessor in chain
- No duplication of rules or tokens
- Historical accuracy maintained
- Clean separation of concerns
The project includes a growing test suite:
- On the order of 270 unit tests across the implemented standards (all currently passing)
- Historical code examples from different eras
- Operator‑precedence validation in the older dialects
- Parse‑tree checks for selected modern constructs
- Cross‑standard compatibility testing where inheritance is involved
- Original FORTRAN team at IBM (John Backus et al.)
- ANTLR4 project for grammar tooling
- Historical FORTRAN documentation from IBM archives
- GitHub Issues:Report bugs or request features
- Project Lead: @krystophny
Building the future of Fortran through understanding its past.
About
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Contributors2
Uh oh!
There was an error while loading.Please reload this page.