-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from blorente/frontend
Frontend
- Loading branch information
Showing
133 changed files
with
2,194 additions
and
371 deletions.
There are no files selected for viewing
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
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
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
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
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() |
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
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
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; | ||
}; |
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
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; |
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
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]; | ||
|
Oops, something went wrong.