Skip to content

Commit

Permalink
Several improvements
Browse files Browse the repository at this point in the history
- `python.tlt` PEP-8 issues
- Code style of JavaScript and JSON improved
- Test suite extensions for JSON (using `jq`)
- Updated Makefile
- Fancy new "logo" ;-)
  • Loading branch information
phorward committed Oct 28, 2023
1 parent c2e46f1 commit e5282a6
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 251 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/c-cpp.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: C/C++ CI
name: Test

on:
push:
Expand All @@ -8,11 +8,11 @@ on:

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: "additional dependencies"
run: sudo apt update && sudo apt install -y jq
- name: make
run: make -f Makefile.gnu
- name: make test
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
*.o
min_lalr1/min_lalr1

src/parse_boot1.c
src/parse_boot2.c
Expand Down
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ This file is used to document any relevant changes done to UniCC.

## [v1.8]

Current main branch.
Released on Oct 28, 2023

- Improved program module generator to support <true>- and <false>-settings
- Target `python` updated to spaces instead of tabs and further improvements
- Target `javascript` updated to more recent JS/ECMAScript6 features
- Updated Test suite
- Target `python` updated to spaces instead of tabs and further PEP-8 improvements
- Target `javascript` updated to more recent JS/ECMAScript6 standards
- Target `json` fixed and updated

## [v1.7]

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2006-2020 by Phorward Software Technologies, Jan Max Meyer.
Copyright © 2006-2023 by Jan Max Meyer, Phorward Software Technologies.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
12 changes: 11 additions & 1 deletion Makefile.gnu
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,17 @@ test_js: $(TESTPREFIX)js_expr $(TESTPREFIX)js_ast
@echo "--- $@ succeded ---"
@rm $(TESTPREFIX)*

# JSON

$(TESTPREFIX)json_ast:
./unicc -wtl json examples/expr.ast.par >$@.json
jq . $@.json

test_json: $(TESTPREFIX)js_expr $(TESTPREFIX)json_ast
@echo "--- $@ succeded ---"
@rm $(TESTPREFIX)*

# Test

test: test_c test_cpp test_py test_js
test: test_c test_cpp test_py test_js test_json
@echo "=== $+ succeeded ==="
54 changes: 37 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
# UniCC [![C/C++ CI](https://github.com/phorward/unicc/actions/workflows/c-cpp.yml/badge.svg)](https://github.com/phorward/unicc/actions/workflows/c-cpp.yml) [![MIT License badge](https://img.shields.io/badge/License-MIT-green.svg)](https://opensource.org/licenses/MIT)

**unicc** is a universal LALR(1) parser generator with built-in scanner generator, targetting C, C++, Python, JavaScript, JSON and XML.
<div align="center">
<img src="https://github.com/phorward/unicc/raw/main/unicc.svg" height="196" alt="UniCC Logo" title="UniCC logo">
<h1>UniCC</h1>
<a href="https://github.com/phorward/unicc/actions/workflows/test.yml">
<img src="https://github.com/phorward/unicc/actions/workflows/text.yml/badge.svg" alt="Badge displaying the test status" title="Test badge">
</a>
<a href="https://github.com/phorward/unicc/LICENSE">
<img src="https://img.shields.io/badge/License-MIT-green.svg" alt="Badge displaying the license" title="License badge">
</a>
<br>
The universal LALR(1) parser generator with built-in scanner generator, creating parsers in different target programming languages.
</div>

## About

**unicc** compiles an augmented grammar definition into a program source code that parses the described grammar. Because UniCC is intended to be target-language independent, it can be configured via template definition files to emit parsers in almost any programming language.
**unicc** is a parser generator that compiles an extended grammar definition into program source code that parses the described grammar. Since UniCC is target language independent, it can be configured via template definition files to generate parsers in any programming language.

UniCC comes with out of the box support for the programming languages **C**, **C++**, **Python** and **JavaScript**. Parsers can also be generated into **JSON** and **XML**.
UniCC natively supports the programming languages **C**, **C++**, **Python** and **JavaScript**. Parse tables can also be generated in **JSON** and **XML**.

UniCC can generate both scanner-less and scanner-mode parsers. The more powerful scanner-less parsing is the default, and allows to break the barrier between the grammar and its tokens, so tokens are under full control of the context-free grammar. Scanner-less parsing requires that the provided grammar is internally rewritten according to whitespace and lexeme settings.
UniCC can generate both scannerless parsers and parsers with a separate scanner. The more powerful scannerless parsing is the default and allows the barrier between the grammar and its tokens to be broken, leaving the tokens under the full control of the context-free grammar. Scannerless parsing requires that the provided grammar is rewritten internally according to the whitespace and lexeme settings.

## Examples

Below is the full definition of a simple, universal grammar example that can be compiled to any of UniCC's target languages.

This example uses the automatic abstract syntax tree construction syntax to define nodes and leafs of the resulting syntax tree.

```unicc
Expand Down Expand Up @@ -82,41 +92,51 @@ $ cc -o expr expr.c

This [C](examples/expr.c.par)-example can also be found for [C++](examples/expr.cpp.par), [Python](examples/expr.py.par) and [JavaScript](examples/expr.js.par).

More real-world examples for parsers implemented with UniCC can be found in [xpl](https://github.com/phorward/xpl), [rapidbatch](https://github.com/phorward/rapidbatch) and [ViUR logics](https://github.com/viur-framework/logics).
More real-world examples for parsers implemented with UniCC can be found in [XPL](https://github.com/phorward/xpl), [RapidBATCH](https://github.com/phorward/rapidbatch) and [Logics](https://github.com/viur-framework/logics).

## Features

UniCC provides the following features and tools:

- Grammars are expressed in a powerful Backus-Naur-style meta language
- Generates parsers in C, C++, Python, JavaScript, JSON and XML
- Scanner-less and scanner-mode parser construction supported
- Build-in full Unicode processing
- Grammar prototyping features, virtual productions and anonymous nonterminals
- Generates standalone (dependency-less) parsers in
- C
- C++
- Python 2 (deprecated)
- Python 3
- JavaScript (ES2018)
- Provides facilities to generate parse tables as
- JSON
- XML (deprecated)
- Scannerless parser supported by default
- Full Unicode processing built-in
- Grammar prototyping features
- automatic grammar revision for scannerless parsers
- virtual productions
- anonymous nonterminals
- Abstract syntax tree notation features
- Semantically determined symbols
- Standard LALR(1) conflict resolution
- Platform-independent (console-based)

## Documentation

The [UniCC User's Manual](http://downloads.phorward-software.com/unicc/unicc.pdf) is the official standard documentation of the UniCC Parser Generator.

## Installation

On Linux and OS X, UniCC can be build and installed like any GNU-style program, with
UniCC can be build and installed like any GNU-style program, with

```sh
./configure
make
make install
```

In the past, setup packages for Windows systems where also provided, but these are not maintained anymore since unicc v1.6. You can still find them [here](https://downloads.phorward-software.com/unicc/).

## UniCC v2
Alternatively, the dev-toolchain can be used, by just calling on any recent Linux system.

Between 2014 and 2020, a version 2 of UniCC was under development, but abandoned for now. This version currently exists in the [branch unicc2](https://github.com/phorward/unicc/tree/unicc2) inside of this repository, and is a complete rewrite, but with the intention to provide better tools for grammar prototyping and direct AST traversal.
```sh
make -f Makefile.gnu
```

## License

Expand Down
70 changes: 41 additions & 29 deletions targets/javascript.tlt
Original file line number Diff line number Diff line change
Expand Up @@ -82,24 +82,24 @@
-->
<defprod>
<col>@@production-number</col>
<col_sep>, </col_sep>
<col> @@production-number</col>
<col_sep>,&#x0A;</col_sep>
</defprod>
<acttab>
<row_start> { </row_start>
<row_end> }</row_end>
<row_start> {</row_start>
<row_end>&#x0A; }</row_end>
<row_sep>,&#x0A;</row_sep>
<col>@@symbol: [ @@action,@@index ]</col>
<col_sep>, </col_sep>
<col>&#x0A; @@symbol: [@@action, @@index]</col>
<col_sep>,</col_sep>
</acttab>
<gotab>
<row_start> { </row_start>
<row_end> }</row_end>
<row_start> {</row_start>
<row_end>&#x0A; }</row_end>
<row_sep>,&#x0A;</row_sep>
<col>@@symbol: [ @@action,@@index ]</col>
<col_sep>, </col_sep>
<col>&#x0A; @@symbol: [@@action, @@index]</col>
<col_sep>,</col_sep>
</gotab>
<!--
Expand All @@ -109,34 +109,34 @@
-->
<dfa_select>
<col>@@machine</col>
<col_sep>, </col_sep>
<col> @@machine</col>
<col_sep>,&#x0A;</col_sep>
</dfa_select>
<dfa_char>
<col>@@from, @@to</col>
<col_sep>, </col_sep>
<col> @@from, @@to</col>
<col_sep>,&#x0A;</col_sep>
</dfa_char>
<dfa_trans>
<col>@@goto</col>
<col_sep>, </col_sep>
<col> @@goto</col>
<col_sep>,&#x0A;</col_sep>
</dfa_trans>
<dfa_idx>
<row_start> [ </row_start>
<row_end> ]</row_end>
<row_start> [</row_start>
<row_end>&#x0A; ]</row_end>
<row_sep>,&#x0A;</row_sep>
<col>@@index</col>
<col_sep>, </col_sep>
<col>&#x0A; @@index</col>
<col_sep>,</col_sep>
</dfa_idx>
<dfa_accept>
<row_start> [ </row_start>
<row_end> ]</row_end>
<row_start> [</row_start>
<row_end>&#x0A; ]</row_end>
<row_sep>,&#x0A;</row_sep>
<col>@@accept</col>
<col_sep>, </col_sep>
<col>&#x0A; @@accept</col>
<col_sep>,</col_sep>
</dfa_accept>
<!--
Expand All @@ -146,12 +146,24 @@
-->
<symbols>
<col> { "symbol": "@@symbol-name", "emit": "@@emit", "is-terminal": @@type, "is-lexem": @@lexem, "is-whitespace": @@whitespace, "is-greedy": @@greedy }</col>
<col> {
"symbol": "@@symbol-name",
"emit": "@@emit",
"is-terminal": @@type,
"is-lexem": @@lexem,
"is-whitespace": @@whitespace,
"is-greedy": @@greedy
}</col>
<col_sep>,&#x0A;</col_sep>
</symbols>

<productions>
<col> { "production": "@@production", "emit": "@@emit", "length": @@length, "left-hand-side": @@lhs }</col>
<col> {
"production": "@@production",
"emit": "@@emit",
"length": @@length,
"left-hand-side": @@lhs
}</col>
<col_sep>,&#x0A;</col_sep>
</productions>
Expand All @@ -161,7 +173,7 @@
****************************************************************************
-->
<file filename="@@basename.js">// Parser module generated by unicc from @@filename.
<file filename="@@basename.js">// This parser module was generated by unicc from @@filename.
// DO NOT EDIT THIS FILE MANUALLY, IT WILL GO AWAY!
@@prologue
Expand Down Expand Up @@ -289,7 +301,7 @@ export default class @@prefixParser {

static #lexer = {
"select": [
@@dfa-select
@@dfa-select
],
"index": [
@@dfa-index
Expand All @@ -312,7 +324,7 @@ export default class @@prefixParser {
@@goto-table
],
"default-production": [
@@default-productions
@@default-productions
]
};

Expand Down
Loading

0 comments on commit e5282a6

Please sign in to comment.