Giter Site home page Giter Site logo

clanguage's People

Contributors

klotzi111 avatar praeclarum 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  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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

clanguage's Issues

Simple test

Hello @praeclarum! I'm trying to use your CLanguage. I'm a bit lost.

This is what I have so far:

public class UnitTest1
{
    [Fact]
    public void Test1()
    {
        var sut = new CCompiler(new CompilerOptions(new MachineInfo()));
        sut.AddDocument(new Document("file.c", "int main { return 123; }"));
        var ex = sut.Compile();
    }
}

How do I get the 123 that results after the execution of the program?

Editor clear background

Want this for my app!

Should be able to just say:

CEditor ed;
ed.BackgroundColor = UIColor.Clear;

Member Instance Not Working (Callback Functions)

// Wire Slave Receiver
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Receives data as an I2C/TWI slave device
// Refer to the "Wire Master Writer" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup()
{
  Serial.begin(9600);
  Wire.begin(4);                // join i2c bus with address #4
  Wire.onReceive(receiveEvent); // register event (Here is the problem)
  Serial.begin(9600);           // start serial for output
}

void loop()
{
  Serial.println("Waiting");
  delay(3000);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  while(1 < Wire.available()) // loop through all but the last
  {
    char c = Wire.read(); // receive byte as a character
    Serial.print(c);         // print the character
  }
  int x = Wire.read();    // receive byte as an integer
  Serial.println(x);         // print the integer
}
 

Left Shift Overflows

This issue is related to a bad conversion, when you try to do a left shit of 16-bit, this will lead to an overflow, and the result will be zero, this means that the number is considered an integer, CLanguage should be able to convert this shift to a long value and don't return a zero, this happens in Arduino

byte  pressure_data_high = readRegister(0x1F, 1);
 pressure_data_high &= 0b00000111; //you only needs bits 2 to 0

 //Read the pressure data lower 16 bits:
 unsigned int pressure_data_low = readRegister(0x20, 2);
 //combine the two parts into one 19-bit number:
 long pressure = ((pressure_data_high << 16) | pressure_data_low) / 4;

Method definitions

When declaring a struct or class, it seems to only be possible to declare functions such as void Test::TestFunc(){ } using the addinternalfunction method. It does not seem to work in code?

Local vs Global Colors

Right now I only have yellow for global colors. Would be nice to have resolved variable colors too.

Fails to parse code

// Adapted from:
// Code Example for jolliFactory's Bi-color 16X16 LED Matrix Conway's Game of Life example 1.0
// and Adafruit NeoPixel Example 'simple'

#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
  #include <avr/power.h>
#endif


#define Width 8
#define Height 4

// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1
#define PIN            6

// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS      (Width * Height)

#define DELAY           250 
#define MAXGENERATIONS  100   
#define MAXBLANK 10           
#define MAXSTATIC 10        

#define ADJBRIGHT             
#define ADJCOLOR         

Adafruit_NeoPixel pixel (NUMPIXELS, PIN, 89);

void hsv2rgb(unsigned int hue, unsigned int sat, unsigned int val, unsigned char * r, unsigned char * g, unsigned char * b, unsigned char maxBrightness );

int idx=0;
int noOfGeneration = 0;
int iCount = 0;
unsigned int hue;
int allOffCount = 0;  // tracking how many cycles all pixels are off
int sameCount = 0;   // tracking how many cycles all pixels the same as the prior cycle
byte sameBuffer[NUMPIXELS];  

byte t1[16][16];                      
byte t2[16][16];
byte last[16][16];



//**********************************************************************************************************************************************************
void setup() {
  // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
#if defined (__AVR_ATtiny85__)
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
#endif
  // End of trinket special code

  pixels.begin(); // This initializes the NeoPixel library.
  
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
  
  randomize(t1); 
}



//**********************************************************************************************************************************************************
void loop()
{

  static bool onoff = false;
  
  if (idx++ > 100 || allOffCount > 10 || sameCount > 10)   //limit no. of generations for display
  {
    allOffCount = 0;
    sameCount = 0;
    hue = random(360);
    randomize(t1);   
    noOfGeneration = 0;     
    idx=0;
  }

  onoff = !onoff;
  digitalWrite(13, onoff?HIGH:LOW);
  compute_previous_generation(t1,t2);
  compute_neighbouring_cells(t1,t2);
  compute_next_generation(t1,t2);
  display(t1);
  delay(DELAY);
}



//**********************************************************************************************************************************************************
void clear_window()
{
  pixels.clear();
  pixels.show();
}



//**********************************************************************************************************************************************************
void display(byte t1[16][16])
{
  byte i,j;

  int offCount = 0;
  byte newBuffer[NUMPIXELS];
  uint32_t c;  
  for(i=0; i<(Width); i++)
  {
    for(j=0; j<Height; j++)
    {  
      byte nCount = countNeighbors(t1,i,j);
      if (t1[i][j])
      {
        newBuffer[j*Width+i] = 1;
        byte r, g, b;
        unsigned int bright = 150;
        unsigned int xhue = hue;
#ifdef ADJBRIGHT
        bright = 10 + 1 << nCount; // 2^nCount makes the scaling logrithmic, so the eye can see the differences
        if (bright > 255) bright = 255; 
#endif
#ifdef ADJCOLOR
        xhue += nCount * 40; // 40 degrees of color rotation per neighbor
        if (xhue >= 360) xhue -= 360;
#endif
        hsv2rgb(xhue,255,255,&r,&g,&b,bright);
        c = pixels.Color(r,g,b);
      }
      else
      {
        c = pixels.Color(0,0,0);
        newBuffer[j*Width+i] = 0;
        offCount++;
      }
      pixels.setPixelColor(j*Width+i,c);
    }     
  }
  pixels.show();
  if (offCount == NUMPIXELS) allOffCount++;
  if (memcmp(newBuffer,sameBuffer,NUMPIXELS) == 0) sameCount++;
  memcpy(sameBuffer,newBuffer,NUMPIXELS);
  
}

//**********************************************************************************************************************************************************
void compute_previous_generation(byte t1[16][16],byte t2[16][16])
{
  byte i,j;

  for(i=0;i<Width;i++)
  {
    for(j=0;j<Height;j++)
    {
      t2[i][j]=t1[i][j];
      last[i][j]=t1[i][j];
    }
  }
}



//**********************************************************************************************************************************************************
void compute_next_generation(byte t1[16][16],byte t2[16][16])
{
  byte i,j;

  for(i=0;i<Width;i++)
  {
    for(j=0;j<Height;j++)
    {
      t1[i][j]=t2[i][j];
    }
  }
  
  noOfGeneration++;
  Serial.println(noOfGeneration);
}



//**********************************************************************************************************************************************************
void compute_neighbouring_cells(byte t1[16][16],byte t2[16][16])   //To Re-visit - does not seems correct
{
  byte i,j,a;

  for(i=0;i<Width;i++)
  {
    for(j=0;j<Height;j++)
    {
      a = countNeighbors(t1,i,j);
      
      if((t1[i][j]==0)&&(a==3)){t2[i][j]=1;}                   // populate if 3 neighours around it
      if((t1[i][j]==1)&&((a==2)||(a==3))){t2[i][j]=1;}         // stay alive if 2 or 3 neigbours around it
      if((t1[i][j]==1)&&((a==1)||(a==0)||(a>3))){t2[i][j]=0;}  // die if only one neighbour or over-crowding with 4 or more neighours
    }
  }
}


byte countNeighbors(byte t1[16][16],byte i, byte j)
{
  byte a;
  if((i==0)&&(j==0))
  {
    a=t1[i][j+1]+t1[i+1][j]+t1[i+1][j+1]+t1[i][Height-1]+t1[i+1][Height-1]+t1[Width-1][j]+t1[Width-1][j+1]+t1[Width-1][Height-1];
  }

  if((i!=0)&&(j!=0)&&(i!=(Width-1))&&(j!=(Height-1)))
  {
    a=t1[i-1][j-1]+t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i+1][j+1]+t1[i+1][j]+t1[i+1][j-1]+t1[i][j-1];
  }
  
  if((i==0)&&(j!=0)&&(j!=(Height-1)))
  {
    a=t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i+1][j+1]+t1[i][j+1]+t1[Width-1][j-1]+t1[Width-1][j]+t1[Width-1][j+1];
  }

  if((i==0)&&(j==(Height-1)))
  {
    a=t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i][0]+t1[i+1][0]+t1[Width-1][0]+t1[Width-1][j]+t1[Width-1][j-1];
  }
  
  if((i==(Width-1))&&(j==0))
  {
    a=t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i][Height-1]+t1[i-1][Height-1]+t1[0][j]+t1[0][j+1]+t1[0][Height-1];
  }
  
  if((i==(Width-1))&&(j!=0)&&(j!=(Height-1)))
  {
    a=t1[i][j-1]+t1[i][j+1]+t1[i-1][j-1]+t1[i-1][j]+t1[i-1][j+1]+t1[0][j]+t1[0][j-1]+t1[0][j+1];
  }
  
  if((i==(Width-1))&&(j==(Height-1)))
  {
    a=t1[i][j-1]+t1[i-1][j-1]+t1[i-1][j]+t1[0][j]+t1[0][j-1]+t1[i][0]+t1[i-1][0]+t1[0][0];
  }

  if((i!=0)&&(i!=(Width-1))&&(j==0))
  {
    a=t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i+1][j+1]+t1[i+1][j]+t1[i][Height-1]+t1[i-1][Height-1]+t1[i+1][Height-1];
  }

  if((i!=0)&&(i!=(Width-1))&&(j==(Height-1)))
  {
    a=t1[i-1][j]+t1[i-1][j-1]+t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i][0]+t1[i-1][0]+t1[i+1][0];
  }
  return a;
}


//**********************************************************************************************************************************************************
void randomize(byte t1[16][16])
{
  byte i,j;
  randomSeed(millis());
  for(i=0;i<Width;i++)
  {
    for(j=0;j<Height;j++)
    {
      t1[i][j]=random(2);
    }
  }
}

/******************************************************************************
 * Tis function converts HSV values to RGB values, scaled from 0 to maxBrightness
 * 
 * The ranges for the input variables are:
 * hue: 0-360
 * sat: 0-255
 * lig: 0-255
 * 
 * The ranges for the output variables are:
 * r: 0-maxBrightness
 * g: 0-maxBrightness
 * b: 0-maxBrightness
 * 
 * r,g, and b are passed as pointers, because a function cannot have 3 return variables
 * Use it like this:
 * int hue, sat, val; 
 * unsigned char red, green, blue;
 * // set hue, sat and val
 * hsv2rgb(hue, sat, val, &red, &green, &blue, maxBrightness); //pass r, g, and b as the location where the result should be stored
 * // use r, b and g.
 * 
 * (c) Elco Jacobs, E-atelier Industrial Design TU/e, July 2011.
 * 
 *****************************************************************************/


void hsv2rgb(unsigned int hue, unsigned int sat, unsigned int val, unsigned char * r, unsigned char * g, unsigned char * b, unsigned char maxBrightness ) { 
  unsigned int H_accent = hue/60;
  unsigned int bottom = ((255 - sat) * val)>>8;
  unsigned int top = val;
  unsigned char rising  = ((top-bottom)  *(hue % 60   )  )  /  60  +  bottom;
  unsigned char falling = ((top-bottom)  *(60 - hue % 60)  )  /  60  +  bottom;

  switch(H_accent) {
  case 0:
    *r = top;
    *g = rising;
    *b = bottom;
    break;

  case 1:
    *r = falling;
    *g = top;
    *b = bottom;
    break;

  case 2:
    *r = bottom;
    *g = top;
    *b = rising;
    break;

  case 3:
    *r = bottom;
    *g = falling;
    *b = top;
    break;

  case 4:
    *r = rising;
    *g = bottom;
    *b = top;
    break;

  case 5:
    *r = top;
    *g = bottom;
    *b = falling;
    break;
  }
  // Scale values to maxBrightness
  *r = *r * maxBrightness/255;
  *g = *g * maxBrightness/255;
  *b = *b * maxBrightness/255;
}

Reduce/reduce conflict parsing constructor definitions

I've just added this project grammar to https://mingodad.github.io/parsertl-playground/playground/ an Yacc/Lex compatible online editor/tester (select CLanguage parser from Examples then click Parse to see the parser tree for the content in Input source).

Any feedback is welcome !

This grammar has one reduce/reduce conflict that will prevent the execution of ctor_identifier_list production:

State 1

  114 type_specifier: TYPE_NAME •
  256 ctor_identifier_list: TYPE_NAME •

    COLONCOLON  reduce using rule 256 (ctor_identifier_list)
    '('         reduce using rule 114 (type_specifier)
    '('         [reduce using rule 256 (ctor_identifier_list)]
    $default    reduce using rule 114 (type_specifier)

    reduce/reduce conflict on token '(':
      114 type_specifier: TYPE_NAME •
      256 ctor_identifier_list: TYPE_NAME •
      First example: TYPE_NAME • '(' declarator ')' declaration_list compound_statement $end
      First reduce derivation
        $accept
        ↳ 0: translation_unit                                                                                                   $end
             ↳ 248: external_declaration
                    ↳ 250: function_definition
                           ↳ 254: declaration_specifiers   declarator                       declaration_list compound_statement
                                  ↳ 85: type_specifier     ↳ 138: direct_declarator
                                        ↳ 114: TYPE_NAME •        ↳ 144: '(' declarator ')'
      Second example: TYPE_NAME • '(' ')' compound_statement $end
      Second reduce derivation
        $accept
        ↳ 0: translation_unit                                                     $end
             ↳ 248: external_declaration
                    ↳ 253: ctor_definition
                           ↳ 259: ctor_identifier_list '(' ')' compound_statement
                                  ↳ 256: TYPE_NAME •

Support expressions as arguments in invocations

Support expressions as arguments in invocations

Some Arduino examples for the NeoPixel use this line of code as part of the constructor

Adafruit_NeoPixel strip(numPixels, neoPixelPin, NEO_GRB + NEO_KHZ800);

However, this syntax is not allowed, and is denoted as a syntax error, specifically the sum NEO_GRB + NEO_KHZ800, this syntax is important because this is the common way to set the arguments to the NeoPixel driver constructor

References

NeoPixel Examples

C Bitmap Structure

Hello @praeclarum ! Thanks for developing this useful library!

i have an issue/request...i need to parse several .h header files in order to find offset of data in memory dump. I used and it works for structures and variables but i now i need to parse bitmaps...

typedef struct
{
unsigned char bit0 : 1;
unsigned char bit1 : 2;
unsigned char NU : 5;
} MyBitmap;

But i have an error with

var exe = CLanguageService.Compile(code, MachineInfo.Windows32, new TestPrinter());

What is it possible to do?
Thanks

errors in compiller

not correct 2d (and more) arrays
return whithout statement not work
errors in lexer:
'\0'
'''
/x11 <- code of char

no empty statement, so for(;;) - not work
bad preprocessor realisation : '#define macros macros' <- endless loop preprocessing when find 'macros' in code
declaration scope - not correct
possible redeclarate variable with same name
not correct declaration specifiers analis : 'long short int' run without problem
incorrect block initialising int arr[2] = {2.0f, 3.0f} <- run whithout cast float to int. it's not correct

no switch
no ellipsis
no goto
incorrect || && logic operators. right hand expressin not run if left ensure logic result '1||2/0' no devision by zero error
constant expression not correct - you need to calc result on your virtual mashine, but you calculate in code.

Switch statement is not working

This code is not working

switch ((int)i % 6) {
      case 0: r = v; g = t; b = p; break;
      case 1: r = q; g = v; b = p; break;
      case 2: r = p; g = v; b = t; break;
      case 3: r = p; g = q; b = v; break;
      case 4: r = t; g = p; b = v; break;
      case 5: r = v; g = p; b = q; break;
  }

is it possible to debug lines of code line by line

Hi,
Excellent project. I want to write a debugger so that I can step through the c code line by line. Is there a way of storing the soource code line number that each bytecode instruction came from.
Thanks

Parse header file

Is there any easy way to parse header file (.h/.hpp) to get information about struct/enum definitions, as well as global variables and function definitions?

EditorTextView.GetLinesInRange Crashes

https://appcenter.ms/users/praeclarum/apps/iCircuit/crashes/errors/149568011u/overview

EditorTextView.GetLinesInRange (Foundation.NSRange range)
SIGABRT: Index was outside the bounds of the array.
EditorTextView.GetLinesInRange (Foundation.NSRange range)
CEditor.UpdateMargin ()
CEditor.DidProcessEditingDep (Foundation.NSNotification aNotification)
AsyncMethodBuilderCore+<>c.<ThrowAsync>b__7_0 (System.Object state)
NSAsyncSynchronizationContextDispatcher.Apply ()

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.