GithubHelp home page GithubHelp logo

steven-r / oberon0compiler Goto Github PK

View Code? Open in Web Editor NEW
5.0 2.0 0.0 905 KB

An implementation of N. Wirths Oberon 0 language implemented with C# and ANTLR. Currently compiler output is generated as MSIL code

License: MIT License

C# 98.47% ANTLR 1.53%
msil compiler oberon wirth antlr4 csharp

oberon0compiler's People

Contributors

steven-r avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

oberon0compiler's Issues

Upgrade ANTLR to 4.12

Eases build and use "official" runtime.

Also:

  • more .NET like structures
  • ignore CS3001 is no longer given for IToken reference

Create LLVM output

This allows interchange to C/C++ and other languages besides oberon0 itself.

Currently LLVM 15 is planned

Tasks:

  • Build generator
  • Build tests
  • Move Oberon0.System to MSIL
  • Implement Oberon0.System in LLVM

add command line interface

Required to allow #29

oberon0.exe source-file.ob0 [/output target.exe] [/asm:<path to ilasm.exe>] [/syslib:<pathtosystem.dll>]

Handle Type "STRING"

  • IO

    • WriteString
    • ReadString
  • conversions

    • TOSTRING(INTEGER/REAL)
    • TOSTRING(INTEGER/REAL. "format")
    • TOSTRING(BOOLEAN)
    • TOSTRING(BOOLEAN, "TRUEVAL", "FALSEVAL")
    • PARSESTR(STRING, VAR REAL/INTEGER)
    • PARSESTR(STRING, VAR BOOLEAN)
    • PARSESTR(STRING, VAR BOOLEAN, "TRUEVAL", "FALSEVAL")
  • Operations like "+", ...

    • "+" - concatenation
    • "*" - repeat string "x" times
  • Others

    • LENGTH(str) -> INTEGER
    • REPLACE(str, pattern) -> STRING
    • SUBSTRING(str, start, length) -> STRING

Assign INTEGER to REAL is not possible

The following is not possible:

VAR r: REAL;

BEGIN
  r := 1;
END;

complaining that left and right side types are not compatible.

There should be a generic mechanismn to allow compatible assignments, aka

Target Source valid
REAL INT ok
BOOL INT ok
INT REAL not ok

For types the base types need to have the same name.

For complex types the underlying types need to be the same.

For arrays the length and base type need to be the same.

Error in Create Issue Branch app configuration

Error in app configuration:

Exception while parsing configuration YAML: name of an alias node must contain at least one character at line 16, column 13:
    - label: *
              ^

Please check the syntax of your .issue-branch.yml

NRE if selector on unknown variable

Code:

MODULE Test; 
VAR
  x: ARRAY 5 OF INTEGER;

BEGIN 
    y[1] := 2
END Test.

Exception:

System.NullReferenceException : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei Oberon0.Compiler.Oberon0CompilerListener.ExitSelector(SelectorContext context)
   bei Oberon0.Compiler.OberonGrammarParser.SelectorContext.ExitRule(IParseTreeListener listener)
   bei Antlr4.Runtime.Parser.TriggerExitRuleEvent()
   bei Antlr4.Runtime.Parser.ExitRule()
   bei Oberon0.Compiler.OberonGrammarParser.module()
   bei Oberon0.Compiler.Oberon0Compiler.CompileString(String source, Oberon0CompilerOptions options)
   bei Oberon0.TestSupport.TestHelper.CompileString(String source, List`1 errors)
   bei Oberon0.TestSupport.TestHelper.CompileString(String source, String[] expectedErrors)
   bei Oberon0.Compiler.Tests.SimpleStatementTests.TestAssignFailVarNotFound()

compiler: Use double instead of decimal

  • rename decimal by double
  • add Epsilon const
  • add Infinity const
  • update tests to reflect changes
  • MSIL: adapt code generation
  • MSIL: Adapt tests
  • Conversions (INT <-> REAL, …)
  • Definitions
    Math functions (SQRT, ABS)

MSIL: Generation of anonymous records fails

The following code generates wrong MSIL:

VAR
  s: RECORD a : INTEGER END;

BEGIN
  ReadInt(s.a);
  s.a := s.a + 1;
  WriteInt(s.a);
  WriteLn
END ReadToRecord.

No type for the record is generated in MSIL

command line fails in all cases

Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Oberon0.Msil.Program.StartCompile(ParseResult result, FileSystemInfo input, Boolean verbose, IConsole console) in D:\Users\StephenReindl\Source\Repos\steven-r\Oberon0Compiler\Oberon0.Msil\Program.cs:line 55
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

D:\Users\StephenReindl\Source\Repos\steven-r\Oberon0Compiler\Oberon0.Msil\bin\Debug\netcoreapp3.1\Oberon0.Msil.exe (process 29484) exited with code 1.
To automatically close the console when debugging stops, enable Tools->Options->Debugging->Automatically close the console when debugging stops.
Press any key to close this window . . .

Array const index of last element fails (and gives NRE)

The following code failes (and should succeed):

VAR a: ARRAY 5 OF INTEGER;
BEGIN
    a[5] := 1;
END test.

In addition a NRE is thrown:

System.NullReferenceException : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei Oberon0.Compiler.Oberon0CompilerListener.ExitAssign_statement(Assign_statementContext context)
   bei Oberon0.Compiler.OberonGrammarParser.Assign_statementContext.ExitRule(IParseTreeListener listener)
   bei Antlr4.Runtime.Parser.TriggerExitRuleEvent()
   bei Antlr4.Runtime.Parser.ExitRule()
   bei Oberon0.Compiler.OberonGrammarParser.module()
   bei Oberon0.Compiler.Oberon0Compiler.CompileString(String source, Oberon0CompilerOptions options)
   bei Oberon0.TestSupport.TestHelper.CompileString(String source, List`1 errors)
   bei Oberon0.TestSupport.TestHelper.CompileString(String source, String[] expectedErrors)
   bei Oberon0.Compiler.Tests.Types.ArrayTests.ArrayFail1TestIndex5()

if (var) generates wrong code

if an if/while/repeat statement contains a simple variable reference (e.g. IF (x) THEN), wrong code is generated.

Nested complex type support

Having a RECORD containing an ARRAY or other complex scenarios are compiling but do not create correct code

NRE on assignment error

The following code throws an NRE:

BEGIN
    a[0] = 1;
END test.

Output:

System.NullReferenceException : Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei Oberon0.Compiler.Oberon0CompilerListener.ExitAssign_statement(Assign_statementContext context)
   bei Oberon0.Compiler.OberonGrammarParser.Assign_statementContext.ExitRule(IParseTreeListener listener)
   bei Antlr4.Runtime.Parser.TriggerExitRuleEvent()
   bei Antlr4.Runtime.Parser.ExitRule()
   bei Oberon0.Compiler.OberonGrammarParser.module()
   bei Oberon0.Compiler.Oberon0Compiler.CompileString(String source, Oberon0CompilerOptions options)
   bei Oberon0.TestSupport.TestHelper.CompileString(String source, List`1 errors)
   bei Oberon0.TestSupport.TestHelper.CompileString(String source, String[] expectedErrors)
   bei Oberon0.Compiler.Tests.Types.ArrayTests.ArrayFail1Test()

[9/9] - mismatched input '=' expecting ':='

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.