Skip to content

Commit

Permalink
Merge pull request #6 from blorente/frontend
Browse files Browse the repository at this point in the history
Frontend
  • Loading branch information
blorente authored Apr 12, 2017
2 parents 9e76168 + 681f66b commit 4da7938
Show file tree
Hide file tree
Showing 133 changed files with 2,194 additions and 371 deletions.
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ cmake-build-debug/
/cmake-build-debug/
*.make
cmake-build-debug/CMakeFiles/Makefile2
.idea/

/interpreter/src/core/parser/generated/
/deps/antlr/build/
/build/
/deps/antlr/run/
/deps/antlr/cmake/
.idea
/cmake-build-debug/antlr4cpp_generated_src/
/cmake-build-debug/locals/
29 changes: 18 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
language: cpp
compiler:
- gcc
addons:
apt:
sources:
- george-edison55-precise-backports
packages:
- cmake
- cmake-data
sudo: required
before_install:
- sudo add-apt-repository ppa:george-edison55/cmake-3.x --yes
- sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
- sudo apt-get update
install:
- sudo apt-get install cmake
- DEPS_DIR="${TRAVIS_BUILD_DIR}/deps"
- mkdir -p ${DEPS_DIR} && cd ${DEPS_DIR}
- |
if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
CMAKE_URL="https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz"
mkdir -p cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C cmake
export PATH=${DEPS_DIR}/cmake/bin:${PATH}
else
brew upgrade cmake || brew install cmake
fi
- cmake --version
- if [ "$CXX" = "g++" ]; then sudo apt-get install -qq g++-6; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-6" CC="gcc-6"; fi
- sudo apt-get install -y uuid-dev

script:
- cd ${TRAVIS_BUILD_DIR}
- mkdir bin
- cd bin
- cmake -G "Unix Makefiles" ..
- cmake --build .
- make -j2 antlr4cpp antlr4cpp_generation_naylang
- cmake -G "Unix Makefiles" ..
- make -j2 VERBOSE=1
- cd tests
- "./tests -r console -s"
before_deploy:
Expand All @@ -36,4 +43,4 @@ deploy:
branch: master
env:
global:
secure: cEgIAN379G8SJa+JFJhzpa6vBbdjDdgz7PXXakgYh+voGJkPZ63JBNSQYKFqrGGrlV0YiLRAhjopHxrqsmmg/W6Y47QWzMipB2koMABabmFFUlmXT9WmDqTVguUEZVxw5y2MNGEtGrJ9nUOXB6Mo4PiGSbOiEX8CB4FQ+CLM602+j0Skj9C5ToPKxRufK6j9ZqG1QNjauexK3LavcVvnAD8Twl1svkb+nqypwNQKLsfoURgZicQmXDUig0zp32j4WfTnw13ndHTElPZTxYi2+diT61GEIJMEg0a9TjIPn0tLG0KEEqUkpipWUXiLU1i/hTBAHZ3PTv+iTFFJtBMlJdk3BFkmml+h6krvugguiEtQh5gMkwN/uGyaOxuZCSFpsKm/leDuCCcFl8WRLn1h3bZFXwRr7JIfVrAHKOrMuXbyg4zZXDN/GRRYExkx9vgmQRg3Gf0TF9GY1S2aFtcgt/8z9GD0r9/J8vkW5hfAa+0Fv6FDtiPRegNE1cKR4Jaa1WkXJUqeNgUVQogfKi5WhiH1gg9jAKrxts34dB5kM5n3NGgfgbgmQzA75JnCmJOyEwqPHnttApl1TRCEsJat6ajFF2xoD/cBlLZu9jNmIKAALoTgr+N6c7y9+v19DrZslAp2NY3G8TcBmKZzJZwuPXnDKsORXn9AmM/m2qbjXzQ=
secure: cEgIAN379G8SJa+JFJhzpa6vBbdjDdgz7PXXakgYh+voGJkPZ63JBNSQYKFqrGGrlV0YiLRAhjopHxrqsmmg/W6Y47QWzMipB2koMABabmFFUlmXT9WmDqTVguUEZVxw5y2MNGEtGrJ9nUOXB6Mo4PiGSbOiEX8CB4FQ+CLM602+j0Skj9C5ToPKxRufK6j9ZqG1QNjauexK3LavcVvnAD8Twl1svkb+nqypwNQKLsfoURgZicQmXDUig0zp32j4WfTnw13ndHTElPZTxYi2+diT61GEIJMEg0a9TjIPn0tLG0KEEqUkpipWUXiLU1i/hTBAHZ3PTv+iTFFJtBMlJdk3BFkmml+h6krvugguiEtQh5gMkwN/uGyaOxuZCSFpsKm/leDuCCcFl8WRLn1h3bZFXwRr7JIfVrAHKOrMuXbyg4zZXDN/GRRYExkx9vgmQRg3Gf0TF9GY1S2aFtcgt/8z9GD0r9/J8vkW5hfAa+0Fv6FDtiPRegNE1cKR4Jaa1WkXJUqeNgUVQogfKi5WhiH1gg9jAKrxts34dB5kM5n3NGgfgbgmQzA75JnCmJOyEwqPHnttApl1TRCEsJat6ajFF2xoD/cBlLZu9jNmIKAALoTgr+N6c7y9+v19DrZslAp2NY3G8TcBmKZzJZwuPXnDKsORXn9AmM/m2qbjXzQ=
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@
cmake_minimum_required(VERSION 3.0)
project(naylang)

LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )

set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED on)

# set variable pointing to the antlr tool that supports C++
set(ANTLR4CPP_JAR_LOCATION ${PROJECT_SOURCE_DIR}/thirdparty/antlr/antlr-4.7-complete.jar)
# add external build for antlrcpp
include( ExternalAntlr4Cpp )
# add antrl4cpp artifacts to project environment
include_directories( ${ANTLR4CPP_INCLUDE_DIRS} )
link_directories( ${ANTLR4CPP_LIBS} )
message(STATUS "Found antlr4cpp libs: ${ANTLR4CPP_LIBS} and includes: ${ANTLR4CPP_INCLUDE_DIRS} ")

# Build Grace grammar lexer and parsers
antlr4cpp_process_grammar(naylang naylang
${PROJECT_SOURCE_DIR}/grammars/GraceLexer.g4
${PROJECT_SOURCE_DIR}/grammars/GraceParser.g4)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14")

add_subdirectory(interpreter)
Expand Down
177 changes: 177 additions & 0 deletions cmake/ExternalAntlr4Cpp.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
# -*- mode:cmake -*-
#
# This Cmake file is for those using a superbuild Cmake Pattern, it
# will download the tools and build locally
#
# use 2the antlr4cpp_process_grammar to support multiple grammars in the
# same project
#
# - Getting quicky started with Antlr4cpp
#
# Here is how you can use this external project to create the antlr4cpp
# demo to start your project off.
#
# create your project source folder somewhere. e.g. ~/srcfolder/
# + make a subfolder cmake
# + Copy this file to srcfolder/cmake
# + cut below and use it to create srcfolder/CMakeLists.txt,
# + from https://github.com/DanMcLaughlin/antlr4/tree/master/runtime/Cpp/demo Copy main.cpp, GraceLexer.g4 and GraceParser.g4 to ./srcfolder/
#
# next make a build folder e.g. ~/buildfolder/
# from the buildfolder, run cmake ~/srcfolder; make
#
###############################################################
# # minimum required CMAKE version
# CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.2 FATAL_ERROR)
#
# LIST( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake )
#
# # compiler must be 11 or 14
# SET (CMAKE_CXX_STANDARD 11)
#
# # set variable pointing to the antlr tool that supports C++
# set(ANTLR4CPP_JAR_LOCATION /home/user/antlr4-4.5.4-SNAPSHOT.jar)
# # add external build for antlrcpp
# include( ExternalAntlr4Cpp )
# # add antrl4cpp artifacts to project environment
# include_directories( ${ANTLR4CPP_INCLUDE_DIRS} )
# link_directories( ${ANTLR4CPP_LIBS} )
# message(STATUS "Found antlr4cpp libs: ${ANTLR4CPP_LIBS} and includes: ${ANTLR4CPP_INCLUDE_DIRS} ")
#
# # Call macro to add lexer and grammar to your build dependencies.
# antlr4cpp_process_grammar(demo antlrcpptest
# ${CMAKE_CURRENT_SOURCE_DIR}/GraceLexer.g4
# ${CMAKE_CURRENT_SOURCE_DIR}/GraceParser.g4)
# # include generated files in project environment
# include_directories(${antlr4cpp_include_dirs_antlrcpptest})
#
# # add generated grammar to demo binary target
# add_executable(demo main.cpp ${antlr4cpp_src_files_antlrcpptest})
# add_dependencies(demo antlr4cpp antlr4cpp_generation_antlrcpptest)
# target_link_libraries(demo antlr4-runtime)
#
###############################################################

CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12.2)
INCLUDE(ExternalProject)
FIND_PACKAGE(Git REQUIRED)

# only JRE required
FIND_PACKAGE(Java COMPONENTS Runtime REQUIRED)

############ Download and Generate runtime #################
set(ANTLR4CPP_EXTERNAL_ROOT ${CMAKE_BINARY_DIR}/externals/antlr4cpp)
set(ANTLR4CPP_LOCAL_ROOT ${CMAKE_BINARY_DIR}/locals/antlr4cpp)

# external repository
# GIT_REPOSITORY https://github.com/antlr/antlr4.git
set(ANTLR4CPP_EXTERNAL_REPO "https://github.com/antlr/antlr4.git")
set(ANTLR4CPP_EXTERNAL_TAG "4.7")
SET(ANTLR4CPP_LOCAL_REPO ${PROJECT_SOURCE_DIR}/thirdparty/antlr/antlr4-master.zip)

if(NOT EXISTS "${ANTLR4CPP_JAR_LOCATION}")
message(FATAL_ERROR "Unable to find antlr tool. ANTLR4CPP_JAR_LOCATION:${ANTLR4CPP_JAR_LOCATION}")
endif()

# default path for source files
if (NOT ANTLR4CPP_GENERATED_SRC_DIR)
set(ANTLR4CPP_GENERATED_SRC_DIR ${CMAKE_BINARY_DIR}/antlr4cpp_generated_src)
endif()

# download runtime environment
ExternalProject_ADD(
#--External-project-name------
antlr4cpp
#--Depend-on-antrl-tool-----------
# DEPENDS antlrtool
#--Core-directories-----------
PREFIX ${ANTLR4CPP_LOCAL_ROOT}
#--Download step--------------
URL ${ANTLR4CPP_LOCAL_REPO}
# GIT_REPOSITORY ${ANTLR4CPP_EXTERNAL_REPO}
# GIT_TAG ${ANTLR4CPP_EXTERNAL_TAG}
TIMEOUT 10
LOG_DOWNLOAD ON
#--Update step----------
# UPDATE_COMMAND ${GIT_EXECUTABLE} pull
#--Patch step----------
# PATCH_COMMAND sh -c "cp <SOURCE_DIR>/scripts/CMakeLists.txt <SOURCE_DIR>"
#--Configure step-------------
CONFIGURE_COMMAND ${CMAKE_COMMAND} -DCMAKE_BUILD_TYPE=Release -DANTLR4CPP_JAR_LOCATION=${ANTLR4CPP_JAR_LOCATION} -DBUILD_SHARED_LIBS=ON -BUILD_TESTS=OFF -DCMAKE_INSTALL_PREFIX:PATH=<INSTALL_DIR> -DCMAKE_SOURCE_DIR:PATH=<SOURCE_DIR>/runtime/Cpp <SOURCE_DIR>/runtime/Cpp
LOG_CONFIGURE ON
#--Build step-----------------
# BUILD_COMMAND ${CMAKE_MAKE_PROGRAM}
LOG_BUILD ON
#--Install step---------------
# INSTALL_COMMAND ""
# INSTALL_DIR ${CMAKE_BINARY_DIR}/
#--Install step---------------
# INSTALL_COMMAND ""
)

ExternalProject_Get_Property(antlr4cpp INSTALL_DIR)

list(APPEND ANTLR4CPP_INCLUDE_DIRS ${INSTALL_DIR}/include/antlr4-runtime)
foreach(src_path misc atn dfa tree support)
list(APPEND ANTLR4CPP_INCLUDE_DIRS ${INSTALL_DIR}/include/antlr4-runtime/${src_path})
endforeach(src_path)

set(ANTLR4CPP_LIBS "${INSTALL_DIR}/lib")

# antlr4_shared ${INSTALL_DIR}/lib/libantlr4-runtime.so
# antlr4_static ${INSTALL_DIR}/lib/libantlr4-runtime.a

############ Generate runtime #################
# macro to add dependencies to target
#
# Param 1 project name
# Param 1 namespace (postfix for dependencies)
# Param 2 Lexer file (full path)
# Param 3 Parser File (full path)
#
# output
#
# antlr4cpp_src_files_{namespace} - src files for add_executable
# antlr4cpp_include_dirs_{namespace} - include dir for generated headers
# antlr4cpp_generation_{namespace} - for add_dependencies tracking

macro(antlr4cpp_process_grammar
antlr4cpp_project
antlr4cpp_project_namespace
antlr4cpp_grammar_lexer
antlr4cpp_grammar_parser)

if(EXISTS "${ANTLR4CPP_JAR_LOCATION}")
message(STATUS "Found antlr tool: ${ANTLR4CPP_JAR_LOCATION}")
else()
message(FATAL_ERROR "Unable to find antlr tool. ANTLR4CPP_JAR_LOCATION:${ANTLR4CPP_JAR_LOCATION}")
endif()

add_custom_target("antlr4cpp_generation_${antlr4cpp_project}"
COMMAND
${CMAKE_COMMAND} -E make_directory ${ANTLR4CPP_GENERATED_SRC_DIR}
COMMAND
"${Java_JAVA_EXECUTABLE}" -jar "${ANTLR4CPP_JAR_LOCATION}" -Dlanguage=Cpp -listener -visitor -o "${ANTLR4CPP_GENERATED_SRC_DIR}/${antlr4cpp_project}" -package ${antlr4cpp_project_namespace} "${antlr4cpp_grammar_lexer}" "${antlr4cpp_grammar_parser}"
WORKING_DIRECTORY "${CMAKE_BINARY_DIR}"
DEPENDS "${antlr4cpp_grammar_lexer}" "${antlr4cpp_grammar_parser}"
)

# Find all the input files
FILE(GLOB generated_files ${ANTLR4CPP_GENERATED_SRC_DIR}/${antlr4cpp_project}/*.cpp)

# export generated cpp files into list
foreach(generated_file ${generated_files})
list(APPEND antlr4cpp_src_files_${antlr4cpp_project} ${generated_file})
set_source_files_properties(
${generated_file}
PROPERTIES
COMPILE_FLAGS -Wno-overloaded-virtual
)
endforeach(generated_file)
message(STATUS "Antlr4Cpp ${antlr4cpp_project} Generated: ${generated_files}")

# export generated include directory
set(antlr4cpp_include_dirs_${antlr4cpp_project} ${ANTLR4CPP_GENERATED_SRC_DIR}/${antlr4cpp_project})
message(STATUS "Antlr4Cpp ${antlr4cpp_project} include: ${ANTLR4CPP_GENERATED_SRC_DIR}/${antlr4cpp_project}")

endmacro()
5 changes: 5 additions & 0 deletions dists/compile_gcc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ fi
mkdir bin
COMPILEDIR="$ROOTDIR/bin"

# Compile antlr antlr
cd "$ROOTDIR/deps/antlr/"
./linux_build.sh
cd $ROOTDIR

cd $COMPILEDIR
cmake -G "Unix Makefiles" ..
cmake --build .
Expand Down
8 changes: 8 additions & 0 deletions examples/Declarations.grace
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
def x = "Hello";
def y = x.++(" World");
def obj = object {
method add(n) to(t) {
n + t
}
var val := 2;
};
10 changes: 10 additions & 0 deletions examples/Variables.grace
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
def x = "Hello";
def y = x.++(" World");
def obj = object {
method add(n) to(t) {
n + t
}
var val := add(2)to(3);
};
def z = obj.add(3)to(4);
def r = obj.val;
83 changes: 83 additions & 0 deletions grammars/GraceLexer.g4
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
lexer grammar GraceLexer;

// These are all supported lexer sections:

// Lexer file header. Appears at the top of h + cpp files. Use e.g. for copyrights.
@lexer::header {/* lexer header section */}

// Appears before any #include in h + cpp files.
@lexer::preinclude {/* lexer precinclude section */}

// Follows directly after the standard #includes in h + cpp files.
@lexer::postinclude {
/* lexer postinclude section */
#ifndef _WIN32
#pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
}

// Directly preceds the lexer class declaration in the h file (e.g. for additional types etc.).
@lexer::context {/* lexer context section */}

// Appears in the public part of the lexer in the h file.
@lexer::members {/* public lexer declarations section */
bool canTestFoo() { return true; }
bool isItFoo() { return true; }
bool isItBar() { return true; }

void myFooLexerAction() { /* do something*/ };
void myBarLexerAction() { /* do something*/ };
}

// Appears in the private part of the lexer in the h file.
@lexer::declarations {/* private lexer declarations/members section */}

// Appears in line with the other class member definitions in the cpp file.
@lexer::definitions {/* lexer definitions section */}

//channels { CommentsChannel, DirectiveChannel }

tokens {
DUMMY
}

WS : [ \r\t\n]+ -> skip ;
INT: Digit+;
Digit: [0-9];

METHOD: 'method ';
VAR_ASSIGN: ':=';
VAR: 'var ';
DEF: 'def ';
PREFIX: 'prefix';
OBJECT: 'object';

COMMA: ',';
DOT: '.';
DELIMITER: ';';
QUOTE: '"';
EXCLAMATION: '!';
RIGHT_ARROW: '->';
OPEN_PAREN: '(';
CLOSE_PAREN: ')';
OPEN_BRACE: '{';
CLOSE_BRACE: '}';
OPEN_BRACKET: '[';
CLOSE_BRACKET: ']';

CONCAT: '++';
PLUS: '+';
MINUS: '-';
MUL: '*';
DIV: '/';
MOD: '%';
POW: '^';
EQUAL: '=';

TRUE: 'true';
FALSE: 'false';

// SHould be defined last, so that reserved words stay reserved
ID: LETTER (LETTER | '0'..'9')*;
fragment LETTER : [a-zA-Z\u0080-\uFFFF];

Loading

0 comments on commit 4da7938

Please sign in to comment.