This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# declaring putc as an external function with implicit io | |
int putchar(io $, char c): | |
implio cimport "putchar" | |
# print function | |
none print(io $, char ch): | |
putchar($, ch); nothing | |
none print(io $, [char] []): nothing | |
none print(io $, [char] ch:str): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <ctype.h> | |
typedef int bool; | |
#define TRUE 1 | |
#define FALSE 0 | |
/* Returns the operator precedence for an operator */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include <stdio.h> | |
#include <ctype.h> | |
double expr(FILE *f) | |
{ | |
double acc = 0.0; | |
int nxt = fgetc(f); | |
if (isspace(nxt)) | |
return expr(f); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Part of the C AIR instruction to file writer | |
*/ | |
static void air_instr_to_string(FILE * f, struct air_expr * e) | |
{ | |
void * it; | |
int j; | |
struct air_expr * ex; | |
struct air_instr * i = e; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
hidden constant char[4] @0 = char[4] { 102,111,111,0 } | |
global char* @str1 = inline { | |
%0 = char* getptr char[4]* @0, int 0, int 0 | |
} char* %0 | |
global char[4] @str2 = char[4] { 98,97,114,0 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
global int @i = inline { | |
%0 = add int 5, int 3 | |
%1 = add int %0, int 1 | |
} int %1 | |
global int @main(int %argc, char** %argv) { | |
%0 = alloca int | |
%1 = alloca char** | |
%2 = alloca int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
element = declaration | "typedef", declaration | implementation | |
declaration = pending type, finisher, { ",", finisher }, ";" | |
implementation = pending type, finisher, "(", param list, ")", scope | |
pending type = primitive | structure | enumeration | defined type | |
finisher = ["*", finisher | "(", finisher, ")", "(", param list, ")" | identifier] | |
param list = ["void" | parameter, { ",", parameter }] | |
parameter = pending type, finisher | |
primitive = integer | floating | |
integer = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fibs :: [Integer] | |
fibs = fibseed 0 1 | |
where fibseed a b = a : fibseed b (a + b) | |
fib :: Int -> Integer | |
fib n = fibs !! n |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- File parsing hub, providing an interface to the parsers and other | |
-- helper functions to be used by other parsers. | |
-- Copyright (C) 2014 Antonie Blom | |
-- | |
-- This library is free software; you can redistribute it and/or | |
-- modify it under the terms of the GNU Lesser General Public | |
-- License as published by the Free Software Foundation; either | |
-- version 2.1 of the License, or (at your option) any later version. | |
module Compiler.Parser where |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Map (Map) | |
import qualified Data.Map as Map | |
import Data.Maybe (Maybe) | |
import qualified Data.Maybe as Maybe | |
lattice :: Int -> Int -> Int | |
lattice x y = fst (latticeI Map.empty x y) | |
where | |
latticeI m a 1 = (a, m) |