Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

License

NotificationsYou must be signed in to change notification settings

lazy-fortran/standard

Repository files navigation

A comprehensive, modular ANTLR4-based implementation of FORTRAN/Fortran language standards from 1957 to LazyFortran2025.

Project Overview

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

Grammar Inheritance Chain

FORTRAN (1957) → FORTRAN II (1958) → FORTRAN 66 (1966) → FORTRAN 77 (1977)                                                                      ↓                                                                 Fortran 90 (1990)                                                                      ↓                                          Fortran 95 → 2003 → 2008 → 2018 → 2023

This 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.

Directory Structure

standard/├── grammars/           # Grammar source files (.g4)├── tests/              # Test suites grouped by standard├── scripts/            # Helper / validation scripts├── tools/              # Extra utilities└── validation/         # External grammar validation tools

Quick Start

Prerequisites

  • Python 3.8+
  • ANTLR4 (Java version)
  • Git

Installation

# 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

Building Grammars

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

Running Tests

# Run all testspython -m pytest tests/ -v

Implementation Status

This 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):

StandardImplemented 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)YesYes (tests/FORTRANII)Adds user‑written subroutines and functions (SUBROUTINE,FUNCTION,CALL,RETURN) andCOMMON blocks, matching the historical FORTRAN II enhancements.
FORTRAN 66 (1966)YesYes (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)YesYes (tests/FORTRAN77)Adds the CHARACTER type, blockIF ... THEN ... ELSE ... ENDIF, PARAMETER, SAVE and other features; coverage is representative but not exhaustive.
Fortran 90 (1990)YesExtensive (tests/Fortran90)Modern foundation: free‑form source, modules, derived types, array operations, dynamic arrays, enhanced control constructs (SELECT CASE,WHERE), etc.
Fortran 95 (1995)YesNo dedicated suite yetGrammar extends F90 with FORALL, enhancements to WHERE and additional intrinsics; tests are still to be written.
Fortran 2003 (2003)YesExtensive (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)YesPresent (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)YesPresent (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)YesPresent (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.

Key Features

FORTRAN (1957)

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 (1958)

FORTRAN II added user‑written subprograms and shared storage:

  • SUBROUTINE /FUNCTION /CALL /RETURN statements for separately compiled procedures
  • COMMON blocks for sharing storage between program units
  • Hollerith constants (nHtext) for representing character data

Development

Test-Driven Development

All features implemented using TDD:

  1. RED - Write failing test
  2. GREEN - Implement to pass
  3. REFACTOR - Clean up

Contributing

SeeCONTRIBUTING.md for guidelines.

Architecture Principles

  1. Each grammar only defines NEW features
  2. Import from predecessor in chain
  3. No duplication of rules or tokens
  4. Historical accuracy maintained
  5. Clean separation of concerns

Comprehensive Validation

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

License

MIT License

Acknowledgments

  • Original FORTRAN team at IBM (John Backus et al.)
  • ANTLR4 project for grammar tooling
  • Historical FORTRAN documentation from IBM archives

Related Projects

Contact


Building the future of Fortran through understanding its past.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors2

  •  
  •  

[8]ページ先頭

©2009-2025 Movatter.jp