Giter Club home page Giter Club logo

daedaluscompiler's Introduction

Daedalus Compiler Build

This is repo with Daedalus ( Gothic I, II scripting language ) compiler. Project is using internally ANTL4 for parsing source code. The compiler itself is written in .NET Core C#.

You can listen about our compiler on below video. Video has bad audio quality, we encourage you to turn on subtitles, on the current moment we have subtitles for Polish, German and English language.

Download

Download latest version of the tool

Requirements

  • Installed .NET Core 2+ runtime

Standard Usage

  • Download & unpack latest release.
  • Use dotnet runtime to run the Compiler:
$ dotnet /path/to/DaedalusCompiler/DaedalusCompiler.dll
  • Make alias for easy usage. Recommended alias is gdc (gothic daedalus compiler).

For example in Linux and MacOS type:

$ alias gdc='dotnet /path/to/DaedalusCompiler/DaedalusCompiler.dll'

Example usage:

  • generate Gothic.dat file from Gothic.src file in output directory:
$ gdc /path/to/Gothic.src
  • generate result.dat file from Gothic.src file in custom directory, using custom runtime:
$ gdc /path/to/Gothic.src --runtime /path/to/runtime.d --output-dat /path/to/result.dat
  • generate ou.csl, ou.bin and Gothic.dat in output directory, ignore warnings W1 and W2:
$ gdc /path/to/Gothic.src --gen-ou --suppress W1:W2
  • generate Gothic.dat in Scripts/_compiled, ou.csl and ou.bin in Scripts/Content/Cutscene:
$ gdc /path/to/Gothic.src --output-dat "Scripts/_compiled/Gothic.dat" --gen-ou --output-ou "Scripts/Content/Cutscene"
  • generate Gothic.dat, enable unused symbol detection, provide zen paths to make that detection more accurate:
$ gdc /path/to/Gothic.src --zen-paths="/path/to/zens/*.zen" 

Usage with docker ( .NET Core runtime not needed )

Our compiler is available on docker hub, if you have installed docker you should be able to run compiler with:

docker run -v "$(pwd)":/usr/workspace dziejekhorinis/daedalus-compiler <path-to-gothic-src>

Path which is argument of docker run is relative to folder where we made mount.

Example usage:

docker run -v "$(pwd)":/usr/workspace dziejekhorinis/daedalus-compiler ./Gothic.src

Configure development environment

Project uses ANTLR4 and .NET Core C#.

For .NET Core C# it is recomended to use Visual Studio 2017.

For ANTLR4 you can use InteliJ or Visual Studio Code.

Configure VSCode for ANTLR

  1. Install Java (I think the best choice will be Java8 SDK).
  2. Install ANTLR4 VSCode extension.
  3. Optionally you can install Daedalus VSCode extension.

Now you can open folder /DaedalusCompiler/src/Parser in VSCode and start contributing Daedalus gramar.

ANTLR 4 VSCode extension helps you developing gramar by syntax coloring, code completion and debugging tools. For more details check out ANTLR 4 VSCode extension site.

daedaluscompiler's People

Contributors

arturkasperek avatar avallach7 avatar dziejekhorinis avatar gjuszczak avatar kisioj avatar tbroma avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

kisioj kirides

daedaluscompiler's Issues

Parse correctly assignments and expressions

We need parse expression like here:

x = 12 + 9 * ( 2 + otherFunc(1 + 7 * 3, 4 + 5) )

correctly ( we need remember about braces and operators importance ex ( '*' > '+' ) ), for that case we should generate assembler like here:

pushi    3
pushi    7
mul      
pushi    1
add      
pushi    5
pushi    4
add      
call     otherFunc
pushi    2
add      
pushi    9
mul      
pushi    12
add      

I added tests for that task. You should look for tests named CorrectlyPassBasicExpression and CorrectlyPassComplexExpression. After implementing that feature tests should pass without problems

Adding a native 'bool' type

As discussed on Discord we'd like to add support for a built-in type 'bool' which can only be inhabited by true/false.

Improvements:

  • We would like programmers to increase their compile-time expressiveness by asserting that a certain variable can only be inhabited by true or false.
  • Expressions using boolean operators such as ==, && or ! will produce a boolean value.

Problems:

  • The values 'true' and 'false' are already defined as constants in Daedalus (with the value 1 and 0 respectively). We can probably just ignore their definition.
  • Just like in C, statements of the form if (intVar) are used quite frequently. We need to accept passing integers into places where a boolean expression is expected, otherwise we break too much code.
  • Conversely, booleans will need to be implicitly converted to integers as well, to support code that is currently using integers as a replacement for booleans, e.g. if (intVar == true), where converting intVar to boolean would be incorrect.
  • If we want to enforce some stricter typechecking, we need an explicit way to convert a boolean into an integer. For now we can provide a built-in function to do so, which becomes a NOP during bytecode creation. For compatibility reasons a daedalus equivalent can be introduced when working with other compilers.

Open Questions:

  • Do we allow implicit conversion from int to bool when providing parameters for a function? I'd like not to, but this will make refactoring a whole lot more annoying, having to change foo(intVar) to foo(intVar != 0) everywhere. On the other hand, this will make refactoring a lot easier because the compiler will yell at places you have forgot to change/refactor.

Here are some examples, including my thoughts on what should happen internally/at the type level.
Examples:

  • if (intVar == True) True is promoted to an integer, using True = 1 and False = 0.
  • if (intVar) Because if-statements expect a boolean value, the integer has to be conceptually converted to a boolean with C-like semantics, i.e. 0 => False, everything else => True. We don't have to change anything, though, because that is what Gothic already does anyway.
  • intVar = True; This should maybe throw a warning or error only in strict mode and convert implicitly in non-strict/compatibility mode.
  • boolVar = 0; this should always throw an error, because the bool datatype is already opt-in, i.e. we have no legacy code to consider.

Please post any additional thoughts you have and I will try to keep the OP updated.

Tokens not recognized because of ControlCharacter

I first thank you for your work, I really appreciate the effort you put into this.
I use it in VSCode as built for my Gothic 2 Sources and it works great.
I encounterd a minor issue. ControlCharacters may lead to Token recognition errors.
I got into this when I freshly setup my PC. So the compiler should run without error against the "original" Gothic 2 sources. But I got an error. In DIA_VLK_439_Vatras.d line 566 unrecognized token. Well it turns out for whatever reason in the sources there is a FF (FormFeed) at position 1, after deleting the compiler ran without errors. I changed my VSCode settings to make CC visible. Anyway maybe you want to ignore these CCs.

Best regards

Add Special Character support for Identifiers (e.g. @^)

Ikarus (for example) introduces functions like _^, _@, _@s. Without adjustment, the compiler will fail to recognize them.

Daedalus.G4 fragment piece (newly added SpecialCharacters)

fragment IdStart : GermanCharacter | SpecialCharacters | [a-zA-Z_];
fragment IdContinue : IdStart | Digit;
fragment GermanCharacter : [\u00DF\u00E4\u00F6\u00FC];
fragment SpecialCharacters : [@^];

Optimize ( also give better naming ) lexer and parser

nameNode, referenceNode, assigmentOperator can be lexer elements ( maybe more elements can be lexer rules, need checking )

Now addOperator can be '-' or '+'. We should leave addOperator as a '+' and add new extra parser rule, subtractionOperator = '-'

Comment Availability

Is it possible for you to allow Comments to be rendered out into the Tree?
I have some problems with Array-Constants and with the AI_output function.

I need to do some workaround, to work with that currently.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.