From fa10fb123a37168c90a82dae226edff5db7a107e Mon Sep 17 00:00:00 2001 From: Intelligide Date: Mon, 28 Nov 2016 07:29:13 +0100 Subject: [PATCH] Update --- CMakeLists.txt | 48 +- CMakeLists.txt.user | 480 ---- README.rst => README.md | 24 +- configure_lexer.py | 3 - src/.gitignore | 3 + src/CMakeLists.txt | 29 +- src/ast/CMakeLists.txt | 13 + src/ast/src/main.cpp | 96 + src/code-gen/CMakeLists.txt | 13 + src/{ => code-gen}/src/main.cpp | 0 src/include/Statement/BreakStatement.hpp | 17 - src/include/Statement/Expr.hpp | 28 - src/include/Statement/NumberLiteralExpr.h | 11 - src/include/Statement/ReturnStatement.hpp | 16 - src/include/Statement/WhileStatement.hpp | 30 - src/lib/CMakeLists.txt | 33 + src/lib/Lexer.cpp | 46 - src/lib/Statement/AssignStatement.cpp | 1 - src/lib/Statement/BreakStatement.cpp | 9 - src/lib/Statement/CallExpr.cpp | 5 - src/lib/Statement/CompoundStatement.cpp | 56 - src/lib/Statement/Expr.cpp | 1 - src/lib/Statement/NumberLiteralExpr.cpp | 1 - src/lib/Statement/ReturnStatement.cpp | 1 - src/lib/Statement/StringLiteralExpr.cpp | 1 - src/lib/Statement/WhileStatement.cpp | 33 - src/lib/lexer.l | 59 - src/lib/parser.y | 61 - src/lib/src/Lexer.cpp | 19 + src/{include => lib/src}/Lexer.hpp | 0 src/lib/{ => src}/LibParser.cpp | 0 src/{include => lib/src}/LibParser.hpp | 0 src/{include => lib/src}/LibRule.hpp | 0 src/{include => lib/src}/LibRuleSet.hpp | 0 src/lib/src/Parser.cpp | 1177 ++++++++++ src/lib/src/Parser.h | 1364 ++++++++++++ src/lib/{ => src}/SourceLocation.cpp | 28 +- src/{include => lib/src}/SourceLocation.hpp | 3 +- src/lib/{ => src}/SourceManager.cpp | 0 src/{include => lib/src}/SourceManager.hpp | 0 src/lib/{ => src}/Statement.cpp | 0 src/{include => lib/src}/Statement.hpp | 1 + src/lib/src/Statement/AssignStatement.cpp | 1 + .../src/Statement/AssignStatement.h} | 2 +- .../Statement/BinaryOperatorExpr.cpp | 9 +- .../src}/Statement/BinaryOperatorExpr.h | 5 +- src/lib/src/Statement/BreakStatement.cpp | 17 + src/lib/src/Statement/BreakStatement.h | 20 + src/lib/src/Statement/CallExpr.cpp | 5 + src/{include => lib/src}/Statement/CallExpr.h | 2 + src/lib/src/Statement/CompoundStatement.cpp | 56 + .../src/Statement/CompoundStatement.h} | 2 +- src/lib/{ => src}/Statement/DoStatement.cpp | 8 +- .../src/Statement/DoStatement.h} | 7 +- src/lib/src/Statement/Expr.cpp | 1 + src/lib/src/Statement/Expr.hpp | 11 + src/lib/src/Statement/FloatLiteralExpr.cpp | 16 + src/lib/src/Statement/FloatLiteralExpr.h | 19 + src/lib/{ => src}/Statement/ForStatement.cpp | 20 +- .../src/Statement/ForStatement.h} | 8 +- src/lib/{ => src}/Statement/GotoStatement.cpp | 11 +- .../src/Statement/GotoStatement.h} | 10 +- src/lib/{ => src}/Statement/IfStatement.cpp | 17 +- .../src/Statement/IfStatement.h} | 12 +- src/lib/src/Statement/IntegerLiteralExpr.cpp | 16 + src/lib/src/Statement/IntegerLiteralExpr.h | 19 + .../{ => src}/Statement/LabelStatement.cpp | 2 +- .../src/Statement/LabelStatement.h} | 4 +- src/lib/src/Statement/NumberLiteralExpr.cpp | 13 + src/lib/src/Statement/NumberLiteralExpr.h | 17 + .../src}/Statement/OperationKinds.def | 1 - src/lib/src/Statement/ReturnStatement.cpp | 16 + src/lib/src/Statement/ReturnStatement.h | 21 + src/lib/src/Statement/StopStatement.cpp | 1 + src/lib/src/Statement/StopStatement.h | 11 + src/lib/src/Statement/StringLiteralExpr.cpp | 1 + .../src}/Statement/StringLiteralExpr.h | 3 +- src/lib/src/Statement/WhileStatement.cpp | 48 + src/lib/src/Statement/WhileStatement.h | 36 + src/lib/src/Statements | 20 + src/lib/{ => src}/Token.cpp | 0 src/{include => lib/src}/Token.hpp | 0 src/lib/{ => src}/TokenList.cpp | 0 src/{include => lib/src}/TokenList.hpp | 0 src/lib/{ => src}/TranslationUnit.cpp | 0 src/{include => lib/src}/TranslationUnit.hpp | 0 src/lib/src/lexer.l | 49 + src/lib/src/lexer_gen.cpp | 1949 +++++++++++++++++ src/lib/src/location.hh | 192 ++ src/lib/src/parser.yy | 113 + src/{include => lib/src}/version.h.in | 0 src/libtest/main.cpp | 2 +- tests/CMakeLists.txt | 3 +- tests/libblang/files/IfTest.bs | 6 + utils/CMakeLists.txt | 22 - utils/src/string.cpp | 31 - utils/src/string.hpp | 27 - 97 files changed, 5511 insertions(+), 1081 deletions(-) delete mode 100644 CMakeLists.txt.user rename README.rst => README.md (52%) delete mode 100644 configure_lexer.py create mode 100644 src/.gitignore create mode 100644 src/ast/CMakeLists.txt create mode 100644 src/ast/src/main.cpp create mode 100644 src/code-gen/CMakeLists.txt rename src/{ => code-gen}/src/main.cpp (100%) delete mode 100644 src/include/Statement/BreakStatement.hpp delete mode 100644 src/include/Statement/Expr.hpp delete mode 100644 src/include/Statement/NumberLiteralExpr.h delete mode 100644 src/include/Statement/ReturnStatement.hpp delete mode 100644 src/include/Statement/WhileStatement.hpp create mode 100644 src/lib/CMakeLists.txt delete mode 100644 src/lib/Lexer.cpp delete mode 100644 src/lib/Statement/AssignStatement.cpp delete mode 100644 src/lib/Statement/BreakStatement.cpp delete mode 100644 src/lib/Statement/CallExpr.cpp delete mode 100644 src/lib/Statement/CompoundStatement.cpp delete mode 100644 src/lib/Statement/Expr.cpp delete mode 100644 src/lib/Statement/NumberLiteralExpr.cpp delete mode 100644 src/lib/Statement/ReturnStatement.cpp delete mode 100644 src/lib/Statement/StringLiteralExpr.cpp delete mode 100644 src/lib/Statement/WhileStatement.cpp delete mode 100644 src/lib/lexer.l delete mode 100644 src/lib/parser.y create mode 100644 src/lib/src/Lexer.cpp rename src/{include => lib/src}/Lexer.hpp (100%) rename src/lib/{ => src}/LibParser.cpp (100%) rename src/{include => lib/src}/LibParser.hpp (100%) rename src/{include => lib/src}/LibRule.hpp (100%) rename src/{include => lib/src}/LibRuleSet.hpp (100%) create mode 100644 src/lib/src/Parser.cpp create mode 100644 src/lib/src/Parser.h rename src/lib/{ => src}/SourceLocation.cpp (79%) rename src/{include => lib/src}/SourceLocation.hpp (85%) rename src/lib/{ => src}/SourceManager.cpp (100%) rename src/{include => lib/src}/SourceManager.hpp (100%) rename src/lib/{ => src}/Statement.cpp (100%) rename src/{include => lib/src}/Statement.hpp (71%) create mode 100644 src/lib/src/Statement/AssignStatement.cpp rename src/{include/Statement/AssignStatement.hpp => lib/src/Statement/AssignStatement.h} (84%) rename src/lib/{ => src}/Statement/BinaryOperatorExpr.cpp (78%) rename src/{include => lib/src}/Statement/BinaryOperatorExpr.h (85%) create mode 100644 src/lib/src/Statement/BreakStatement.cpp create mode 100644 src/lib/src/Statement/BreakStatement.h create mode 100644 src/lib/src/Statement/CallExpr.cpp rename src/{include => lib/src}/Statement/CallExpr.h (85%) create mode 100644 src/lib/src/Statement/CompoundStatement.cpp rename src/{include/Statement/CompoundStatement.hpp => lib/src/Statement/CompoundStatement.h} (97%) rename src/lib/{ => src}/Statement/DoStatement.cpp (83%) rename src/{include/Statement/DoStatement.hpp => lib/src/Statement/DoStatement.h} (90%) create mode 100644 src/lib/src/Statement/Expr.cpp create mode 100644 src/lib/src/Statement/Expr.hpp create mode 100644 src/lib/src/Statement/FloatLiteralExpr.cpp create mode 100644 src/lib/src/Statement/FloatLiteralExpr.h rename src/lib/{ => src}/Statement/ForStatement.cpp (70%) rename src/{include/Statement/ForStatement.hpp => lib/src/Statement/ForStatement.h} (88%) rename src/lib/{ => src}/Statement/GotoStatement.cpp (78%) rename src/{include/Statement/GotoStatement.hpp => lib/src/Statement/GotoStatement.h} (75%) rename src/lib/{ => src}/Statement/IfStatement.cpp (71%) rename src/{include/Statement/IfStatement.hpp => lib/src/Statement/IfStatement.h} (78%) create mode 100644 src/lib/src/Statement/IntegerLiteralExpr.cpp create mode 100644 src/lib/src/Statement/IntegerLiteralExpr.h rename src/lib/{ => src}/Statement/LabelStatement.cpp (87%) rename src/{include/Statement/LabelStatement.hpp => lib/src/Statement/LabelStatement.h} (84%) create mode 100644 src/lib/src/Statement/NumberLiteralExpr.cpp create mode 100644 src/lib/src/Statement/NumberLiteralExpr.h rename src/{include => lib/src}/Statement/OperationKinds.def (98%) create mode 100644 src/lib/src/Statement/ReturnStatement.cpp create mode 100644 src/lib/src/Statement/ReturnStatement.h create mode 100644 src/lib/src/Statement/StopStatement.cpp create mode 100644 src/lib/src/Statement/StopStatement.h create mode 100644 src/lib/src/Statement/StringLiteralExpr.cpp rename src/{include => lib/src}/Statement/StringLiteralExpr.h (88%) create mode 100644 src/lib/src/Statement/WhileStatement.cpp create mode 100644 src/lib/src/Statement/WhileStatement.h create mode 100644 src/lib/src/Statements rename src/lib/{ => src}/Token.cpp (100%) rename src/{include => lib/src}/Token.hpp (100%) rename src/lib/{ => src}/TokenList.cpp (100%) rename src/{include => lib/src}/TokenList.hpp (100%) rename src/lib/{ => src}/TranslationUnit.cpp (100%) rename src/{include => lib/src}/TranslationUnit.hpp (100%) create mode 100644 src/lib/src/lexer.l create mode 100644 src/lib/src/lexer_gen.cpp create mode 100644 src/lib/src/location.hh create mode 100644 src/lib/src/parser.yy rename src/{include => lib/src}/version.h.in (100%) create mode 100644 tests/libblang/files/IfTest.bs delete mode 100644 utils/CMakeLists.txt delete mode 100644 utils/src/string.cpp delete mode 100644 utils/src/string.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b77818e..e89e61d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,47 +2,49 @@ cmake_minimum_required(VERSION 2.8.3) project(Blang) -if(NOT INSTALL_RUNTIME_DIR) - set(INSTALL_RUNTIME_DIR bin) -endif() +set(Blang_VERSION 1.0.0) +set(Blang_RELEASE 1) -if(NOT INSTALL_LIBRARY_DIR) - set(INSTALL_LIBRARY_DIR bin) -endif() +if (NOT INSTALL_RUNTIME_DIR) + set(INSTALL_RUNTIME_DIR bin) +endif () -if(NOT INSTALL_DATA_DIR) - set(INSTALL_DATA_DIR share/blang) -endif() +if (NOT INSTALL_LIBRARY_DIR) + set(INSTALL_LIBRARY_DIR bin) +endif () -if(NOT INSTALL_DOC_DIR) - set(INSTALL_DOC_DIR doc/blang) -endif() +if (NOT INSTALL_DATA_DIR) + set(INSTALL_DATA_DIR share/blang) +endif () -if(NOT INSTALL_CLIB_DIR) - set(INSTALL_CLIB_DIR clib) -endif() +if (NOT INSTALL_DOC_DIR) + set(INSTALL_DOC_DIR doc/blang) +endif () + +if (NOT INSTALL_CLIB_DIR) + set(INSTALL_CLIB_DIR clib) +endif () set(CMAKE_CXX_FLAGS "-std=c++11") find_package(BISON REQUIRED) find_package(FLEX REQUIRED) -add_subdirectory(utils) add_subdirectory(tools) add_subdirectory(src) option(BUILD_UNIT_TESTS "Build unit tests" OFF) -if(BUILD_UNIT_TESTS) - add_subdirectory(tests) -endif() +if (BUILD_UNIT_TESTS) + add_subdirectory(tests) +endif () option(BUILD_DOC "Build documentation" OFF) -if(BUILD_DOC) - add_subdirectory(doc) -endif() +if (BUILD_DOC) + add_subdirectory(doc) +endif () install(DIRECTORY share/blang/ DESTINATION "${INSTALL_DATA_DIR}") install(DIRECTORY clib/ DESTINATION "${INSTALL_CLIB_DIR}") -install(FILES "LICENSE" "NOTICE" DESTINATION "${INSTALL_DOC_DIR}" ) +install(FILES "LICENSE" "NOTICE" DESTINATION "${INSTALL_DOC_DIR}") diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user deleted file mode 100644 index 0c47ec8..0000000 --- a/CMakeLists.txt.user +++ /dev/null @@ -1,480 +0,0 @@ - - - - - - EnvironmentId - {3fb93d8a-9d4c-46aa-821b-80ac79602a86} - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - true - false - true - - Cpp - - CppGlobal - - - - QmlJS - - QmlJSGlobal - - - 2 - UTF-8 - false - 4 - false - 80 - true - true - 1 - true - false - 0 - true - true - 0 - 8 - true - 1 - true - true - true - false - - - - ProjectExplorer.Project.PluginSettings - - true - - - - ProjectExplorer.Project.Target.0 - - Desktop Qt 5.6.1 MinGW 32bit - Desktop Qt 5.6.1 MinGW 32bit - qt.56.win32_mingw49_kit - 0 - 0 - 2 - - - CMAKE_CXX_COMPILER:FILEPATH=C:/Dev/mingw32/bin/g++.exe - - C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build - - - - - all - - true - Make - - CMakeProjectManager.MakeStep - - 1 - Build - - ProjectExplorer.BuildSteps.Build - - - - - - clean - - true - Make - - CMakeProjectManager.MakeStep - - 1 - Clean - - ProjectExplorer.BuildSteps.Clean - - 2 - false - - Default - Default - CMakeProjectManager.CMakeBuildConfiguration - - 1 - - - 0 - Deploy - - ProjectExplorer.BuildSteps.Deploy - - 1 - Deploy locally - - ProjectExplorer.DefaultDeployConfiguration - - 1 - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - PreBlang - - - C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/tools/PreBlang - -1 - - PreBlang - - CMakeProjectManager.CMakeRunConfiguration.PreBlang - 3768 - false - true - false - false - true - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - Lex - - - C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/tools/lex - -1 - - Lex - - CMakeProjectManager.CMakeRunConfiguration.Lex - 3768 - false - true - false - false - true - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - Blang - - - C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/src - 2 - - Blang - - CMakeProjectManager.CMakeRunConfiguration.Blang - 3768 - false - true - false - false - true - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - LibBlangTests - - - C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/unittests/libblang - -1 - - LibBlangTests (disabled) - - CMakeProjectManager.CMakeRunConfiguration.LibBlangTests - 3768 - false - true - false - false - true - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - lexTest - - - C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/unittests/lex - -1 - - lexTest (disabled) - - CMakeProjectManager.CMakeRunConfiguration.lexTest - 3768 - false - true - false - false - true - - - false - false - 1000 - - true - - false - false - false - false - true - 0.01 - 10 - true - 1 - 25 - - 1 - true - false - true - valgrind - - 0 - 1 - 2 - 3 - 4 - 5 - 6 - 7 - 8 - 9 - 10 - 11 - 12 - 13 - 14 - - MustacheTest - - - C:/Users/Yoann/Documents/Informatique/GitHub/Blang-build/unittests/Mustache - -1 - - MustacheTest (disabled) - - CMakeProjectManager.CMakeRunConfiguration.MustacheTest - 3768 - false - true - false - false - true - - 6 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 18 - - - Version - 18 - - diff --git a/README.rst b/README.md similarity index 52% rename from README.rst rename to README.md index fb00744..ee1b403 100644 --- a/README.rst +++ b/README.md @@ -1,28 +1,14 @@ -G1M-assembler -******* +### G1M-assembler -Introduction -============ +## Introduction -G1M-assembler is a Text-to-BasicCasio converter tools. -Manual -====== +Blang is a Text-to-BasicCasio converter tools. -See the `mkg1m(1)`_ manual page for instructions to run the tool. +## Build -.. _`mkg1m(1)`: man/mkg1m.1 -License -======= - -CastXML is licensed under the `GPL V3`_. -See the ``__ and ``__ files for details. - -Build -===== - -To build g1m-assembler tools from source, first obtain the prerequisites: +To build Blang tools from source, first obtain the prerequisites: * A C/C++ compiler diff --git a/configure_lexer.py b/configure_lexer.py deleted file mode 100644 index 0e94f01..0000000 --- a/configure_lexer.py +++ /dev/null @@ -1,3 +0,0 @@ -import json -json_data = open('file') -data = json.load(json_data) \ No newline at end of file diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000..bfd3092 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1,3 @@ +lib/src/Parser.cpp +lib/parser_gen.cpp +lib/src/Parser.h \ No newline at end of file diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f9fac89..0a54b32 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,15 +1,11 @@ -include_directories(include) +include_directories(lib/src) set(LIBRARY_OUTPUT_PATH lib/${CMAKE_BUILD_TYPE}) -set(Blang_VERSION 1.0.0) -set(Blang_RELEASE 1) -configure_file(include/version.h.in include/version.h @ONLY) - -BISON_TARGET(BlangParser parser.y lib/parser_gen.cpp) -FLEX_TARGET(BlangScanner lexer.l lib/lexer_gen.cpp) -ADD_FLEX_BISON_DEPENDENCY(BlangScanner BlangParser) +add_subdirectory(lib) +add_subdirectory(ast) +add_subdirectory(code-gen) file( GLOB_RECURSE @@ -19,25 +15,8 @@ file( add_executable(Blang ${sources_files}) -file( - GLOB_RECURSE - lib_files - lib/* -) - -add_library( - libblang - SHARED - ${lib_files} -) - target_link_libraries( Blang libblang ) -target_link_libraries( - libblang - libpreblang - blangutils -) diff --git a/src/ast/CMakeLists.txt b/src/ast/CMakeLists.txt new file mode 100644 index 0000000..bc75591 --- /dev/null +++ b/src/ast/CMakeLists.txt @@ -0,0 +1,13 @@ +file( + GLOB_RECURSE + sources_files + src/* +) + +add_executable(blang-ast ${sources_files}) + +target_link_libraries( + blang-ast + libblang +) + diff --git a/src/ast/src/main.cpp b/src/ast/src/main.cpp new file mode 100644 index 0000000..380845f --- /dev/null +++ b/src/ast/src/main.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include +#include +#include + +using namespace std; + +string getHelpString(){ + return "\nUsage : Blang input-file [OPTION]\n\n" + " -o output\t\tWrite output to file.\n" + " -l lib\t\tSearch the library named library.\n" + " -L dir\t\tadd all the libraries in the folder dir.\n" + " -v\t\t\tShow version then exit\n" + " -h\t\t\tShow help then exit\n"; +} + +string getVersionString(){ + string str; +/* + str += "g1m-assembler-mkg1m version "; + str += BLANG_VERSION; + str += " release "; + str += BLANG_RELEASE; +*/ + return str; +} + +int main(int argc,char *argv[]) +{ + vector outputFiles; + vector CLibraries; + vector CLibraryDir; + + int c; + opterr = 0; // disable getopt error + + int option_index = 0; + static struct option long_options[] = { + {"version", no_argument, 0, 'v' }, + {"help", no_argument, 0, 'h' }, + {"output", required_argument, 0, 'o' }, + {0, 0, 0, 0 } + }; + + while ((c = getopt_long(argc, argv, "o:l:L:vh", long_options,&option_index)) != -1){ + switch (c){ + case 'o': + outputFiles.push_back(optarg); //get output files + break; + case 'l': + CLibraries.push_back(optarg); //get input files + break; + case 'L': + CLibraryDir.push_back(optarg); //get input files + break; + case 'v': + cout << getVersionString(); + return 0; + case 'h': + cout << getHelpString(); + return 0; + case '?': + if (optopt == 'o') + fprintf (stderr, "Option -%c requires an argument.\n", optopt); + else if (isprint (optopt)) + fprintf (stderr, "Unknown option `-%c'.\n", optopt); + else + fprintf (stderr,"Unknown option character `\\x%x'.\n",optopt); + return 1; + default: + return 1; + } + } + + string inputStr; + + if(optind < argc) { + string file = argv[optind]; + ifstream fileStream(file, std::ios::in); + if(fileStream.is_open()) { + // TODO + } else { + cerr << "Cannot open file: " << file; + return 1; + } + } else { + cin >> inputStr; + } + + // TODO + + return 0; +} diff --git a/src/code-gen/CMakeLists.txt b/src/code-gen/CMakeLists.txt new file mode 100644 index 0000000..a9668de --- /dev/null +++ b/src/code-gen/CMakeLists.txt @@ -0,0 +1,13 @@ +file( + GLOB_RECURSE + sources_files + src/* +) + +add_executable(blang-codegen ${sources_files}) + +target_link_libraries( + blang-codegen + libblang +) + diff --git a/src/src/main.cpp b/src/code-gen/src/main.cpp similarity index 100% rename from src/src/main.cpp rename to src/code-gen/src/main.cpp diff --git a/src/include/Statement/BreakStatement.hpp b/src/include/Statement/BreakStatement.hpp deleted file mode 100644 index 44b99a1..0000000 --- a/src/include/Statement/BreakStatement.hpp +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef BREAKSTATEMENT_HPP -#define BREAKSTATEMENT_HPP - -#include "Statement.hpp" -#include "SourceLocation.hpp" - - -class BreakStatement: public Statement{ -public: - SourceLocation getBreakLocation() const; - void setBreakLocation(SourceLocation); - -private: - SourceLocation _BreakLoc; -}; - -#endif \ No newline at end of file diff --git a/src/include/Statement/Expr.hpp b/src/include/Statement/Expr.hpp deleted file mode 100644 index 82e1f64..0000000 --- a/src/include/Statement/Expr.hpp +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef EXPRSTATEMENT_HPP -#define EXPRSTATEMENT_HPP - -#include "Statement.hpp" - -class Expr : public Statement -{ - -public: - - void getCond(); - void getCond() const; - void setCond(); - - void getThen(); - void getThen() const; - void setThen(); - - void getElse(); - void getElse() const; - void setElse(); - - void getIfLocation(); - void getThenLocation(); - -}; - -#endif \ No newline at end of file diff --git a/src/include/Statement/NumberLiteralExpr.h b/src/include/Statement/NumberLiteralExpr.h deleted file mode 100644 index a4b2cdd..0000000 --- a/src/include/Statement/NumberLiteralExpr.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef BLANG_NUMBERLITERALEXPR_H -#define BLANG_NUMBERLITERALEXPR_H - - -class NumberLiteralExpr -{ - -}; - - -#endif //BLANG_NUMBERLITERALEXPR_H diff --git a/src/include/Statement/ReturnStatement.hpp b/src/include/Statement/ReturnStatement.hpp deleted file mode 100644 index 991da8d..0000000 --- a/src/include/Statement/ReturnStatement.hpp +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef RETURNSTATEMENT_HPP -#define RETURNSTATEMENT_HPP - -#include "Statement.hpp" -#include "SourceLocation.hpp" - - -class ReturnStatement: public Statement{ -public: - - SourceLocation getReturnLocation() const; - void setReturnLocation(SourceLocation); - -}; - -#endif \ No newline at end of file diff --git a/src/include/Statement/WhileStatement.hpp b/src/include/Statement/WhileStatement.hpp deleted file mode 100644 index 29fe561..0000000 --- a/src/include/Statement/WhileStatement.hpp +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef WHILESTATEMENT_HPP -#define WHILESTATEMENT_HPP - -#include "Statement.hpp" -#include "Expr.hpp" -#include "SourceLocation.hpp" - - -class WhileStatement: public Statement{ - -public: - - ExprStatement* getCond(); - const ExprStatement* getCond() const; - void setCond(ExprStatement*); - - Statement* getBody(); - const Statement* getBody() const; - void setBody(Statement*); - - SourceLocation getWhileLocation() const; - void setWhileLocation(SourceLocation); - -private: - SourceLocation _WhileLoc; - enum { VAR, COND, BODY, END_EXPR }; - Statement* _subExprs[END_EXPR]; -}; - -#endif \ No newline at end of file diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt new file mode 100644 index 0000000..13cc6e6 --- /dev/null +++ b/src/lib/CMakeLists.txt @@ -0,0 +1,33 @@ + +configure_file(src/version.h.in include/version.h @ONLY) + +BISON_TARGET(BlangParser lib/src/parser.yy lib/src/Parser.cpp DEFINES_FILE lib/src/Parser.h) +FLEX_TARGET(BlangScanner lib/src/lexer.l lib/src/lexer_gen.cpp) +ADD_FLEX_BISON_DEPENDENCY(BlangScanner BlangParser) + +file( + GLOB_RECURSE + src_files + src/* +) + +add_library( + libblang + SHARED + ${src_files} + src/Parser.cpp + src/lexer_gen.cpp +) + +target_link_libraries( + libblang + libpreblang +) + +file( + GLOB_RECURSE + header_files + src/*.h +) + +install(FILES header_files DESTINATION include) \ No newline at end of file diff --git a/src/lib/Lexer.cpp b/src/lib/Lexer.cpp deleted file mode 100644 index 307afc4..0000000 --- a/src/lib/Lexer.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "Lexer.hpp" -#include "TokenList.hpp" - -#include -#include -#include - -#include - -using namespace Blang; - -static std::map regexMap; - -TokenList Lexer::tokenize(const std::string& t){ - - string text(t); - - std::string::const_iterator itt; - TokenList tokenList; - - for ( itt = text.begin (); itt != text.end (); ++ itt ){ - if(text.substr(itt, itt+1) == "If"){ - itt += 2; - }else if(*itt == '\"'){ - int bpos = itt; - while(*itt != '\"') - itt++; - tokenList << Token(Token::Token_StringLiteral, text.substr(itt, itt+1)); - } else if(std::string(" \t").find(*itt) >= 0){ - tokenList << Token(Token::Token_Whitespace, itt); - } - } -} - -TokenList Lexer::tokenizeFile(const std::string& filename){ - std::ifstream fileStream(filename); - if(fileStream){ - std::string text, line; - while(getline(fileStream, line)){ - text += line + std::endl; - } - tokenizeFile(text); - } else { - std::cout << "Error: Unable to read file" << std::endl; - } -} diff --git a/src/lib/Statement/AssignStatement.cpp b/src/lib/Statement/AssignStatement.cpp deleted file mode 100644 index d5918b7..0000000 --- a/src/lib/Statement/AssignStatement.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "../../include/Statement/AssignStatement.hpp" diff --git a/src/lib/Statement/BreakStatement.cpp b/src/lib/Statement/BreakStatement.cpp deleted file mode 100644 index b7cb868..0000000 --- a/src/lib/Statement/BreakStatement.cpp +++ /dev/null @@ -1,9 +0,0 @@ -#include "Statement/BreakStatement.hpp" - -SourceLocation BreakStatement::getBreakLocation() const{ - return _BreakLoc; -} - -void BreakStatement::setBreakLocation(SourceLocation loc){ - _BreakLoc = loc; -} \ No newline at end of file diff --git a/src/lib/Statement/CallExpr.cpp b/src/lib/Statement/CallExpr.cpp deleted file mode 100644 index 6074cc6..0000000 --- a/src/lib/Statement/CallExpr.cpp +++ /dev/null @@ -1,5 +0,0 @@ -// -// Created by yoann on 24/11/16. -// - -#include "../../include/Statement/CallExpr.h" diff --git a/src/lib/Statement/CompoundStatement.cpp b/src/lib/Statement/CompoundStatement.cpp deleted file mode 100644 index 2f80cd9..0000000 --- a/src/lib/Statement/CompoundStatement.cpp +++ /dev/null @@ -1,56 +0,0 @@ -#include "Statement/CompoundStatement.hpp" - -unsigned int CompoundStatement::size() const -{ - return _body.size(); -} - -bool CompoundStatement::empty() const -{ - return _body.empty(); -} - -void CompoundStatement::setLastStatement(Statement *S) -{ - _body.push_back(S); -} - -const_body_iterator CompoundStatement::body_begin() const -{ - return _body.begin(); -} - -body_iterator CompoundStatement::body_begin() -{ - return _body.begin(); -} - -const_body_iterator CompoundStatement::body_end() const -{ - return _body.end(); -} - -body_iterator CompoundStatement::body_end() -{ - return _body.end(); -} - -const_reverse_body_iterator CompoundStatement::body_rbegin() const -{ - return _body.rbegin(); -} - -reverse_body_iterator CompoundStatement::body_rbegin() -{ - return _body.rbegin(); -} - -const_reverse_body_iterator CompoundStatement::body_rend() const -{ - return _body.rend(); -} - -reverse_body_iterator CompoundStatement::body_rend() -{ - return _body.rend(); -} \ No newline at end of file diff --git a/src/lib/Statement/Expr.cpp b/src/lib/Statement/Expr.cpp deleted file mode 100644 index 54d7667..0000000 --- a/src/lib/Statement/Expr.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Statement/Expr.hpp" \ No newline at end of file diff --git a/src/lib/Statement/NumberLiteralExpr.cpp b/src/lib/Statement/NumberLiteralExpr.cpp deleted file mode 100644 index dfe54b0..0000000 --- a/src/lib/Statement/NumberLiteralExpr.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Statement/NumberLiteralExpr.h" diff --git a/src/lib/Statement/ReturnStatement.cpp b/src/lib/Statement/ReturnStatement.cpp deleted file mode 100644 index d4f5dd6..0000000 --- a/src/lib/Statement/ReturnStatement.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Statement/ReturnStatement.hpp" \ No newline at end of file diff --git a/src/lib/Statement/StringLiteralExpr.cpp b/src/lib/Statement/StringLiteralExpr.cpp deleted file mode 100644 index 150e94e..0000000 --- a/src/lib/Statement/StringLiteralExpr.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "Statement/StringLiteralExpr.h" diff --git a/src/lib/Statement/WhileStatement.cpp b/src/lib/Statement/WhileStatement.cpp deleted file mode 100644 index 63e1a83..0000000 --- a/src/lib/Statement/WhileStatement.cpp +++ /dev/null @@ -1,33 +0,0 @@ -#include "Statement/WhileStatement.hpp" - -ExprStatement* WhileStatement::getCond(){ - return reinterpret_cast(_subExprs[COND]); -} - -const ExprStatement* WhileStatement::getCond() const{ - return getCond(); -} - -void WhileStatement::setCond(ExprStatement* e){ - _subExprs[COND] = reinterpret_cast(e); -} - -Statement* WhileStatement::getBody(){ - return _subExprs[BODY]; -} - -const Statement* WhileStatement::getBody() const{ - return getBody(); -} - -void WhileStatement::setBody(Statement* s){ - _subExprs[BODY] = s; -} - -SourceLocation WhileStatement::getWhileLocation() const{ - return _WhileLoc; -} - -void WhileStatement::setWhileLocation(SourceLocation loc){ - _WhileLoc = loc; -} \ No newline at end of file diff --git a/src/lib/lexer.l b/src/lib/lexer.l deleted file mode 100644 index a2da5de..0000000 --- a/src/lib/lexer.l +++ /dev/null @@ -1,59 +0,0 @@ -%{ -#include -#include - -#include "Token.hpp" - -using namespace std; - -string val; -int nbLines = 0; -int nbChars = 0; -%} - -%option noyywrap - -%x strEnv - -integer [0-9]+ -real [0-9]+\.[0-9]*|\.[0-9]+ -value {integer}|{real} -operator "+"|"-"|"/"|"*"|"=>"|"<="|">="|"="|"->" -keyword "+"|"-"|"/"|"*"|"=>"|"<="|">="|"="|"->" -ident [a-zA-Z_][0-9a-zA-Z_]* - -%% - -{value} { val=yytext; return(Token::Token_NumberLiteral); } -{operator} { val=yytext; return(Token::Token_Operator); } -{keyword} { val=yytext; return(Token::Token_Keyword); } -{ident} { val=yytext; return(Token::Token_Identifier); } -"\"" { val.clear(); BEGIN(strEnv); } -"\"" { BEGIN(INITIAL); return(Token::Token_StringLiteral); } -"\n" { cerr << "multi-line strings not allowed" << endl; ++nbLines; } -"\\\n" { val+='\n'; ++nbLines; } // line cut by \ -"\\". { val+=yytext[1]; } -<> { BEGIN(INITIAL); return(STRING); } -. { val+=yytext[0]; } -[ \t]+ { /* nothing to be done */ } -"\n" { ++nbLines; } -. { val=yytext; return(Token::Token_Unknown); } - -%% -int main(int argc,char ** argv) -{ - int token; - if(argc>1) - yyin=fopen(argv[1],"r"); // check result !!! - TODO - do { - token=yylex(); - switch(token) { - case STRING: cerr << "STRING[" << val << "]" << endl; break; - case INTEGER: cerr << "INTEGER[" << val << "]" << endl; break; - } - } while(token); - - cerr << nbLines << " lines" << endl; - return(0); -} \ No newline at end of file diff --git a/src/lib/parser.y b/src/lib/parser.y deleted file mode 100644 index 9e08efc..0000000 --- a/src/lib/parser.y +++ /dev/null @@ -1,61 +0,0 @@ -#include -#include -using namespace std; -int yylex(void); // defini dans progL.cpp, utilise par yyparse() -void yyerror(const char * msg); // defini plus loin, utilise par yyparse() -int lineNumber; // notre compteur de lignes -extern FILE * yyin; // defini dans progL.cpp, utilise par main() - -%} - -%token START END // les lexemes que doit fournir yylex() -%token ASSIGN SEMICOLON -%token IDENT REAL INTEGER -%start program // l'axiome de notre grammaire - -%% - -program : stmtList -; -stmtList : stmtList stmt { CompoundStatement* stmt = $1; stmt.setLastStatement($2); $$ = stmt; } - | stmt { CompoundStatement* stmt = new CompoundStatement(); stmt.setLastStatement($1); $$ = stmt; } -; -stmt : assign - | ifStmt - | WHILE expr EOL stmtList EOL WHILEEND {} - | DO EOL stmtList EOL LPWHILE expr {} - | FOR assignStmt TO expr EOL stmtList EOL NEXT { $$ = new ForStatement($2, $4, $6);} - | FOR assignStmt TO expr STEP expr EOL stmtList EOL NEXT { $$ = new ForStatement($2, $4, $8, $6);} - | GOTO IDENT - | LABEL IDENT - | BREAK - | RETURN - | STOP - | expr -; -expr : IDENT { cerr << "integer expr" << endl; } - | NUMBER { cerr << "real expr" << endl; } - | expr OPERATOR expr { cerr << "ident expr" << endl; } -; -assignStmt : expr ASSIGN IDENT -; -ifStmt : IF expr EOL THEN EOL stmtList EOL IFEND { $$ = new IfStatement($2, $6); } - | IF expr EOL THEN EOL stmtList EOL ELSE EOL stmtList EOL IFEND { $$ = new IfStatement($2, $6, $10); } - | expr => assign { $$ = new IfStatement($2, $3); } - -%% - -void yyerror(const char * msg) -{ - cerr << "line " << lineNumber << ": " << msg << endl; -} - -int main(int argc,char ** argv) -{ - if(argc>1) - yyin=fopen(argv[1],"r"); // check result !!! - lineNumber=1; - if(!yyparse()) - cerr << "Success" << endl; - return(0); -} \ No newline at end of file diff --git a/src/lib/src/Lexer.cpp b/src/lib/src/Lexer.cpp new file mode 100644 index 0000000..a77a32e --- /dev/null +++ b/src/lib/src/Lexer.cpp @@ -0,0 +1,19 @@ +#include "Lexer.hpp" +#include "TokenList.hpp" + +#include +#include +#include + +using namespace Blang; + + +TokenList Lexer::tokenizeFile(const std::string& filename){ + std::ifstream fileStream(filename); + if(fileStream){ + std::string text, line; + // TODO + } else { + std::cout << "Error: Unable to read file" << std::endl; + } +} diff --git a/src/include/Lexer.hpp b/src/lib/src/Lexer.hpp similarity index 100% rename from src/include/Lexer.hpp rename to src/lib/src/Lexer.hpp diff --git a/src/lib/LibParser.cpp b/src/lib/src/LibParser.cpp similarity index 100% rename from src/lib/LibParser.cpp rename to src/lib/src/LibParser.cpp diff --git a/src/include/LibParser.hpp b/src/lib/src/LibParser.hpp similarity index 100% rename from src/include/LibParser.hpp rename to src/lib/src/LibParser.hpp diff --git a/src/include/LibRule.hpp b/src/lib/src/LibRule.hpp similarity index 100% rename from src/include/LibRule.hpp rename to src/lib/src/LibRule.hpp diff --git a/src/include/LibRuleSet.hpp b/src/lib/src/LibRuleSet.hpp similarity index 100% rename from src/include/LibRuleSet.hpp rename to src/lib/src/LibRuleSet.hpp diff --git a/src/lib/src/Parser.cpp b/src/lib/src/Parser.cpp new file mode 100644 index 0000000..8c50a5f --- /dev/null +++ b/src/lib/src/Parser.cpp @@ -0,0 +1,1177 @@ +// A Bison parser, made by GNU Bison 3.0.4. + +// Skeleton implementation for Bison LALR(1) parsers in C++ + +// Copyright (C) 2002-2015 Free Software Foundation, Inc. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// As a special exception, you may create a larger work that contains +// part or all of the Bison parser skeleton and distribute that work +// under terms of your choice, so long as that work isn't itself a +// parser generator using the skeleton or a modified version thereof +// as a parser skeleton. Alternatively, if you modify or redistribute +// the parser skeleton itself, you may (at your option) remove this +// special exception, which will cause the skeleton and the resulting +// Bison output files to be licensed under the GNU General Public +// License without this special exception. + +// This special exception was added by the Free Software Foundation in +// version 2.2 of Bison. + + +// First part of user declarations. +#line 1 "lib/parser.y" // lalr1.cc:404 + +#include +#include + +#include "Statements" + +using namespace std; + + +int yylex(void); +void yyerror(const char * msg); + +std::string filename; +SourceLocation createLocation(int line,int column); + +extern FILE * yyin; + +#line 54 "lib/Parser.cpp" // lalr1.cc:404 + +# ifndef YY_NULLPTR +# if defined __cplusplus && 201103L <= __cplusplus +# define YY_NULLPTR nullptr +# else +# define YY_NULLPTR 0 +# endif +# endif + +#include "Parser.h" + +// User implementation prologue. + +#line 68 "lib/Parser.cpp" // lalr1.cc:412 + + +#ifndef YY_ +# if defined YYENABLE_NLS && YYENABLE_NLS +# if ENABLE_NLS +# include // FIXME: INFRINGES ON USER NAME SPACE. +# define YY_(msgid) dgettext ("bison-runtime", msgid) +# endif +# endif +# ifndef YY_ +# define YY_(msgid) msgid +# endif +#endif + +#define YYRHSLOC(Rhs, K) ((Rhs)[K].location) +/* YYLLOC_DEFAULT -- Set CURRENT to span from RHS[1] to RHS[N]. + If N is 0, then set CURRENT to the empty location which ends + the previous symbol: RHS[0] (always defined). */ + +# ifndef YYLLOC_DEFAULT +# define YYLLOC_DEFAULT(Current, Rhs, N) \ + do \ + if (N) \ + { \ + (Current).begin = YYRHSLOC (Rhs, 1).begin; \ + (Current).end = YYRHSLOC (Rhs, N).end; \ + } \ + else \ + { \ + (Current).begin = (Current).end = YYRHSLOC (Rhs, 0).end; \ + } \ + while (/*CONSTCOND*/ false) +# endif + + +// Suppress unused-variable warnings by "using" E. +#define YYUSE(E) ((void) (E)) + +// Enable debugging if requested. +#if YYDEBUG + +// A pseudo ostream that takes yydebug_ into account. +# define YYCDEBUG if (yydebug_) (*yycdebug_) + +# define YY_SYMBOL_PRINT(Title, Symbol) \ + do { \ + if (yydebug_) \ + { \ + *yycdebug_ << Title << ' '; \ + yy_print_ (*yycdebug_, Symbol); \ + *yycdebug_ << std::endl; \ + } \ + } while (false) + +# define YY_REDUCE_PRINT(Rule) \ + do { \ + if (yydebug_) \ + yy_reduce_print_ (Rule); \ + } while (false) + +# define YY_STACK_PRINT() \ + do { \ + if (yydebug_) \ + yystack_print_ (); \ + } while (false) + +#else // !YYDEBUG + +# define YYCDEBUG if (false) std::cerr +# define YY_SYMBOL_PRINT(Title, Symbol) YYUSE(Symbol) +# define YY_REDUCE_PRINT(Rule) static_cast(0) +# define YY_STACK_PRINT() static_cast(0) + +#endif // !YYDEBUG + +#define yyerrok (yyerrstatus_ = 0) +#define yyclearin (yyla.clear ()) + +#define YYACCEPT goto yyacceptlab +#define YYABORT goto yyabortlab +#define YYERROR goto yyerrorlab +#define YYRECOVERING() (!!yyerrstatus_) + + +namespace yy { +#line 154 "lib/Parser.cpp" // lalr1.cc:479 + + /* Return YYSTR after stripping away unnecessary quotes and + backslashes, so that it's suitable for yyerror. The heuristic is + that double-quoting is unnecessary unless the string contains an + apostrophe, a comma, or backslash (other than backslash-backslash). + YYSTR is taken from yytname. */ + std::string + Parser ::yytnamerr_ (const char *yystr) + { + if (*yystr == '"') + { + std::string yyr = ""; + char const *yyp = yystr; + + for (;;) + switch (*++yyp) + { + case '\'': + case ',': + goto do_not_strip_quotes; + + case '\\': + if (*++yyp != '\\') + goto do_not_strip_quotes; + // Fall through. + default: + yyr += *yyp; + break; + + case '"': + return yyr; + } + do_not_strip_quotes: ; + } + + return yystr; + } + + + /// Build a parser object. + Parser :: Parser () +#if YYDEBUG + :yydebug_ (false), + yycdebug_ (&std::cerr) +#endif + {} + + Parser ::~ Parser () + {} + + + /*---------------. + | Symbol types. | + `---------------*/ + + + + // by_state. + inline + Parser ::by_state::by_state () + : state (empty_state) + {} + + inline + Parser ::by_state::by_state (const by_state& other) + : state (other.state) + {} + + inline + void + Parser ::by_state::clear () + { + state = empty_state; + } + + inline + void + Parser ::by_state::move (by_state& that) + { + state = that.state; + that.clear (); + } + + inline + Parser ::by_state::by_state (state_type s) + : state (s) + {} + + inline + Parser ::symbol_number_type + Parser ::by_state::type_get () const + { + if (state == empty_state) + return empty_symbol; + else + return yystos_[state]; + } + + inline + Parser ::stack_symbol_type::stack_symbol_type () + {} + + + inline + Parser ::stack_symbol_type::stack_symbol_type (state_type s, symbol_type& that) + : super_type (s, that.location) + { + switch (that.type_get ()) + { + case 38: // assignStmt + value.move< AssignStatement* > (that.value); + break; + + case 34: // stmtList + value.move< CompoundStatement* > (that.value); + break; + + case 36: // expr + value.move< Expr* > (that.value); + break; + + case 40: // forStmt + value.move< ForStatement* > (that.value); + break; + + case 39: // ifStmt + value.move< IfStatement* > (that.value); + break; + + case 35: // stmt + value.move< Statement* > (that.value); + break; + + case 25: // INTEGER + case 26: // FLOAT + value.move< int > (that.value); + break; + + case 24: // STRING + case 27: // IDENTIFIER + case 28: // OPERATOR + value.move< std::string > (that.value); + break; + + default: + break; + } + + // that is emptied. + that.type = empty_symbol; + } + + inline + Parser ::stack_symbol_type& + Parser ::stack_symbol_type::operator= (const stack_symbol_type& that) + { + state = that.state; + switch (that.type_get ()) + { + case 38: // assignStmt + value.copy< AssignStatement* > (that.value); + break; + + case 34: // stmtList + value.copy< CompoundStatement* > (that.value); + break; + + case 36: // expr + value.copy< Expr* > (that.value); + break; + + case 40: // forStmt + value.copy< ForStatement* > (that.value); + break; + + case 39: // ifStmt + value.copy< IfStatement* > (that.value); + break; + + case 35: // stmt + value.copy< Statement* > (that.value); + break; + + case 25: // INTEGER + case 26: // FLOAT + value.copy< int > (that.value); + break; + + case 24: // STRING + case 27: // IDENTIFIER + case 28: // OPERATOR + value.copy< std::string > (that.value); + break; + + default: + break; + } + + location = that.location; + return *this; + } + + + template + inline + void + Parser ::yy_destroy_ (const char* yymsg, basic_symbol& yysym) const + { + if (yymsg) + YY_SYMBOL_PRINT (yymsg, yysym); + } + +#if YYDEBUG + template + void + Parser ::yy_print_ (std::ostream& yyo, + const basic_symbol& yysym) const + { + std::ostream& yyoutput = yyo; + YYUSE (yyoutput); + symbol_number_type yytype = yysym.type_get (); + // Avoid a (spurious) G++ 4.8 warning about "array subscript is + // below array bounds". + if (yysym.empty ()) + std::abort (); + yyo << (yytype < yyntokens_ ? "token" : "nterm") + << ' ' << yytname_[yytype] << " (" + << yysym.location << ": "; + YYUSE (yytype); + yyo << ')'; + } +#endif + + inline + void + Parser ::yypush_ (const char* m, state_type s, symbol_type& sym) + { + stack_symbol_type t (s, sym); + yypush_ (m, t); + } + + inline + void + Parser ::yypush_ (const char* m, stack_symbol_type& s) + { + if (m) + YY_SYMBOL_PRINT (m, s); + yystack_.push (s); + } + + inline + void + Parser ::yypop_ (unsigned int n) + { + yystack_.pop (n); + } + +#if YYDEBUG + std::ostream& + Parser ::debug_stream () const + { + return *yycdebug_; + } + + void + Parser ::set_debug_stream (std::ostream& o) + { + yycdebug_ = &o; + } + + + Parser ::debug_level_type + Parser ::debug_level () const + { + return yydebug_; + } + + void + Parser ::set_debug_level (debug_level_type l) + { + yydebug_ = l; + } +#endif // YYDEBUG + + inline Parser ::state_type + Parser ::yy_lr_goto_state_ (state_type yystate, int yysym) + { + int yyr = yypgoto_[yysym - yyntokens_] + yystate; + if (0 <= yyr && yyr <= yylast_ && yycheck_[yyr] == yystate) + return yytable_[yyr]; + else + return yydefgoto_[yysym - yyntokens_]; + } + + inline bool + Parser ::yy_pact_value_is_default_ (int yyvalue) + { + return yyvalue == yypact_ninf_; + } + + inline bool + Parser ::yy_table_value_is_error_ (int yyvalue) + { + return yyvalue == yytable_ninf_; + } + + int + Parser ::parse () + { + // State. + int yyn; + /// Length of the RHS of the rule being reduced. + int yylen = 0; + + // Error handling. + int yynerrs_ = 0; + int yyerrstatus_ = 0; + + /// The lookahead symbol. + symbol_type yyla; + + /// The locations where the error started and ended. + stack_symbol_type yyerror_range[3]; + + /// The return value of parse (). + int yyresult; + + // FIXME: This shoud be completely indented. It is not yet to + // avoid gratuitous conflicts when merging into the master branch. + try + { + YYCDEBUG << "Starting parse" << std::endl; + + + /* Initialize the stack. The initial state will be set in + yynewstate, since the latter expects the semantical and the + location values to have been already stored, initialize these + stacks with a primary value. */ + yystack_.clear (); + yypush_ (YY_NULLPTR, 0, yyla); + + // A new symbol was pushed on the stack. + yynewstate: + YYCDEBUG << "Entering state " << yystack_[0].state << std::endl; + + // Accept? + if (yystack_[0].state == yyfinal_) + goto yyacceptlab; + + goto yybackup; + + // Backup. + yybackup: + + // Try to take a decision without lookahead. + yyn = yypact_[yystack_[0].state]; + if (yy_pact_value_is_default_ (yyn)) + goto yydefault; + + // Read a lookahead token. + if (yyla.empty ()) + { + YYCDEBUG << "Reading a token: "; + try + { + symbol_type yylookahead (yylex ()); + yyla.move (yylookahead); + } + catch (const syntax_error& yyexc) + { + error (yyexc); + goto yyerrlab1; + } + } + YY_SYMBOL_PRINT ("Next token is", yyla); + + /* If the proper action on seeing token YYLA.TYPE is to reduce or + to detect an error, take that action. */ + yyn += yyla.type_get (); + if (yyn < 0 || yylast_ < yyn || yycheck_[yyn] != yyla.type_get ()) + goto yydefault; + + // Reduce or error. + yyn = yytable_[yyn]; + if (yyn <= 0) + { + if (yy_table_value_is_error_ (yyn)) + goto yyerrlab; + yyn = -yyn; + goto yyreduce; + } + + // Count tokens shifted since error; after three, turn off error status. + if (yyerrstatus_) + --yyerrstatus_; + + // Shift the lookahead token. + yypush_ ("Shifting", yyn, yyla); + goto yynewstate; + + /*-----------------------------------------------------------. + | yydefault -- do the default action for the current state. | + `-----------------------------------------------------------*/ + yydefault: + yyn = yydefact_[yystack_[0].state]; + if (yyn == 0) + goto yyerrlab; + goto yyreduce; + + /*-----------------------------. + | yyreduce -- Do a reduction. | + `-----------------------------*/ + yyreduce: + yylen = yyr2_[yyn]; + { + stack_symbol_type yylhs; + yylhs.state = yy_lr_goto_state_(yystack_[yylen].state, yyr1_[yyn]); + /* Variants are always initialized to an empty instance of the + correct type. The default '$$ = $1' action is NOT applied + when using variants. */ + switch (yyr1_[yyn]) + { + case 38: // assignStmt + yylhs.value.build< AssignStatement* > (); + break; + + case 34: // stmtList + yylhs.value.build< CompoundStatement* > (); + break; + + case 36: // expr + yylhs.value.build< Expr* > (); + break; + + case 40: // forStmt + yylhs.value.build< ForStatement* > (); + break; + + case 39: // ifStmt + yylhs.value.build< IfStatement* > (); + break; + + case 35: // stmt + yylhs.value.build< Statement* > (); + break; + + case 25: // INTEGER + case 26: // FLOAT + yylhs.value.build< int > (); + break; + + case 24: // STRING + case 27: // IDENTIFIER + case 28: // OPERATOR + yylhs.value.build< std::string > (); + break; + + default: + break; + } + + + // Compute the default @$. + { + slice slice (yystack_, yylen); + YYLLOC_DEFAULT (yylhs.location, slice, yylen); + } + + // Perform the reduction. + YY_REDUCE_PRINT (yyn); + try + { + switch (yyn) + { + case 3: +#line 61 "lib/parser.y" // lalr1.cc:859 + { CompoundStatement* stmt = yystack_[1].value.as< CompoundStatement* > (); stmt.setLastStatement(yystack_[0].value.as< Statement* > ()); yylhs.value.as< CompoundStatement* > () = stmt; } +#line 632 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 4: +#line 62 "lib/parser.y" // lalr1.cc:859 + { CompoundStatement* stmt = new CompoundStatement(); stmt.setLastStatement(yystack_[0].value.as< Statement* > ()); yylhs.value.as< CompoundStatement* > () = stmt; } +#line 638 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 7: +#line 66 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Statement* > () = new WhileStatement(yystack_[4].value.as< Expr* > (), yystack_[2].value.as< CompoundStatement* > (), createLocation(yylhs.location.first_line, yylhs.location.first_column)); } +#line 644 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 8: +#line 67 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Statement* > () = new DoStatement(yystack_[3].value.as< CompoundStatement* > (), yystack_[0].value.as< Expr* > (), createLocation(yystack_[5].location.first_line, yystack_[5].location.first_column), createLocation(yystack_[0].location.first_line, yystack_[0].location.first_column)); } +#line 650 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 12: +#line 71 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Statement* > () = new BreakStatement(createLocation(yylhs.location.first_line, yylhs.location.first_column)); } +#line 656 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 13: +#line 72 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Statement* > () = new ReturnStatement(createLocation(yylhs.location.first_line, yylhs.location.first_column)); } +#line 662 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 14: +#line 73 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Statement* > () = new StopStatement(createLocation(yylhs.location.first_line, yylhs.location.first_column)); } +#line 668 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 17: +#line 77 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Expr* > () = new StringLiteralExpr(yystack_[0].value.as< std::string > (), createLocation(yystack_[0].location.first_line, yystack_[0].location.first_column)); } +#line 674 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 18: +#line 78 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Expr* > () = new IntegerLiteralExpr(yystack_[0].value.as< int > (), createLocation(yystack_[0].location.first_line, yystack_[0].location.first_column)) } +#line 680 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 19: +#line 79 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Expr* > () = new FloatLiteralExpr(yystack_[0].value.as< int > (), createLocation(yystack_[0].location.first_line, yystack_[0].location.first_column)) } +#line 686 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 20: +#line 80 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< Expr* > () = new BinaryOperatorExpr(yystack_[2].value.as< Expr* > (), yystack_[0].value.as< Expr* > (), BinaryOperatorExpr::getStrOpcode(yystack_[1].value.as< std::string > ())); } +#line 692 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 23: +#line 86 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< IfStatement* > () = new IfStatement(createLocation(yylhs.location.first_line, yylhs.location.first_column), yystack_[6].value.as< Expr* > (), yystack_[2].value.as< CompoundStatement* > ()); } +#line 698 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 24: +#line 87 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< IfStatement* > () = new IfStatement(createLocation(yylhs.location.first_line, yylhs.location.first_column), yystack_[10].value.as< Expr* > (), yystack_[6].value.as< CompoundStatement* > (), createLocation(yystack_[2].location.first_line, yystack_[2].location.first_column), yystack_[2].value.as< CompoundStatement* > ()); } +#line 704 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 25: +#line 88 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< IfStatement* > () = new IfStatement(yystack_[2].value.as< Expr* > (), yystack_[0].value.as< AssignStatement* > ()); } +#line 710 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 26: +#line 90 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< ForStatement* > () = new ForStatement(createLocation(yylhs.location.first_line, yylhs.location.first_column), yystack_[6].value.as< AssignStatement* > (), yystack_[4].value.as< Expr* > (), yystack_[2].value.as< CompoundStatement* > ());} +#line 716 "lib/Parser.cpp" // lalr1.cc:859 + break; + + case 27: +#line 91 "lib/parser.y" // lalr1.cc:859 + { yylhs.value.as< ForStatement* > () = new ForStatement(createLocation(yylhs.location.first_line, yylhs.location.first_column), yystack_[8].value.as< AssignStatement* > (), yystack_[6].value.as< Expr* > (), yystack_[2].value.as< CompoundStatement* > (), yystack_[4].value.as< Expr* > ());} +#line 722 "lib/Parser.cpp" // lalr1.cc:859 + break; + + +#line 726 "lib/Parser.cpp" // lalr1.cc:859 + default: + break; + } + } + catch (const syntax_error& yyexc) + { + error (yyexc); + YYERROR; + } + YY_SYMBOL_PRINT ("-> $$ =", yylhs); + yypop_ (yylen); + yylen = 0; + YY_STACK_PRINT (); + + // Shift the result of the reduction. + yypush_ (YY_NULLPTR, yylhs); + } + goto yynewstate; + + /*--------------------------------------. + | yyerrlab -- here on detecting error. | + `--------------------------------------*/ + yyerrlab: + // If not already recovering from an error, report this error. + if (!yyerrstatus_) + { + ++yynerrs_; + error (yyla.location, yysyntax_error_ (yystack_[0].state, yyla)); + } + + + yyerror_range[1].location = yyla.location; + if (yyerrstatus_ == 3) + { + /* If just tried and failed to reuse lookahead token after an + error, discard it. */ + + // Return failure if at end of input. + if (yyla.type_get () == yyeof_) + YYABORT; + else if (!yyla.empty ()) + { + yy_destroy_ ("Error: discarding", yyla); + yyla.clear (); + } + } + + // Else will try to reuse lookahead token after shifting the error token. + goto yyerrlab1; + + + /*---------------------------------------------------. + | yyerrorlab -- error raised explicitly by YYERROR. | + `---------------------------------------------------*/ + yyerrorlab: + + /* Pacify compilers like GCC when the user code never invokes + YYERROR and the label yyerrorlab therefore never appears in user + code. */ + if (false) + goto yyerrorlab; + yyerror_range[1].location = yystack_[yylen - 1].location; + /* Do not reclaim the symbols of the rule whose action triggered + this YYERROR. */ + yypop_ (yylen); + yylen = 0; + goto yyerrlab1; + + /*-------------------------------------------------------------. + | yyerrlab1 -- common code for both syntax error and YYERROR. | + `-------------------------------------------------------------*/ + yyerrlab1: + yyerrstatus_ = 3; // Each real token shifted decrements this. + { + stack_symbol_type error_token; + for (;;) + { + yyn = yypact_[yystack_[0].state]; + if (!yy_pact_value_is_default_ (yyn)) + { + yyn += yyterror_; + if (0 <= yyn && yyn <= yylast_ && yycheck_[yyn] == yyterror_) + { + yyn = yytable_[yyn]; + if (0 < yyn) + break; + } + } + + // Pop the current state because it cannot handle the error token. + if (yystack_.size () == 1) + YYABORT; + + yyerror_range[1].location = yystack_[0].location; + yy_destroy_ ("Error: popping", yystack_[0]); + yypop_ (); + YY_STACK_PRINT (); + } + + yyerror_range[2].location = yyla.location; + YYLLOC_DEFAULT (error_token.location, yyerror_range, 2); + + // Shift the error token. + error_token.state = yyn; + yypush_ ("Shifting", error_token); + } + goto yynewstate; + + // Accept. + yyacceptlab: + yyresult = 0; + goto yyreturn; + + // Abort. + yyabortlab: + yyresult = 1; + goto yyreturn; + + yyreturn: + if (!yyla.empty ()) + yy_destroy_ ("Cleanup: discarding lookahead", yyla); + + /* Do not reclaim the symbols of the rule whose action triggered + this YYABORT or YYACCEPT. */ + yypop_ (yylen); + while (1 < yystack_.size ()) + { + yy_destroy_ ("Cleanup: popping", yystack_[0]); + yypop_ (); + } + + return yyresult; + } + catch (...) + { + YYCDEBUG << "Exception caught: cleaning lookahead and stack" + << std::endl; + // Do not try to display the values of the reclaimed symbols, + // as their printer might throw an exception. + if (!yyla.empty ()) + yy_destroy_ (YY_NULLPTR, yyla); + + while (1 < yystack_.size ()) + { + yy_destroy_ (YY_NULLPTR, yystack_[0]); + yypop_ (); + } + throw; + } + } + + void + Parser ::error (const syntax_error& yyexc) + { + error (yyexc.location, yyexc.what()); + } + + // Generate an error message. + std::string + Parser ::yysyntax_error_ (state_type yystate, const symbol_type& yyla) const + { + // Number of reported tokens (one for the "unexpected", one per + // "expected"). + size_t yycount = 0; + // Its maximum. + enum { YYERROR_VERBOSE_ARGS_MAXIMUM = 5 }; + // Arguments of yyformat. + char const *yyarg[YYERROR_VERBOSE_ARGS_MAXIMUM]; + + /* There are many possibilities here to consider: + - If this state is a consistent state with a default action, then + the only way this function was invoked is if the default action + is an error action. In that case, don't check for expected + tokens because there are none. + - The only way there can be no lookahead present (in yyla) is + if this state is a consistent state with a default action. + Thus, detecting the absence of a lookahead is sufficient to + determine that there is no unexpected or expected token to + report. In that case, just report a simple "syntax error". + - Don't assume there isn't a lookahead just because this state is + a consistent state with a default action. There might have + been a previous inconsistent state, consistent state with a + non-default action, or user semantic action that manipulated + yyla. (However, yyla is currently not documented for users.) + - Of course, the expected token list depends on states to have + correct lookahead information, and it depends on the parser not + to perform extra reductions after fetching a lookahead from the + scanner and before detecting a syntax error. Thus, state + merging (from LALR or IELR) and default reductions corrupt the + expected token list. However, the list is correct for + canonical LR with one exception: it will still contain any + token that will not be accepted due to an error action in a + later state. + */ + if (!yyla.empty ()) + { + int yytoken = yyla.type_get (); + yyarg[yycount++] = yytname_[yytoken]; + int yyn = yypact_[yystate]; + if (!yy_pact_value_is_default_ (yyn)) + { + /* Start YYX at -YYN if negative to avoid negative indexes in + YYCHECK. In other words, skip the first -YYN actions for + this state because they are default actions. */ + int yyxbegin = yyn < 0 ? -yyn : 0; + // Stay within bounds of both yycheck and yytname. + int yychecklim = yylast_ - yyn + 1; + int yyxend = yychecklim < yyntokens_ ? yychecklim : yyntokens_; + for (int yyx = yyxbegin; yyx < yyxend; ++yyx) + if (yycheck_[yyx + yyn] == yyx && yyx != yyterror_ + && !yy_table_value_is_error_ (yytable_[yyx + yyn])) + { + if (yycount == YYERROR_VERBOSE_ARGS_MAXIMUM) + { + yycount = 1; + break; + } + else + yyarg[yycount++] = yytname_[yyx]; + } + } + } + + char const* yyformat = YY_NULLPTR; + switch (yycount) + { +#define YYCASE_(N, S) \ + case N: \ + yyformat = S; \ + break + YYCASE_(0, YY_("syntax error")); + YYCASE_(1, YY_("syntax error, unexpected %s")); + YYCASE_(2, YY_("syntax error, unexpected %s, expecting %s")); + YYCASE_(3, YY_("syntax error, unexpected %s, expecting %s or %s")); + YYCASE_(4, YY_("syntax error, unexpected %s, expecting %s or %s or %s")); + YYCASE_(5, YY_("syntax error, unexpected %s, expecting %s or %s or %s or %s")); +#undef YYCASE_ + } + + std::string yyres; + // Argument number. + size_t yyi = 0; + for (char const* yyp = yyformat; *yyp; ++yyp) + if (yyp[0] == '%' && yyp[1] == 's' && yyi < yycount) + { + yyres += yytnamerr_ (yyarg[yyi++]); + ++yyp; + } + else + yyres += *yyp; + return yyres; + } + + + const signed char Parser ::yypact_ninf_ = -23; + + const signed char Parser ::yytable_ninf_ = -1; + + const short int + Parser ::yypact_[] = + { + 169, -18, -2, -2, -2, 4, 4, -23, -23, -23, + -23, -23, -23, -23, 14, 169, -23, 27, -23, -23, + -23, -23, 169, -22, -21, 0, 10, -23, -23, -23, + -23, -2, 4, -2, 43, 169, 28, -2, -12, -23, + -23, 33, 64, 12, -13, -2, 36, 169, -2, 169, + -12, -23, 85, -11, 106, 46, 169, 35, 20, -23, + 127, -23, 169, 54, 148, -23, 47, -23 + }; + + const unsigned char + Parser ::yydefact_[] = + { + 0, 0, 0, 0, 0, 0, 0, 12, 13, 14, + 17, 18, 19, 21, 0, 2, 4, 15, 16, 5, + 6, 9, 0, 0, 0, 0, 0, 10, 11, 1, + 3, 0, 0, 0, 0, 0, 0, 0, 20, 22, + 25, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 8, 7, 0, 0, 0, 0, 0, 0, 0, 23, + 0, 26, 0, 0, 0, 27, 0, 24 + }; + + const signed char + Parser ::yypgoto_[] = + { + -23, -23, -14, -15, -1, 6, 1, -23, -23 + }; + + const signed char + Parser ::yydefgoto_[] = + { + -1, 14, 15, 16, 17, 18, 19, 20, 21 + }; + + const unsigned char + Parser ::yytable_[] = + { + 30, 23, 24, 25, 48, 26, 31, 31, 34, 35, + 36, 27, 28, 22, 29, 31, 31, 31, 49, 30, + 56, 42, 10, 11, 12, 13, 37, 30, 31, 32, + 38, 13, 25, 52, 40, 54, 44, 30, 39, 30, + 43, 45, 60, 47, 50, 30, 51, 53, 64, 30, + 1, 62, 2, 61, 3, 31, 32, 33, 4, 58, + 59, 67, 5, 6, 7, 8, 9, 10, 11, 12, + 13, 1, 65, 2, 41, 3, 0, 0, 0, 4, + 0, 0, 0, 5, 6, 7, 8, 9, 10, 11, + 12, 13, 1, 0, 2, 46, 3, 0, 0, 0, + 4, 0, 0, 0, 5, 6, 7, 8, 9, 10, + 11, 12, 13, 1, 0, 2, 55, 3, 0, 0, + 0, 4, 0, 0, 0, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 1, 0, 2, 57, 3, 0, + 0, 0, 4, 0, 0, 0, 5, 6, 7, 8, + 9, 10, 11, 12, 13, 1, 0, 2, 63, 3, + 0, 0, 0, 4, 0, 0, 0, 5, 6, 7, + 8, 9, 10, 11, 12, 13, 1, 0, 2, 66, + 3, 0, 0, 0, 4, 0, 0, 0, 5, 6, + 7, 8, 9, 10, 11, 12, 13 + }; + + const signed char + Parser ::yycheck_[] = + { + 15, 2, 3, 4, 17, 4, 28, 28, 22, 31, + 31, 5, 6, 31, 0, 28, 28, 28, 31, 34, + 31, 35, 24, 25, 26, 27, 16, 42, 28, 29, + 31, 27, 33, 47, 33, 49, 37, 52, 32, 54, + 12, 8, 56, 31, 45, 60, 10, 48, 62, 64, + 7, 31, 9, 18, 11, 28, 29, 30, 15, 13, + 14, 14, 19, 20, 21, 22, 23, 24, 25, 26, + 27, 7, 18, 9, 31, 11, -1, -1, -1, 15, + -1, -1, -1, 19, 20, 21, 22, 23, 24, 25, + 26, 27, 7, -1, 9, 31, 11, -1, -1, -1, + 15, -1, -1, -1, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 7, -1, 9, 31, 11, -1, -1, + -1, 15, -1, -1, -1, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 7, -1, 9, 31, 11, -1, + -1, -1, 15, -1, -1, -1, 19, 20, 21, 22, + 23, 24, 25, 26, 27, 7, -1, 9, 31, 11, + -1, -1, -1, 15, -1, -1, -1, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 7, -1, 9, 31, + 11, -1, -1, -1, 15, -1, -1, -1, 19, 20, + 21, 22, 23, 24, 25, 26, 27 + }; + + const unsigned char + Parser ::yystos_[] = + { + 0, 7, 9, 11, 15, 19, 20, 21, 22, 23, + 24, 25, 26, 27, 33, 34, 35, 36, 37, 38, + 39, 40, 31, 36, 36, 36, 38, 37, 37, 0, + 35, 28, 29, 30, 34, 31, 31, 16, 36, 37, + 38, 31, 34, 12, 36, 8, 31, 31, 17, 31, + 36, 10, 34, 36, 34, 31, 31, 31, 13, 14, + 34, 18, 31, 31, 34, 18, 31, 14 + }; + + const unsigned char + Parser ::yyr1_[] = + { + 0, 32, 33, 34, 34, 35, 35, 35, 35, 35, + 35, 35, 35, 35, 35, 35, 36, 36, 36, 36, + 36, 37, 38, 39, 39, 39, 40, 40 + }; + + const unsigned char + Parser ::yyr2_[] = + { + 0, 2, 1, 2, 1, 1, 1, 6, 6, 1, + 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, + 3, 1, 3, 8, 12, 3, 8, 10 + }; + + + + // YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM. + // First, the terminals, then, starting at \a yyntokens_, nonterminals. + const char* + const Parser ::yytname_[] = + { + "$end", "error", "$undefined", "'-'", "'+'", "'*'", "'/'", "DO", + "LPWHILE", "WHILE", "WHILEEND", "IF", "THEN", "ELSE", "IFEND", "FOR", + "TO", "STEP", "NEXT", "GOTO", "LABEL", "BREAK", "RETURN", "STOP", + "STRING", "INTEGER", "FLOAT", "IDENTIFIER", "OPERATOR", "ASSIGN", + "IMPLIES", "EOL", "$accept", "program", "stmtList", "stmt", "expr", + "identifier", "assignStmt", "ifStmt", "forStmt", YY_NULLPTR + }; + +#if YYDEBUG + const unsigned char + Parser ::yyrline_[] = + { + 0, 59, 59, 61, 62, 64, 65, 66, 67, 68, + 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, + 80, 82, 84, 86, 87, 88, 90, 91 + }; + + // Print the state stack on the debug stream. + void + Parser ::yystack_print_ () + { + *yycdebug_ << "Stack now"; + for (stack_type::const_iterator + i = yystack_.begin (), + i_end = yystack_.end (); + i != i_end; ++i) + *yycdebug_ << ' ' << i->state; + *yycdebug_ << std::endl; + } + + // Report on the debug stream that the rule \a yyrule is going to be reduced. + void + Parser ::yy_reduce_print_ (int yyrule) + { + unsigned int yylno = yyrline_[yyrule]; + int yynrhs = yyr2_[yyrule]; + // Print the symbols being reduced, and their result. + *yycdebug_ << "Reducing stack by rule " << yyrule - 1 + << " (line " << yylno << "):" << std::endl; + // The symbols being reduced. + for (int yyi = 0; yyi < yynrhs; yyi++) + YY_SYMBOL_PRINT (" $" << yyi + 1 << " =", + yystack_[(yynrhs) - (yyi + 1)]); + } +#endif // YYDEBUG + + + +} // yy +#line 1155 "lib/Parser.cpp" // lalr1.cc:1167 +#line 92 "lib/parser.y" // lalr1.cc:1168 + + +void yyerror(const char * msg) +{ + cerr << "line " << lineNumber << ": " << msg << endl; +} + +SourceLocation createLocation(int line,int column) +{ + return SourceLocation(filename, line, column); +} + + +AST* parse_str(std::string str) +{ + if(argc>1) + yyin=fopen(argv[1],"r"); // check result !!! + lineNumber=1; + if(!yyparse()) + cerr << "Success" << endl; + return(0); +} diff --git a/src/lib/src/Parser.h b/src/lib/src/Parser.h new file mode 100644 index 0000000..415cda6 --- /dev/null +++ b/src/lib/src/Parser.h @@ -0,0 +1,1364 @@ +// A Bison parser, made by GNU Bison 3.0.4. + +// Skeleton interface for Bison LALR(1) parsers in C++ + +// Copyright (C) 2002-2015 Free Software Foundation, Inc. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// As a special exception, you may create a larger work that contains +// part or all of the Bison parser skeleton and distribute that work +// under terms of your choice, so long as that work isn't itself a +// parser generator using the skeleton or a modified version thereof +// as a parser skeleton. Alternatively, if you modify or redistribute +// the parser skeleton itself, you may (at your option) remove this +// special exception, which will cause the skeleton and the resulting +// Bison output files to be licensed under the GNU General Public +// License without this special exception. + +// This special exception was added by the Free Software Foundation in +// version 2.2 of Bison. + +/** + ** \file include/Parser.h + ** Define the yy::parser class. + */ + +// C++ LALR(1) parser skeleton written by Akim Demaille. + +#ifndef YY_YY_INCLUDE_PARSER_H_INCLUDED +# define YY_YY_INCLUDE_PARSER_H_INCLUDED + +# include +# include // std::abort +# include +# include +# include +# include +# include "stack.hh" +# include "location.hh" +#include +#ifndef YYASSERT +# include +# define YYASSERT assert +#endif + + +#ifndef YY_ATTRIBUTE +# if (defined __GNUC__ \ + && (2 < __GNUC__ || (__GNUC__ == 2 && 96 <= __GNUC_MINOR__))) \ + || defined __SUNPRO_C && 0x5110 <= __SUNPRO_C +# define YY_ATTRIBUTE(Spec) __attribute__(Spec) +# else +# define YY_ATTRIBUTE(Spec) /* empty */ +# endif +#endif + +#ifndef YY_ATTRIBUTE_PURE +# define YY_ATTRIBUTE_PURE YY_ATTRIBUTE ((__pure__)) +#endif + +#ifndef YY_ATTRIBUTE_UNUSED +# define YY_ATTRIBUTE_UNUSED YY_ATTRIBUTE ((__unused__)) +#endif + +#if !defined _Noreturn \ + && (!defined __STDC_VERSION__ || __STDC_VERSION__ < 201112) +# if defined _MSC_VER && 1200 <= _MSC_VER +# define _Noreturn __declspec (noreturn) +# else +# define _Noreturn YY_ATTRIBUTE ((__noreturn__)) +# endif +#endif + +/* Suppress unused-variable warnings by "using" E. */ +#if ! defined lint || defined __GNUC__ +# define YYUSE(E) ((void) (E)) +#else +# define YYUSE(E) /* empty */ +#endif + +#if defined __GNUC__ && 407 <= __GNUC__ * 100 + __GNUC_MINOR__ +/* Suppress an incorrect diagnostic about yylval being uninitialized. */ +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \ + _Pragma ("GCC diagnostic push") \ + _Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\ + _Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"") +# define YY_IGNORE_MAYBE_UNINITIALIZED_END \ + _Pragma ("GCC diagnostic pop") +#else +# define YY_INITIAL_VALUE(Value) Value +#endif +#ifndef YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN +# define YY_IGNORE_MAYBE_UNINITIALIZED_END +#endif +#ifndef YY_INITIAL_VALUE +# define YY_INITIAL_VALUE(Value) /* Nothing. */ +#endif + +/* Debug traces. */ +#ifndef YYDEBUG +# define YYDEBUG 1 +#endif + + +namespace yy { +#line 119 "include/Parser.h" // lalr1.cc:377 + + + + /// A char[S] buffer to store and retrieve objects. + /// + /// Sort of a variant, but does not keep track of the nature + /// of the stored data, since that knowledge is available + /// via the current state. + template + struct variant + { + /// Type of *this. + typedef variant self_type; + + /// Empty construction. + variant () + : yytypeid_ (YY_NULLPTR) + {} + + /// Construct and fill. + template + variant (const T& t) + : yytypeid_ (&typeid (T)) + { + YYASSERT (sizeof (T) <= S); + new (yyas_ ()) T (t); + } + + /// Destruction, allowed only if empty. + ~variant () + { + YYASSERT (!yytypeid_); + } + + /// Instantiate an empty \a T in here. + template + T& + build () + { + YYASSERT (!yytypeid_); + YYASSERT (sizeof (T) <= S); + yytypeid_ = & typeid (T); + return *new (yyas_ ()) T; + } + + /// Instantiate a \a T in here from \a t. + template + T& + build (const T& t) + { + YYASSERT (!yytypeid_); + YYASSERT (sizeof (T) <= S); + yytypeid_ = & typeid (T); + return *new (yyas_ ()) T (t); + } + + /// Accessor to a built \a T. + template + T& + as () + { + YYASSERT (*yytypeid_ == typeid (T)); + YYASSERT (sizeof (T) <= S); + return *yyas_ (); + } + + /// Const accessor to a built \a T (for %printer). + template + const T& + as () const + { + YYASSERT (*yytypeid_ == typeid (T)); + YYASSERT (sizeof (T) <= S); + return *yyas_ (); + } + + /// Swap the content with \a other, of same type. + /// + /// Both variants must be built beforehand, because swapping the actual + /// data requires reading it (with as()), and this is not possible on + /// unconstructed variants: it would require some dynamic testing, which + /// should not be the variant's responsability. + /// Swapping between built and (possibly) non-built is done with + /// variant::move (). + template + void + swap (self_type& other) + { + YYASSERT (yytypeid_); + YYASSERT (*yytypeid_ == *other.yytypeid_); + std::swap (as (), other.as ()); + } + + /// Move the content of \a other to this. + /// + /// Destroys \a other. + template + void + move (self_type& other) + { + build (); + swap (other); + other.destroy (); + } + + /// Copy the content of \a other to this. + template + void + copy (const self_type& other) + { + build (other.as ()); + } + + /// Destroy the stored \a T. + template + void + destroy () + { + as ().~T (); + yytypeid_ = YY_NULLPTR; + } + + private: + /// Prohibit blind copies. + self_type& operator=(const self_type&); + variant (const self_type&); + + /// Accessor to raw memory as \a T. + template + T* + yyas_ () + { + void *yyp = yybuffer_.yyraw; + return static_cast (yyp); + } + + /// Const accessor to raw memory as \a T. + template + const T* + yyas_ () const + { + const void *yyp = yybuffer_.yyraw; + return static_cast (yyp); + } + + union + { + /// Strongest alignment constraints. + long double yyalign_me; + /// A buffer large enough to store any of the semantic values. + char yyraw[S]; + } yybuffer_; + + /// Whether the content is built: if defined, the name of the stored type. + const std::type_info *yytypeid_; + }; + + + /// A Bison parser. + class Parser + { + public: +#ifndef YYSTYPE + /// An auxiliary type to compute the largest semantic type. + union union_type + { + // assignStmt + char dummy1[sizeof(AssignStatement*)]; + + // stmtList + char dummy2[sizeof(CompoundStatement*)]; + + // expr + char dummy3[sizeof(Expr*)]; + + // forStmt + char dummy4[sizeof(ForStatement*)]; + + // ifStmt + char dummy5[sizeof(IfStatement*)]; + + // stmt + char dummy6[sizeof(Statement*)]; + + // INTEGER + // FLOAT + char dummy7[sizeof(int)]; + + // STRING + // IDENTIFIER + // OPERATOR + char dummy8[sizeof(std::string)]; +}; + + /// Symbol semantic values. + typedef variant semantic_type; +#else + typedef YYSTYPE semantic_type; +#endif + /// Symbol locations. + typedef location location_type; + + /// Syntax errors thrown from user actions. + struct syntax_error : std::runtime_error + { + syntax_error (const location_type& l, const std::string& m); + location_type location; + }; + + /// Tokens. + struct token + { + enum yytokentype + { + DO = 258, + LPWHILE = 259, + WHILE = 260, + WHILEEND = 261, + IF = 262, + THEN = 263, + ELSE = 264, + IFEND = 265, + FOR = 266, + TO = 267, + STEP = 268, + NEXT = 269, + GOTO = 270, + LABEL = 271, + BREAK = 272, + RETURN = 273, + STOP = 274, + STRING = 275, + INTEGER = 276, + FLOAT = 277, + IDENTIFIER = 278, + OPERATOR = 279, + ASSIGN = 280, + IMPLIES = 281, + EOL = 282 + }; + }; + + /// (External) token type, as returned by yylex. + typedef token::yytokentype token_type; + + /// Symbol type: an internal symbol number. + typedef int symbol_number_type; + + /// The symbol type number to denote an empty symbol. + enum { empty_symbol = -2 }; + + /// Internal symbol number for tokens (subsumed by symbol_number_type). + typedef unsigned char token_number_type; + + /// A complete symbol. + /// + /// Expects its Base type to provide access to the symbol type + /// via type_get(). + /// + /// Provide access to semantic value and location. + template + struct basic_symbol : Base + { + /// Alias to Base. + typedef Base super_type; + + /// Default constructor. + basic_symbol (); + + /// Copy constructor. + basic_symbol (const basic_symbol& other); + + /// Constructor for valueless symbols, and symbols from each type. + + basic_symbol (typename Base::kind_type t, const location_type& l); + + basic_symbol (typename Base::kind_type t, const AssignStatement* v, const location_type& l); + + basic_symbol (typename Base::kind_type t, const CompoundStatement* v, const location_type& l); + + basic_symbol (typename Base::kind_type t, const Expr* v, const location_type& l); + + basic_symbol (typename Base::kind_type t, const ForStatement* v, const location_type& l); + + basic_symbol (typename Base::kind_type t, const IfStatement* v, const location_type& l); + + basic_symbol (typename Base::kind_type t, const Statement* v, const location_type& l); + + basic_symbol (typename Base::kind_type t, const int v, const location_type& l); + + basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l); + + + /// Constructor for symbols with semantic value. + basic_symbol (typename Base::kind_type t, + const semantic_type& v, + const location_type& l); + + /// Destroy the symbol. + ~basic_symbol (); + + /// Destroy contents, and record that is empty. + void clear (); + + /// Whether empty. + bool empty () const; + + /// Destructive move, \a s is emptied into this. + void move (basic_symbol& s); + + /// The semantic value. + semantic_type value; + + /// The location. + location_type location; + + private: + /// Assignment operator. + basic_symbol& operator= (const basic_symbol& other); + }; + + /// Type access provider for token (enum) based symbols. + struct by_type + { + /// Default constructor. + by_type (); + + /// Copy constructor. + by_type (const by_type& other); + + /// The symbol type as needed by the constructor. + typedef token_type kind_type; + + /// Constructor from (external) token numbers. + by_type (kind_type t); + + /// Record that this symbol is empty. + void clear (); + + /// Steal the symbol type from \a that. + void move (by_type& that); + + /// The (internal) type number (corresponding to \a type). + /// \a empty when empty. + symbol_number_type type_get () const; + + /// The token. + token_type token () const; + + /// The symbol type. + /// \a empty_symbol when empty. + /// An int, not token_number_type, to be able to store empty_symbol. + int type; + }; + + /// "External" symbols: returned by the scanner. + typedef basic_symbol symbol_type; + + // Symbol constructors declarations. + static inline + symbol_type + make_DO (const location_type& l); + + static inline + symbol_type + make_LPWHILE (const location_type& l); + + static inline + symbol_type + make_WHILE (const location_type& l); + + static inline + symbol_type + make_WHILEEND (const location_type& l); + + static inline + symbol_type + make_IF (const location_type& l); + + static inline + symbol_type + make_THEN (const location_type& l); + + static inline + symbol_type + make_ELSE (const location_type& l); + + static inline + symbol_type + make_IFEND (const location_type& l); + + static inline + symbol_type + make_FOR (const location_type& l); + + static inline + symbol_type + make_TO (const location_type& l); + + static inline + symbol_type + make_STEP (const location_type& l); + + static inline + symbol_type + make_NEXT (const location_type& l); + + static inline + symbol_type + make_GOTO (const location_type& l); + + static inline + symbol_type + make_LABEL (const location_type& l); + + static inline + symbol_type + make_BREAK (const location_type& l); + + static inline + symbol_type + make_RETURN (const location_type& l); + + static inline + symbol_type + make_STOP (const location_type& l); + + static inline + symbol_type + make_STRING (const std::string& v, const location_type& l); + + static inline + symbol_type + make_INTEGER (const int& v, const location_type& l); + + static inline + symbol_type + make_FLOAT (const int& v, const location_type& l); + + static inline + symbol_type + make_IDENTIFIER (const std::string& v, const location_type& l); + + static inline + symbol_type + make_OPERATOR (const std::string& v, const location_type& l); + + static inline + symbol_type + make_ASSIGN (const location_type& l); + + static inline + symbol_type + make_IMPLIES (const location_type& l); + + static inline + symbol_type + make_EOL (const location_type& l); + + + /// Build a parser object. + Parser (); + virtual ~ Parser (); + + /// Parse. + /// \returns 0 iff parsing succeeded. + virtual int parse (); + +#if YYDEBUG + /// The current debugging stream. + std::ostream& debug_stream () const YY_ATTRIBUTE_PURE; + /// Set the current debugging stream. + void set_debug_stream (std::ostream &); + + /// Type for debugging levels. + typedef int debug_level_type; + /// The current debugging level. + debug_level_type debug_level () const YY_ATTRIBUTE_PURE; + /// Set the current debugging level. + void set_debug_level (debug_level_type l); +#endif + + /// Report a syntax error. + /// \param loc where the syntax error is found. + /// \param msg a description of the syntax error. + virtual void error (const location_type& loc, const std::string& msg); + + /// Report a syntax error. + void error (const syntax_error& err); + + private: + /// This class is not copyable. + Parser (const Parser &); + Parser & operator= (const Parser &); + + /// State numbers. + typedef int state_type; + + /// Generate an error message. + /// \param yystate the state where the error occurred. + /// \param yyla the lookahead token. + virtual std::string yysyntax_error_ (state_type yystate, + const symbol_type& yyla) const; + + /// Compute post-reduction state. + /// \param yystate the current state + /// \param yysym the nonterminal to push on the stack + state_type yy_lr_goto_state_ (state_type yystate, int yysym); + + /// Whether the given \c yypact_ value indicates a defaulted state. + /// \param yyvalue the value to check + static bool yy_pact_value_is_default_ (int yyvalue); + + /// Whether the given \c yytable_ value indicates a syntax error. + /// \param yyvalue the value to check + static bool yy_table_value_is_error_ (int yyvalue); + + static const signed char yypact_ninf_; + static const signed char yytable_ninf_; + + /// Convert a scanner token number \a t to a symbol number. + static token_number_type yytranslate_ (token_type t); + + // Tables. + // YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing + // STATE-NUM. + static const short int yypact_[]; + + // YYDEFACT[STATE-NUM] -- Default reduction number in state STATE-NUM. + // Performed when YYTABLE does not specify something else to do. Zero + // means the default is an error. + static const unsigned char yydefact_[]; + + // YYPGOTO[NTERM-NUM]. + static const signed char yypgoto_[]; + + // YYDEFGOTO[NTERM-NUM]. + static const signed char yydefgoto_[]; + + // YYTABLE[YYPACT[STATE-NUM]] -- What to do in state STATE-NUM. If + // positive, shift that token. If negative, reduce the rule whose + // number is the opposite. If YYTABLE_NINF, syntax error. + static const unsigned char yytable_[]; + + static const signed char yycheck_[]; + + // YYSTOS[STATE-NUM] -- The (internal number of the) accessing + // symbol of state STATE-NUM. + static const unsigned char yystos_[]; + + // YYR1[YYN] -- Symbol number of symbol that rule YYN derives. + static const unsigned char yyr1_[]; + + // YYR2[YYN] -- Number of symbols on the right hand side of rule YYN. + static const unsigned char yyr2_[]; + + + /// Convert the symbol name \a n to a form suitable for a diagnostic. + static std::string yytnamerr_ (const char *n); + + + /// For a symbol, its name in clear. + static const char* const yytname_[]; +#if YYDEBUG + // YYRLINE[YYN] -- Source line where rule number YYN was defined. + static const unsigned char yyrline_[]; + /// Report on the debug stream that the rule \a r is going to be reduced. + virtual void yy_reduce_print_ (int r); + /// Print the state stack on the debug stream. + virtual void yystack_print_ (); + + // Debugging. + int yydebug_; + std::ostream* yycdebug_; + + /// \brief Display a symbol type, value and location. + /// \param yyo The output stream. + /// \param yysym The symbol. + template + void yy_print_ (std::ostream& yyo, const basic_symbol& yysym) const; +#endif + + /// \brief Reclaim the memory associated to a symbol. + /// \param yymsg Why this token is reclaimed. + /// If null, print nothing. + /// \param yysym The symbol. + template + void yy_destroy_ (const char* yymsg, basic_symbol& yysym) const; + + private: + /// Type access provider for state based symbols. + struct by_state + { + /// Default constructor. + by_state (); + + /// The symbol type as needed by the constructor. + typedef state_type kind_type; + + /// Constructor. + by_state (kind_type s); + + /// Copy constructor. + by_state (const by_state& other); + + /// Record that this symbol is empty. + void clear (); + + /// Steal the symbol type from \a that. + void move (by_state& that); + + /// The (internal) type number (corresponding to \a state). + /// \a empty_symbol when empty. + symbol_number_type type_get () const; + + /// The state number used to denote an empty symbol. + enum { empty_state = -1 }; + + /// The state. + /// \a empty when empty. + state_type state; + }; + + /// "Internal" symbol: element of the stack. + struct stack_symbol_type : basic_symbol + { + /// Superclass. + typedef basic_symbol super_type; + /// Construct an empty symbol. + stack_symbol_type (); + /// Steal the contents from \a sym to build this. + stack_symbol_type (state_type s, symbol_type& sym); + /// Assignment, needed by push_back. + stack_symbol_type& operator= (const stack_symbol_type& that); + }; + + /// Stack type. + typedef stack stack_type; + + /// The stack. + stack_type yystack_; + + /// Push a new state on the stack. + /// \param m a debug message to display + /// if null, no trace is output. + /// \param s the symbol + /// \warning the contents of \a s.value is stolen. + void yypush_ (const char* m, stack_symbol_type& s); + + /// Push a new look ahead token on the state on the stack. + /// \param m a debug message to display + /// if null, no trace is output. + /// \param s the state + /// \param sym the symbol (for its value and location). + /// \warning the contents of \a s.value is stolen. + void yypush_ (const char* m, state_type s, symbol_type& sym); + + /// Pop \a n symbols the three stacks. + void yypop_ (unsigned int n = 1); + + /// Constants. + enum + { + yyeof_ = 0, + yylast_ = 196, ///< Last index in yytable_. + yynnts_ = 9, ///< Number of nonterminal symbols. + yyfinal_ = 29, ///< Termination state number. + yyterror_ = 1, + yyerrcode_ = 256, + yyntokens_ = 32 ///< Number of tokens. + }; + + + }; + + // Symbol number corresponding to token number t. + inline + Parser ::token_number_type + Parser ::yytranslate_ (token_type t) + { + static + const token_number_type + translate_table[] = + { + 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 5, 4, 2, 3, 2, 6, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, + 2, 2, 2, 2, 2, 2, 1, 2, 7, 8, + 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, + 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, + 29, 30, 31 + }; + const unsigned int user_token_number_max_ = 282; + const token_number_type undef_token_ = 2; + + if (static_cast(t) <= yyeof_) + return yyeof_; + else if (static_cast (t) <= user_token_number_max_) + return translate_table[t]; + else + return undef_token_; + } + + inline + Parser ::syntax_error::syntax_error (const location_type& l, const std::string& m) + : std::runtime_error (m) + , location (l) + {} + + // basic_symbol. + template + inline + Parser ::basic_symbol::basic_symbol () + : value () + {} + + template + inline + Parser ::basic_symbol::basic_symbol (const basic_symbol& other) + : Base (other) + , value () + , location (other.location) + { + switch (other.type_get ()) + { + case 38: // assignStmt + value.copy< AssignStatement* > (other.value); + break; + + case 34: // stmtList + value.copy< CompoundStatement* > (other.value); + break; + + case 36: // expr + value.copy< Expr* > (other.value); + break; + + case 40: // forStmt + value.copy< ForStatement* > (other.value); + break; + + case 39: // ifStmt + value.copy< IfStatement* > (other.value); + break; + + case 35: // stmt + value.copy< Statement* > (other.value); + break; + + case 25: // INTEGER + case 26: // FLOAT + value.copy< int > (other.value); + break; + + case 24: // STRING + case 27: // IDENTIFIER + case 28: // OPERATOR + value.copy< std::string > (other.value); + break; + + default: + break; + } + + } + + + template + inline + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const semantic_type& v, const location_type& l) + : Base (t) + , value () + , location (l) + { + (void) v; + switch (this->type_get ()) + { + case 38: // assignStmt + value.copy< AssignStatement* > (v); + break; + + case 34: // stmtList + value.copy< CompoundStatement* > (v); + break; + + case 36: // expr + value.copy< Expr* > (v); + break; + + case 40: // forStmt + value.copy< ForStatement* > (v); + break; + + case 39: // ifStmt + value.copy< IfStatement* > (v); + break; + + case 35: // stmt + value.copy< Statement* > (v); + break; + + case 25: // INTEGER + case 26: // FLOAT + value.copy< int > (v); + break; + + case 24: // STRING + case 27: // IDENTIFIER + case 28: // OPERATOR + value.copy< std::string > (v); + break; + + default: + break; + } +} + + + // Implementation of basic_symbol constructor for each type. + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const location_type& l) + : Base (t) + , value () + , location (l) + {} + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const AssignStatement* v, const location_type& l) + : Base (t) + , value (v) + , location (l) + {} + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const CompoundStatement* v, const location_type& l) + : Base (t) + , value (v) + , location (l) + {} + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const Expr* v, const location_type& l) + : Base (t) + , value (v) + , location (l) + {} + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const ForStatement* v, const location_type& l) + : Base (t) + , value (v) + , location (l) + {} + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const IfStatement* v, const location_type& l) + : Base (t) + , value (v) + , location (l) + {} + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const Statement* v, const location_type& l) + : Base (t) + , value (v) + , location (l) + {} + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const int v, const location_type& l) + : Base (t) + , value (v) + , location (l) + {} + + template + Parser ::basic_symbol::basic_symbol (typename Base::kind_type t, const std::string v, const location_type& l) + : Base (t) + , value (v) + , location (l) + {} + + + template + inline + Parser ::basic_symbol::~basic_symbol () + { + clear (); + } + + template + inline + void + Parser ::basic_symbol::clear () + { + // User destructor. + symbol_number_type yytype = this->type_get (); + basic_symbol& yysym = *this; + (void) yysym; + switch (yytype) + { + default: + break; + } + + // Type destructor. + switch (yytype) + { + case 38: // assignStmt + value.template destroy< AssignStatement* > (); + break; + + case 34: // stmtList + value.template destroy< CompoundStatement* > (); + break; + + case 36: // expr + value.template destroy< Expr* > (); + break; + + case 40: // forStmt + value.template destroy< ForStatement* > (); + break; + + case 39: // ifStmt + value.template destroy< IfStatement* > (); + break; + + case 35: // stmt + value.template destroy< Statement* > (); + break; + + case 25: // INTEGER + case 26: // FLOAT + value.template destroy< int > (); + break; + + case 24: // STRING + case 27: // IDENTIFIER + case 28: // OPERATOR + value.template destroy< std::string > (); + break; + + default: + break; + } + + Base::clear (); + } + + template + inline + bool + Parser ::basic_symbol::empty () const + { + return Base::type_get () == empty_symbol; + } + + template + inline + void + Parser ::basic_symbol::move (basic_symbol& s) + { + super_type::move(s); + switch (this->type_get ()) + { + case 38: // assignStmt + value.move< AssignStatement* > (s.value); + break; + + case 34: // stmtList + value.move< CompoundStatement* > (s.value); + break; + + case 36: // expr + value.move< Expr* > (s.value); + break; + + case 40: // forStmt + value.move< ForStatement* > (s.value); + break; + + case 39: // ifStmt + value.move< IfStatement* > (s.value); + break; + + case 35: // stmt + value.move< Statement* > (s.value); + break; + + case 25: // INTEGER + case 26: // FLOAT + value.move< int > (s.value); + break; + + case 24: // STRING + case 27: // IDENTIFIER + case 28: // OPERATOR + value.move< std::string > (s.value); + break; + + default: + break; + } + + location = s.location; + } + + // by_type. + inline + Parser ::by_type::by_type () + : type (empty_symbol) + {} + + inline + Parser ::by_type::by_type (const by_type& other) + : type (other.type) + {} + + inline + Parser ::by_type::by_type (token_type t) + : type (yytranslate_ (t)) + {} + + inline + void + Parser ::by_type::clear () + { + type = empty_symbol; + } + + inline + void + Parser ::by_type::move (by_type& that) + { + type = that.type; + that.clear (); + } + + inline + int + Parser ::by_type::type_get () const + { + return type; + } + + inline + Parser ::token_type + Parser ::by_type::token () const + { + // YYTOKNUM[NUM] -- (External) token number corresponding to the + // (internal) symbol number NUM (which must be that of a token). */ + static + const unsigned short int + yytoken_number_[] = + { + 0, 256, 257, 45, 43, 42, 47, 258, 259, 260, + 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, + 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, + 281, 282 + }; + return static_cast (yytoken_number_[type]); + } + // Implementation of make_symbol for each symbol type. + Parser ::symbol_type + Parser ::make_DO (const location_type& l) + { + return symbol_type (token::DO, l); + } + + Parser ::symbol_type + Parser ::make_LPWHILE (const location_type& l) + { + return symbol_type (token::LPWHILE, l); + } + + Parser ::symbol_type + Parser ::make_WHILE (const location_type& l) + { + return symbol_type (token::WHILE, l); + } + + Parser ::symbol_type + Parser ::make_WHILEEND (const location_type& l) + { + return symbol_type (token::WHILEEND, l); + } + + Parser ::symbol_type + Parser ::make_IF (const location_type& l) + { + return symbol_type (token::IF, l); + } + + Parser ::symbol_type + Parser ::make_THEN (const location_type& l) + { + return symbol_type (token::THEN, l); + } + + Parser ::symbol_type + Parser ::make_ELSE (const location_type& l) + { + return symbol_type (token::ELSE, l); + } + + Parser ::symbol_type + Parser ::make_IFEND (const location_type& l) + { + return symbol_type (token::IFEND, l); + } + + Parser ::symbol_type + Parser ::make_FOR (const location_type& l) + { + return symbol_type (token::FOR, l); + } + + Parser ::symbol_type + Parser ::make_TO (const location_type& l) + { + return symbol_type (token::TO, l); + } + + Parser ::symbol_type + Parser ::make_STEP (const location_type& l) + { + return symbol_type (token::STEP, l); + } + + Parser ::symbol_type + Parser ::make_NEXT (const location_type& l) + { + return symbol_type (token::NEXT, l); + } + + Parser ::symbol_type + Parser ::make_GOTO (const location_type& l) + { + return symbol_type (token::GOTO, l); + } + + Parser ::symbol_type + Parser ::make_LABEL (const location_type& l) + { + return symbol_type (token::LABEL, l); + } + + Parser ::symbol_type + Parser ::make_BREAK (const location_type& l) + { + return symbol_type (token::BREAK, l); + } + + Parser ::symbol_type + Parser ::make_RETURN (const location_type& l) + { + return symbol_type (token::RETURN, l); + } + + Parser ::symbol_type + Parser ::make_STOP (const location_type& l) + { + return symbol_type (token::STOP, l); + } + + Parser ::symbol_type + Parser ::make_STRING (const std::string& v, const location_type& l) + { + return symbol_type (token::STRING, v, l); + } + + Parser ::symbol_type + Parser ::make_INTEGER (const int& v, const location_type& l) + { + return symbol_type (token::INTEGER, v, l); + } + + Parser ::symbol_type + Parser ::make_FLOAT (const int& v, const location_type& l) + { + return symbol_type (token::FLOAT, v, l); + } + + Parser ::symbol_type + Parser ::make_IDENTIFIER (const std::string& v, const location_type& l) + { + return symbol_type (token::IDENTIFIER, v, l); + } + + Parser ::symbol_type + Parser ::make_OPERATOR (const std::string& v, const location_type& l) + { + return symbol_type (token::OPERATOR, v, l); + } + + Parser ::symbol_type + Parser ::make_ASSIGN (const location_type& l) + { + return symbol_type (token::ASSIGN, l); + } + + Parser ::symbol_type + Parser ::make_IMPLIES (const location_type& l) + { + return symbol_type (token::IMPLIES, l); + } + + Parser ::symbol_type + Parser ::make_EOL (const location_type& l) + { + return symbol_type (token::EOL, l); + } + + + +} // yy +#line 1360 "include/Parser.h" // lalr1.cc:377 + + + + +#endif // !YY_YY_INCLUDE_PARSER_H_INCLUDED diff --git a/src/lib/SourceLocation.cpp b/src/lib/src/SourceLocation.cpp similarity index 79% rename from src/lib/SourceLocation.cpp rename to src/lib/src/SourceLocation.cpp index 0c5a84e..baa5458 100644 --- a/src/lib/SourceLocation.cpp +++ b/src/lib/src/SourceLocation.cpp @@ -2,15 +2,27 @@ #include "SourceLocation.hpp" -SourceLocation::SourceLocation(std::string file, int line, int column, int offset): +SourceLocation::SourceLocation(std::string file, int line, int column): _file(file), _line(line), - _column(column), - _offset(offset) + _column(column) { } +SourceLocation::SourceLocation(): + _file(""), + _line(0), + _column(0) +{ + +} + +bool SourceLocation::isValid() const +{ + return _line > 0 && _column > 0 && !_file.empty(); +} + void SourceLocation::print() const { std::cout << printToString(); @@ -49,14 +61,4 @@ int SourceLocation::columnLocation() const void SourceLocation::setColumnLocation(int c) { _column = c; -} - -int SourceLocation::offset() const -{ - return _offset; -} - -void SourceLocation::setOffset(int offset) -{ - _offset = offset; } \ No newline at end of file diff --git a/src/include/SourceLocation.hpp b/src/lib/src/SourceLocation.hpp similarity index 85% rename from src/include/SourceLocation.hpp rename to src/lib/src/SourceLocation.hpp index 010c24b..c7fb93c 100644 --- a/src/include/SourceLocation.hpp +++ b/src/lib/src/SourceLocation.hpp @@ -7,7 +7,7 @@ class SourceLocation { public: SourceLocation(); - SourceLocation(std::string file, int line, int column, int offset); + SourceLocation(std::string file, int line, int column); bool isValid() const; @@ -28,7 +28,6 @@ public: private: std::string _file; - int _offset; int _column; int _line; diff --git a/src/lib/SourceManager.cpp b/src/lib/src/SourceManager.cpp similarity index 100% rename from src/lib/SourceManager.cpp rename to src/lib/src/SourceManager.cpp diff --git a/src/include/SourceManager.hpp b/src/lib/src/SourceManager.hpp similarity index 100% rename from src/include/SourceManager.hpp rename to src/lib/src/SourceManager.hpp diff --git a/src/lib/Statement.cpp b/src/lib/src/Statement.cpp similarity index 100% rename from src/lib/Statement.cpp rename to src/lib/src/Statement.cpp diff --git a/src/include/Statement.hpp b/src/lib/src/Statement.hpp similarity index 71% rename from src/include/Statement.hpp rename to src/lib/src/Statement.hpp index 9990501..c059b9e 100644 --- a/src/include/Statement.hpp +++ b/src/lib/src/Statement.hpp @@ -1,6 +1,7 @@ #ifndef STATEMENT_HPP #define STATEMENT_HPP +#include "SourceLocation.hpp" class Statement{ diff --git a/src/lib/src/Statement/AssignStatement.cpp b/src/lib/src/Statement/AssignStatement.cpp new file mode 100644 index 0000000..0f3ae04 --- /dev/null +++ b/src/lib/src/Statement/AssignStatement.cpp @@ -0,0 +1 @@ +#include "AssignStatement.h" diff --git a/src/include/Statement/AssignStatement.hpp b/src/lib/src/Statement/AssignStatement.h similarity index 84% rename from src/include/Statement/AssignStatement.hpp rename to src/lib/src/Statement/AssignStatement.h index f0b9edb..27e2be3 100644 --- a/src/include/Statement/AssignStatement.hpp +++ b/src/lib/src/Statement/AssignStatement.h @@ -1,7 +1,7 @@ #ifndef BLANG_ASSIGNSTATEMENT_H #define BLANG_ASSIGNSTATEMENT_H -#include "Statement.hpp" +#include "../Statement.hpp" class AssignStatement: public Statement { diff --git a/src/lib/Statement/BinaryOperatorExpr.cpp b/src/lib/src/Statement/BinaryOperatorExpr.cpp similarity index 78% rename from src/lib/Statement/BinaryOperatorExpr.cpp rename to src/lib/src/Statement/BinaryOperatorExpr.cpp index e0f4a61..6b70c16 100644 --- a/src/lib/Statement/BinaryOperatorExpr.cpp +++ b/src/lib/src/Statement/BinaryOperatorExpr.cpp @@ -1,11 +1,11 @@ -#include "Statement/BinaryOperatorExpr.h" +#include "BinaryOperatorExpr.h" -static std::string BinaryOperatorExpr::getOpcodeStr(BinaryOperatorExpr::Opcode opc) const +std::string BinaryOperatorExpr::getOpcodeStr(BinaryOperatorExpr::Opcode opc) { switch (opc) { #define BINARY_OPERATION(Name, Spelling) case BO_##Name: return Spelling; -#include "OperationKinds.def" +#include "Statement/OperationKinds.def" } } @@ -18,6 +18,7 @@ BinaryOperatorExpr::BinaryOperatorExpr(Expr *lhs, Expr *rhs, BinaryOperatorExpr: Expr *BinaryOperatorExpr::getLHS() const { + return _subExprs.at(LHS); } void BinaryOperatorExpr::setLHS(Expr *E) @@ -27,7 +28,7 @@ void BinaryOperatorExpr::setLHS(Expr *E) Expr *BinaryOperatorExpr::getRHS() const { - return _subExprs[RHS]; + return _subExprs.at(RHS); } void BinaryOperatorExpr::setRHS(Expr *E) diff --git a/src/include/Statement/BinaryOperatorExpr.h b/src/lib/src/Statement/BinaryOperatorExpr.h similarity index 85% rename from src/include/Statement/BinaryOperatorExpr.h rename to src/lib/src/Statement/BinaryOperatorExpr.h index fb7d07b..bc52d1d 100644 --- a/src/include/Statement/BinaryOperatorExpr.h +++ b/src/lib/src/Statement/BinaryOperatorExpr.h @@ -1,6 +1,8 @@ #ifndef BLANG_BINARYOPERATOREXPR_H #define BLANG_BINARYOPERATOREXPR_H +#include + #include "Expr.hpp" class BinaryOperatorExpr: public Expr @@ -23,7 +25,8 @@ public: void setOpcode (Opcode O); std::string getOpcodeStr() const; - static std::string getOpcodeStr(Opcode opc) const; + static std::string getOpcodeStr(Opcode opc); + static Opcode getStrOpcode(std::string str); private: Opcode _opc; diff --git a/src/lib/src/Statement/BreakStatement.cpp b/src/lib/src/Statement/BreakStatement.cpp new file mode 100644 index 0000000..feb6c85 --- /dev/null +++ b/src/lib/src/Statement/BreakStatement.cpp @@ -0,0 +1,17 @@ +#include "BreakStatement.h" + +BreakStatement::BreakStatement(SourceLocation l): + _BreakLoc(l) +{ + +} + +SourceLocation BreakStatement::getBreakLocation() const +{ + return _BreakLoc; +} + +void BreakStatement::setBreakLocation(SourceLocation loc) +{ + _BreakLoc = loc; +} \ No newline at end of file diff --git a/src/lib/src/Statement/BreakStatement.h b/src/lib/src/Statement/BreakStatement.h new file mode 100644 index 0000000..e758b4a --- /dev/null +++ b/src/lib/src/Statement/BreakStatement.h @@ -0,0 +1,20 @@ +#ifndef BREAKSTATEMENT_HPP +#define BREAKSTATEMENT_HPP + +#include "../Statement.hpp" +#include "../SourceLocation.hpp" + + +class BreakStatement : public Statement +{ +public: + BreakStatement(SourceLocation l); + + SourceLocation getBreakLocation() const; + void setBreakLocation(SourceLocation); + +private: + SourceLocation _BreakLoc; +}; + +#endif \ No newline at end of file diff --git a/src/lib/src/Statement/CallExpr.cpp b/src/lib/src/Statement/CallExpr.cpp new file mode 100644 index 0000000..67021fd --- /dev/null +++ b/src/lib/src/Statement/CallExpr.cpp @@ -0,0 +1,5 @@ +// +// Created by yoann on 24/11/16. +// + +#include "CallExpr.h" diff --git a/src/include/Statement/CallExpr.h b/src/lib/src/Statement/CallExpr.h similarity index 85% rename from src/include/Statement/CallExpr.h rename to src/lib/src/Statement/CallExpr.h index 0975ed7..674fd1e 100644 --- a/src/include/Statement/CallExpr.h +++ b/src/lib/src/Statement/CallExpr.h @@ -1,6 +1,8 @@ #ifndef CALLEXPR_H #define CALLEXPR_H +#include "Expr.hpp" + /*!Represents a function call */ class CallExpr: public Expr { diff --git a/src/lib/src/Statement/CompoundStatement.cpp b/src/lib/src/Statement/CompoundStatement.cpp new file mode 100644 index 0000000..1bd8e2f --- /dev/null +++ b/src/lib/src/Statement/CompoundStatement.cpp @@ -0,0 +1,56 @@ +#include "CompoundStatement.h" + +unsigned int CompoundStatement::size() const +{ + return _body.size(); +} + +bool CompoundStatement::empty() const +{ + return _body.empty(); +} + +void CompoundStatement::setLastStatement(Statement *S) +{ + _body.push_back(S); +} + +CompoundStatement::const_body_iterator CompoundStatement::body_begin() const +{ + return _body.begin(); +} + +CompoundStatement::body_iterator CompoundStatement::body_begin() +{ + return _body.begin(); +} + +CompoundStatement::const_body_iterator CompoundStatement::body_end() const +{ + return _body.end(); +} + +CompoundStatement::body_iterator CompoundStatement::body_end() +{ + return _body.end(); +} + +CompoundStatement::const_reverse_body_iterator CompoundStatement::body_rbegin() const +{ + return _body.rbegin(); +} + +CompoundStatement::reverse_body_iterator CompoundStatement::body_rbegin() +{ + return _body.rbegin(); +} + +CompoundStatement::const_reverse_body_iterator CompoundStatement::body_rend() const +{ + return _body.rend(); +} + +CompoundStatement::reverse_body_iterator CompoundStatement::body_rend() +{ + return _body.rend(); +} \ No newline at end of file diff --git a/src/include/Statement/CompoundStatement.hpp b/src/lib/src/Statement/CompoundStatement.h similarity index 97% rename from src/include/Statement/CompoundStatement.hpp rename to src/lib/src/Statement/CompoundStatement.h index 82ee92d..4c8ca60 100644 --- a/src/include/Statement/CompoundStatement.hpp +++ b/src/lib/src/Statement/CompoundStatement.h @@ -3,7 +3,7 @@ #include -#include "Statement.hpp" +#include "../Statement.hpp" class CompoundStatement : public Statement { diff --git a/src/lib/Statement/DoStatement.cpp b/src/lib/src/Statement/DoStatement.cpp similarity index 83% rename from src/lib/Statement/DoStatement.cpp rename to src/lib/src/Statement/DoStatement.cpp index 52f6b83..728ce2c 100644 --- a/src/lib/Statement/DoStatement.cpp +++ b/src/lib/src/Statement/DoStatement.cpp @@ -1,4 +1,4 @@ -#include "Statement/DoStatement.hpp" +#include "DoStatement.h" DoStatement::DoStatement(Statement *body, Expr *cond, SourceLocation DL, SourceLocation WL): _doLoc(DL), @@ -11,12 +11,12 @@ DoStatement::DoStatement(Statement *body, Expr *cond, SourceLocation DL, SourceL Expr *DoStatement::getCond() { - return reinterpret_cast(_subStmts[COND]); + return reinterpret_cast(_subStmts.at(COND)); } const Expr *DoStatement::getCond() const { - return reinterpret_cast(_subStmts[COND]); + return reinterpret_cast(_subStmts.at(COND)); } void DoStatement::setCond(Expr *e) @@ -31,7 +31,7 @@ Statement *DoStatement::getBody() const Statement *DoStatement::getBody() const { - return _subStmts[BODY]; + return _subStmts.at(BODY); } void DoStatement::setBody(Statement *s) diff --git a/src/include/Statement/DoStatement.hpp b/src/lib/src/Statement/DoStatement.h similarity index 90% rename from src/include/Statement/DoStatement.hpp rename to src/lib/src/Statement/DoStatement.h index 16c7de6..9e12d9a 100644 --- a/src/include/Statement/DoStatement.hpp +++ b/src/lib/src/Statement/DoStatement.h @@ -1,10 +1,11 @@ #ifndef DOSTATEMENT_HPP #define DOSTATEMENT_HPP -#include "Statement.hpp" -#include "Expr.hpp" -#include "SourceLocation.hpp" +#include +#include "../Statement.hpp" +#include "Expr.hpp" +#include "../SourceLocation.hpp" class DoStatement : public Statement { diff --git a/src/lib/src/Statement/Expr.cpp b/src/lib/src/Statement/Expr.cpp new file mode 100644 index 0000000..5e1c180 --- /dev/null +++ b/src/lib/src/Statement/Expr.cpp @@ -0,0 +1 @@ +#include "Expr.hpp" \ No newline at end of file diff --git a/src/lib/src/Statement/Expr.hpp b/src/lib/src/Statement/Expr.hpp new file mode 100644 index 0000000..5ba1a3f --- /dev/null +++ b/src/lib/src/Statement/Expr.hpp @@ -0,0 +1,11 @@ +#ifndef EXPRSTATEMENT_HPP +#define EXPRSTATEMENT_HPP + +#include "../Statement.hpp" + +class Expr : public Statement +{ + +}; + +#endif \ No newline at end of file diff --git a/src/lib/src/Statement/FloatLiteralExpr.cpp b/src/lib/src/Statement/FloatLiteralExpr.cpp new file mode 100644 index 0000000..e768e01 --- /dev/null +++ b/src/lib/src/Statement/FloatLiteralExpr.cpp @@ -0,0 +1,16 @@ +#include "FloatLiteralExpr.h" + +FloatLiteralExpr::FloatLiteralExpr(float value, SourceLocation l): NumberLiteralExpr(l), + _value(value) +{ +} + +float FloatLiteralExpr::getValue() const +{ + return _value; +} + +void FloatLiteralExpr::setValue(float v) +{ + _value = v; +} \ No newline at end of file diff --git a/src/lib/src/Statement/FloatLiteralExpr.h b/src/lib/src/Statement/FloatLiteralExpr.h new file mode 100644 index 0000000..8c0e5ea --- /dev/null +++ b/src/lib/src/Statement/FloatLiteralExpr.h @@ -0,0 +1,19 @@ +#ifndef BLANG_FLOATLITERALEXPR_H +#define BLANG_FLOATLITERALEXPR_H + +#include "NumberLiteralExpr.h" + +class FloatLiteralExpr: public NumberLiteralExpr +{ +public: + FloatLiteralExpr(float value, SourceLocation); + + float getValue() const; + void setValue(float); + +private: + float _value; +}; + + +#endif //BLANG_FLOATLITERALEXPR_H diff --git a/src/lib/Statement/ForStatement.cpp b/src/lib/src/Statement/ForStatement.cpp similarity index 70% rename from src/lib/Statement/ForStatement.cpp rename to src/lib/src/Statement/ForStatement.cpp index bd2e18a..3385442 100644 --- a/src/lib/Statement/ForStatement.cpp +++ b/src/lib/src/Statement/ForStatement.cpp @@ -1,5 +1,5 @@ -#include -#include "Statement/ForStatement.hpp" +#include "Expr.hpp" +#include "ForStatement.h" ForStatement::ForStatement(SourceLocation forLocation, AssignStatement *init, Expr *cond, Statement *body, Expr *inc): @@ -15,12 +15,12 @@ ForStatement::ForStatement(SourceLocation forLocation, AssignStatement *init, Ex AssignStatement *ForStatement::getInit() { - return reinterpret_cast(_subStmts[INIT]); + return reinterpret_cast(_subStmts.at(INIT)); } const AssignStatement *ForStatement::getInit() const { - return reinterpret_cast(_subStmts[INIT]); + return reinterpret_cast(_subStmts.at(INIT)); } void ForStatement::setInit(AssignStatement *init) @@ -30,12 +30,12 @@ void ForStatement::setInit(AssignStatement *init) Expr *ForStatement::getCond() { - return reinterpret_cast(_subStmts[COND]); + return reinterpret_cast(_subStmts.at(COND)); } const Expr *ForStatement::getCond() const { - return reinterpret_cast(_subStmts[COND]); + return reinterpret_cast(_subStmts.at(COND)); } void ForStatement::setCond(Expr *cond) @@ -45,12 +45,12 @@ void ForStatement::setCond(Expr *cond) Expr *ForStatement::getInc() { - return reinterpret_cast(_subStmts[INC]); + return reinterpret_cast(_subStmts.at(INC)); } const Expr *ForStatement::getInc() const { - return reinterpret_cast(_subStmts[INC]); + return reinterpret_cast(_subStmts.at(INC)); } void ForStatement::setInc(Expr *inc) @@ -60,12 +60,12 @@ void ForStatement::setInc(Expr *inc) Statement *ForStatement::getBody() { - return _subStmts[BODY]; + return _subStmts.at(BODY); } const Statement *ForStatement::getBody() const { - return _subStmts[BODY]; + return _subStmts.at(BODY); } void ForStatement::setBody(Statement *body) diff --git a/src/include/Statement/ForStatement.hpp b/src/lib/src/Statement/ForStatement.h similarity index 88% rename from src/include/Statement/ForStatement.hpp rename to src/lib/src/Statement/ForStatement.h index a0fdfc5..387d780 100644 --- a/src/include/Statement/ForStatement.hpp +++ b/src/lib/src/Statement/ForStatement.h @@ -1,9 +1,11 @@ #ifndef FORSTATEMENT_HPP #define FORSTATEMENT_HPP -#include "Statement.hpp" -#include "SourceLocation.hpp" -#include "AssignStatement.hpp" +#include + +#include "../Statement.hpp" +#include "../SourceLocation.hpp" +#include "AssignStatement.h" class ForStatement : public Statement diff --git a/src/lib/Statement/GotoStatement.cpp b/src/lib/src/Statement/GotoStatement.cpp similarity index 78% rename from src/lib/Statement/GotoStatement.cpp rename to src/lib/src/Statement/GotoStatement.cpp index 1acaaf6..a952b8b 100644 --- a/src/lib/Statement/GotoStatement.cpp +++ b/src/lib/src/Statement/GotoStatement.cpp @@ -1,4 +1,4 @@ -#include "Statement/GotoStatement.hpp" +#include "GotoStatement.h" GotoStatement::GotoStatement(LabelDecl* label, SourceLocation gl, SourceLocation ll): _label(label), @@ -34,12 +34,13 @@ void GotoStatement::setGotoLocation(SourceLocation loc) SourceLocation GotoStatement::getLabelLocation() const { - if (_Label) - return _Label->getLabelLocation(); + if (_label) + return _label->getLabelLocation(); + return SourceLocation(); } void GotoStatement::setLabelLocation(SourceLocation loc) { - if (_Label) - return _Label->setLabelLocation(loc); + if (_label) + _label->setLabelLocation(loc); } \ No newline at end of file diff --git a/src/include/Statement/GotoStatement.hpp b/src/lib/src/Statement/GotoStatement.h similarity index 75% rename from src/include/Statement/GotoStatement.hpp rename to src/lib/src/Statement/GotoStatement.h index 2b3e744..d64a54e 100644 --- a/src/include/Statement/GotoStatement.hpp +++ b/src/lib/src/Statement/GotoStatement.h @@ -1,9 +1,9 @@ #ifndef GOTOSTATEMENT_HPP #define GOTOSTATEMENT_HPP -#include "Statement.hpp" -#include "LabelStatement.hpp" -#include "SourceLocation.hpp" +#include "../Statement.hpp" +#include "LabelStatement.h" +#include "../SourceLocation.hpp" class GotoStatement : public Statement @@ -11,9 +11,9 @@ class GotoStatement : public Statement public: GotoStatement(LabelDecl* label, SourceLocation gl, SourceLocation ll); - LabelDecl *getLabel(); + /*LabelDecl *getLabel(); const LabelDecl *getLabel() const; - void setLabel(LabelDecl *); + void setLabel(LabelDecl *);*/ SourceLocation getGotoLocation() const; void setGotoLocation(SourceLocation); diff --git a/src/lib/Statement/IfStatement.cpp b/src/lib/src/Statement/IfStatement.cpp similarity index 71% rename from src/lib/Statement/IfStatement.cpp rename to src/lib/src/Statement/IfStatement.cpp index 238031d..bea80c5 100644 --- a/src/lib/Statement/IfStatement.cpp +++ b/src/lib/src/Statement/IfStatement.cpp @@ -1,6 +1,6 @@ -#include "Statement/IfStatement.hpp" +#include "IfStatement.h" -IfStatement::IfStatement(SourceLocation IfLocation, Expr* cond, Statement* then, SourceLocation ElseLocation = SourceLocation(), Statement* elses = NULL): +IfStatement::IfStatement(SourceLocation IfLocation, Expr* cond, Statement* then, SourceLocation ElseLocation, Statement* elses): _IfLoc(IfLocation), _ElseLoc(ElseLocation) { @@ -14,12 +14,12 @@ IfStatement::IfStatement(SourceLocation IfLocation, Expr* cond, Statement* then, Expr* IfStatement::getCond() { - return reinterpret_cast(_subStmts[COND]); + return reinterpret_cast(_subStmts.at(COND)); } const Expr *IfStatement::getCond() const { - return reinterpret_cast(_subStmts[COND]); + return reinterpret_cast(_subStmts.at(COND)); } void IfStatement::setCond(Expr *e) @@ -29,13 +29,12 @@ void IfStatement::setCond(Expr *e) Statement *IfStatement::getThen() { - return _subStmts[THEN]; + return _subStmts.at(THEN); } const Statement *IfStatement::getThen() const { - SourceLocation getThenLocation() const; - void setThenLocation(SourceLocation); + return _subStmts.at(THEN); } void IfStatement::setThen(Statement *s) @@ -45,12 +44,12 @@ void IfStatement::setThen(Statement *s) Statement *IfStatement::getElse() { - return _subStmts[ELSE]; + return _subStmts.at(ELSE); } const Statement *IfStatement::getElse() const { - return _subStmts[ELSE]; + return _subStmts.at(ELSE); } void IfStatement::setElse(Statement *s) diff --git a/src/include/Statement/IfStatement.hpp b/src/lib/src/Statement/IfStatement.h similarity index 78% rename from src/include/Statement/IfStatement.hpp rename to src/lib/src/Statement/IfStatement.h index 99537a1..b13ab32 100644 --- a/src/include/Statement/IfStatement.hpp +++ b/src/lib/src/Statement/IfStatement.h @@ -3,19 +3,19 @@ #include -#include "Statement.hpp" +#include "../Statement.hpp" #include "Expr.hpp" -#include "SourceLocation.hpp" +#include "../SourceLocation.hpp" class IfStatement : public Statement { public: - IfStatement(SourceLocation IfLocation, Expr* cond, Statement* then, SourceLocation EL = SourceLocation(), Statement* elses); + IfStatement(SourceLocation IfLocation, Expr* cond, Statement* then, SourceLocation EL = SourceLocation(), Statement* elses = NULL); - ExprStatement* getCond(); - const ExprStatement *getCond() const; - void setCond(ExprStatement *); + Expr* getCond(); + const Expr *getCond() const; + void setCond(Expr *); Statement *getThen(); const Statement *getThen() const; diff --git a/src/lib/src/Statement/IntegerLiteralExpr.cpp b/src/lib/src/Statement/IntegerLiteralExpr.cpp new file mode 100644 index 0000000..3efd06c --- /dev/null +++ b/src/lib/src/Statement/IntegerLiteralExpr.cpp @@ -0,0 +1,16 @@ +#include "IntegerLiteralExpr.h" + +IntegerLiteralExpr::IntegerLiteralExpr(int value, SourceLocation l): NumberLiteralExpr(l), + _value(value) +{ +} + +int IntegerLiteralExpr::getValue() const +{ + return _value; +} + +void IntegerLiteralExpr::setValue(int v) +{ + _value = v; +} \ No newline at end of file diff --git a/src/lib/src/Statement/IntegerLiteralExpr.h b/src/lib/src/Statement/IntegerLiteralExpr.h new file mode 100644 index 0000000..ac12468 --- /dev/null +++ b/src/lib/src/Statement/IntegerLiteralExpr.h @@ -0,0 +1,19 @@ +#ifndef BLANG_INTEGERLITERALEXPR_H +#define BLANG_INTEGERLITERALEXPR_H + +#include "NumberLiteralExpr.h" + +class IntegerLiteralExpr: public NumberLiteralExpr +{ +public: + IntegerLiteralExpr(int value, SourceLocation); + + int getValue() const; + void setValue(int); + +private: + int _value; +}; + + +#endif //BLANG_INTEGERLITERALEXPR_H diff --git a/src/lib/Statement/LabelStatement.cpp b/src/lib/src/Statement/LabelStatement.cpp similarity index 87% rename from src/lib/Statement/LabelStatement.cpp rename to src/lib/src/Statement/LabelStatement.cpp index ccaff82..623f32b 100644 --- a/src/lib/Statement/LabelStatement.cpp +++ b/src/lib/src/Statement/LabelStatement.cpp @@ -1,4 +1,4 @@ -#include "Statement/LabelStatement.hpp" +#include "LabelStatement.h" LabelStatement::LabelStatement(SourceLocation ll, LabelDecl* decl): _decl(decl), diff --git a/src/include/Statement/LabelStatement.hpp b/src/lib/src/Statement/LabelStatement.h similarity index 84% rename from src/include/Statement/LabelStatement.hpp rename to src/lib/src/Statement/LabelStatement.h index e1e1d8c..6fce90e 100644 --- a/src/include/Statement/LabelStatement.hpp +++ b/src/lib/src/Statement/LabelStatement.h @@ -1,9 +1,9 @@ #ifndef LABELSTATEMENT_HPP #define LABELSTATEMENT_HPP -#include "Statement.hpp" +#include "../Statement.hpp" #include "Expr.hpp" -#include "SourceLocation.hpp" +#include "../SourceLocation.hpp" class LabelStatement : public Statement diff --git a/src/lib/src/Statement/NumberLiteralExpr.cpp b/src/lib/src/Statement/NumberLiteralExpr.cpp new file mode 100644 index 0000000..ef86631 --- /dev/null +++ b/src/lib/src/Statement/NumberLiteralExpr.cpp @@ -0,0 +1,13 @@ +#include "NumberLiteralExpr.h" + +NumberLiteralExpr::NumberLiteralExpr(SourceLocation l): + _l(l) +{ + +} + +SourceLocation NumberLiteralExpr::getLocation() const +{ + return _l; +} + diff --git a/src/lib/src/Statement/NumberLiteralExpr.h b/src/lib/src/Statement/NumberLiteralExpr.h new file mode 100644 index 0000000..a316ab7 --- /dev/null +++ b/src/lib/src/Statement/NumberLiteralExpr.h @@ -0,0 +1,17 @@ +#ifndef BLANG_NUMBERLITERALEXPR_H +#define BLANG_NUMBERLITERALEXPR_H + +#include "Expr.hpp" + +class NumberLiteralExpr: public Expr +{ +public: + NumberLiteralExpr(SourceLocation l); + SourceLocation getLocation() const; + +protected: + SourceLocation _l; +}; + + +#endif //BLANG_NUMBERLITERALEXPR_H diff --git a/src/include/Statement/OperationKinds.def b/src/lib/src/Statement/OperationKinds.def similarity index 98% rename from src/include/Statement/OperationKinds.def rename to src/lib/src/Statement/OperationKinds.def index cfc0dfd..1ef80ce 100644 --- a/src/include/Statement/OperationKinds.def +++ b/src/lib/src/Statement/OperationKinds.def @@ -35,5 +35,4 @@ BINARY_OPERATION(GE, ">=") BINARY_OPERATION(EQ, "=") BINARY_OPERATION(NE, "!=") -#undef CAST_OPERATION #undef BINARY_OPERATION diff --git a/src/lib/src/Statement/ReturnStatement.cpp b/src/lib/src/Statement/ReturnStatement.cpp new file mode 100644 index 0000000..5e2876d --- /dev/null +++ b/src/lib/src/Statement/ReturnStatement.cpp @@ -0,0 +1,16 @@ +#include "ReturnStatement.h" + +ReturnStatement::ReturnStatement(SourceLocation l): + _returnLocation(l) +{ +} + +SourceLocation ReturnStatement::getReturnLocation() const +{ + return _returnLocation; +} + +void ReturnStatement::setReturnLocation(SourceLocation l) +{ + _returnLocation = l; +} \ No newline at end of file diff --git a/src/lib/src/Statement/ReturnStatement.h b/src/lib/src/Statement/ReturnStatement.h new file mode 100644 index 0000000..38007bb --- /dev/null +++ b/src/lib/src/Statement/ReturnStatement.h @@ -0,0 +1,21 @@ +#ifndef RETURNSTATEMENT_HPP +#define RETURNSTATEMENT_HPP + +#include "../Statement.hpp" +#include "../SourceLocation.hpp" + + +class ReturnStatement : public Statement +{ +public: + ReturnStatement(SourceLocation l); + + SourceLocation getReturnLocation() const; + void setReturnLocation(SourceLocation); + +private: + SourceLocation _returnLocation; + +}; + +#endif \ No newline at end of file diff --git a/src/lib/src/Statement/StopStatement.cpp b/src/lib/src/Statement/StopStatement.cpp new file mode 100644 index 0000000..a8f3c4f --- /dev/null +++ b/src/lib/src/Statement/StopStatement.cpp @@ -0,0 +1 @@ +#include "StopStatement.h" diff --git a/src/lib/src/Statement/StopStatement.h b/src/lib/src/Statement/StopStatement.h new file mode 100644 index 0000000..1930629 --- /dev/null +++ b/src/lib/src/Statement/StopStatement.h @@ -0,0 +1,11 @@ +#ifndef BLANG_STOPSTATEMENT_H +#define BLANG_STOPSTATEMENT_H + + +class StopStatement +{ + +}; + + +#endif //BLANG_STOPSTATEMENT_H diff --git a/src/lib/src/Statement/StringLiteralExpr.cpp b/src/lib/src/Statement/StringLiteralExpr.cpp new file mode 100644 index 0000000..2f1a9db --- /dev/null +++ b/src/lib/src/Statement/StringLiteralExpr.cpp @@ -0,0 +1 @@ +#include "StringLiteralExpr.h" diff --git a/src/include/Statement/StringLiteralExpr.h b/src/lib/src/Statement/StringLiteralExpr.h similarity index 88% rename from src/include/Statement/StringLiteralExpr.h rename to src/lib/src/Statement/StringLiteralExpr.h index c307110..f09a3b4 100644 --- a/src/include/Statement/StringLiteralExpr.h +++ b/src/lib/src/Statement/StringLiteralExpr.h @@ -1,8 +1,9 @@ #ifndef BLANG_STRINGLITERALEXPR_H #define BLANG_STRINGLITERALEXPR_H +#include "Expr.hpp" -class StringLiteralExpr +class StringLiteralExpr: public Expr { public: StringLiteralExpr(std::string str, SourceLocation loc); diff --git a/src/lib/src/Statement/WhileStatement.cpp b/src/lib/src/Statement/WhileStatement.cpp new file mode 100644 index 0000000..1dcf014 --- /dev/null +++ b/src/lib/src/Statement/WhileStatement.cpp @@ -0,0 +1,48 @@ +#include "WhileStatement.h" + +WhileStatement::WhileStatement(Expr *cond, Statement *body, SourceLocation wl): + _whileLoc(wl) +{ + _subStmts[COND] = cond; + _subStmts[BODY] = body; +} + +Expr *WhileStatement::getCond() +{ + return reinterpret_cast(_subStmts.at(COND)); +} + +const Expr *WhileStatement::getCond() const +{ + return reinterpret_cast(_subStmts.at(COND)); +} + +void WhileStatement::setCond(Expr *e) +{ + _subStmts[COND] = reinterpret_cast(e); +} + +Statement *WhileStatement::getBody() +{ + return _subStmts.at(BODY); +} + +const Statement *WhileStatement::getBody() const +{ + return _subStmts.at(BODY); +} + +void WhileStatement::setBody(Statement *s) +{ + _subStmts[BODY] = s; +} + +SourceLocation WhileStatement::getWhileLocation() const +{ + return _whileLoc; +} + +void WhileStatement::setWhileLocation(SourceLocation loc) +{ + _whileLoc = loc; +} \ No newline at end of file diff --git a/src/lib/src/Statement/WhileStatement.h b/src/lib/src/Statement/WhileStatement.h new file mode 100644 index 0000000..c46868f --- /dev/null +++ b/src/lib/src/Statement/WhileStatement.h @@ -0,0 +1,36 @@ +#ifndef WHILESTATEMENT_HPP +#define WHILESTATEMENT_HPP + +#include + +#include "../Statement.hpp" +#include "Expr.hpp" +#include "../SourceLocation.hpp" + +class WhileStatement : public Statement +{ + +public: + WhileStatement(Expr* cond, Statement* body, SourceLocation wl); + + Expr *getCond(); + const Expr *getCond() const; + void setCond(Expr *); + + Statement *getBody(); + const Statement *getBody() const; + void setBody(Statement *); + + SourceLocation getWhileLocation() const; + void setWhileLocation(SourceLocation); + +private: + SourceLocation _whileLoc; + enum StmtIdentifier + { + COND, BODY + }; + std::map _subStmts; +}; + +#endif \ No newline at end of file diff --git a/src/lib/src/Statements b/src/lib/src/Statements new file mode 100644 index 0000000..622b46b --- /dev/null +++ b/src/lib/src/Statements @@ -0,0 +1,20 @@ +#ifndef STATEMENTS +#define STATEMENTS + +#include "Statement/AssignStatement.h" +#include "Statement/BinaryOperatorExpr.h" +#include "Statement/BreakStatement.h" +#include "Statement/CallExpr.h" +#include "Statement/CompoundStatement.h" +#include "Statement/DoStatement.h" +#include "Statement/ForStatement.h" +#include "Statement/GotoStatement.h" +#include "Statement/IfStatement.h" +#include "Statement/LabelStatement.h" +#include "Statement/NumberLiteralExpr.h" +#include "Statement/ReturnStatement.h" +#include "Statement/StopStatement.h" +#include "Statement/StringLiteralExpr.h" +#include "Statement/WhileStatement.h" + +#endif \ No newline at end of file diff --git a/src/lib/Token.cpp b/src/lib/src/Token.cpp similarity index 100% rename from src/lib/Token.cpp rename to src/lib/src/Token.cpp diff --git a/src/include/Token.hpp b/src/lib/src/Token.hpp similarity index 100% rename from src/include/Token.hpp rename to src/lib/src/Token.hpp diff --git a/src/lib/TokenList.cpp b/src/lib/src/TokenList.cpp similarity index 100% rename from src/lib/TokenList.cpp rename to src/lib/src/TokenList.cpp diff --git a/src/include/TokenList.hpp b/src/lib/src/TokenList.hpp similarity index 100% rename from src/include/TokenList.hpp rename to src/lib/src/TokenList.hpp diff --git a/src/lib/TranslationUnit.cpp b/src/lib/src/TranslationUnit.cpp similarity index 100% rename from src/lib/TranslationUnit.cpp rename to src/lib/src/TranslationUnit.cpp diff --git a/src/include/TranslationUnit.hpp b/src/lib/src/TranslationUnit.hpp similarity index 100% rename from src/include/TranslationUnit.hpp rename to src/lib/src/TranslationUnit.hpp diff --git a/src/lib/src/lexer.l b/src/lib/src/lexer.l new file mode 100644 index 0000000..b33f611 --- /dev/null +++ b/src/lib/src/lexer.l @@ -0,0 +1,49 @@ +%{ +#include +#include + +#include "Token.hpp" +#include "parser_gen.h" + +using namespace std; + +%} + +%option noyywrap + +integer [0-9]+ +real [0-9]+\.[0-9]*|\.[0-9]+ +operator "+"|"-"|"/"|"*"|">"|"<"|"<="|">="|"="|"!=" +ident [a-zA-Z_][0-9a-zA-Z_]* +string \"[^\n"]+\" +%% + +{integer} { return(INTEGER); } +{real} { return(FLOAT); } +{string} { return(STRING); } +{operator} { return(DO) } +"->" { return(ASSIGN); } +"=>" { return(IMPLIES); } +"Do" { return(DO); } +"LpWhile" { return(LPWHILE); } +"While" { return(WHILE); } +"WhileEnd" { return(WHILEEND); } +"If" { return(IF); } +"Then" { return(THEN); } +"Else" { return(ELSE); } +"IfEnd" { return(IFEND); } +"For" { return(FOR); } +"To" { return(TO); } +"Step" { return(STEP); } +"Next" { return(NEXT); } +"Goto" { return(GOTO); } +"Lbl" { return(LABEL); } +"Break" { return(BREAK); } +"Return" { return(RETURN); } +"Stop" { return(STOP); } +{ident} { return(IDENTIFIER); } +"\n" { return(EOL); } +[ \t]+ +. { cerr << "Invalid character: " << yytext << endl; } + +%% diff --git a/src/lib/src/lexer_gen.cpp b/src/lib/src/lexer_gen.cpp new file mode 100644 index 0000000..7dd9c3c --- /dev/null +++ b/src/lib/src/lexer_gen.cpp @@ -0,0 +1,1949 @@ +#line 2 "lib/lexer_gen.cpp" + +#line 4 "lib/lexer_gen.cpp" + +#define YY_INT_ALIGNED short int + +/* A lexical scanner generated by flex */ + +#define FLEX_SCANNER +#define YY_FLEX_MAJOR_VERSION 2 +#define YY_FLEX_MINOR_VERSION 6 +#define YY_FLEX_SUBMINOR_VERSION 1 +#if YY_FLEX_SUBMINOR_VERSION > 0 +#define FLEX_BETA +#endif + +/* First, we deal with platform-specific or compiler-specific issues. */ + +/* begin standard C headers. */ +#include +#include +#include +#include + +/* end standard C headers. */ + +/* flex integer type definitions */ + +#ifndef FLEXINT_H +#define FLEXINT_H + +/* C99 systems have . Non-C99 systems may or may not. */ + +#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L + +/* C99 says to define __STDC_LIMIT_MACROS before including stdint.h, + * if you want the limit (max/min) macros for int types. + */ +#ifndef __STDC_LIMIT_MACROS +#define __STDC_LIMIT_MACROS 1 +#endif + +#include +typedef int8_t flex_int8_t; +typedef uint8_t flex_uint8_t; +typedef int16_t flex_int16_t; +typedef uint16_t flex_uint16_t; +typedef int32_t flex_int32_t; +typedef uint32_t flex_uint32_t; +#else +typedef signed char flex_int8_t; +typedef short int flex_int16_t; +typedef int flex_int32_t; +typedef unsigned char flex_uint8_t; +typedef unsigned short int flex_uint16_t; +typedef unsigned int flex_uint32_t; + +/* Limits of integral types. */ +#ifndef INT8_MIN +#define INT8_MIN (-128) +#endif +#ifndef INT16_MIN +#define INT16_MIN (-32767-1) +#endif +#ifndef INT32_MIN +#define INT32_MIN (-2147483647-1) +#endif +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif +#ifndef UINT8_MAX +#define UINT8_MAX (255U) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535U) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif + +#endif /* ! C99 */ + +#endif /* ! FLEXINT_H */ + +/* TODO: this is always defined, so inline it */ +#define yyconst const + +#if defined(__GNUC__) && __GNUC__ >= 3 +#define yynoreturn __attribute__((__noreturn__)) +#else +#define yynoreturn +#endif + +/* Returned upon end-of-file. */ +#define YY_NULL 0 + +/* Promotes a possibly negative, possibly signed char to an unsigned + * integer for use as an array index. If the signed char is negative, + * we want to instead treat it as an 8-bit unsigned char, hence the + * double cast. + */ +#define YY_SC_TO_UI(c) ((unsigned int) (unsigned char) c) + +/* Enter a start condition. This macro really ought to take a parameter, + * but we do it the disgusting crufty way forced on us by the ()-less + * definition of BEGIN. + */ +#define BEGIN (yy_start) = 1 + 2 * + +/* Translate the current start state into a value that can be later handed + * to BEGIN to return to the state. The YYSTATE alias is for lex + * compatibility. + */ +#define YY_START (((yy_start) - 1) / 2) +#define YYSTATE YY_START + +/* Action number for EOF rule of a given start state. */ +#define YY_STATE_EOF(state) (YY_END_OF_BUFFER + state + 1) + +/* Special action meaning "start processing a new file". */ +#define YY_NEW_FILE yyrestart(yyin ) + +#define YY_END_OF_BUFFER_CHAR 0 + +/* Size of default input buffer. */ +#ifndef YY_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k. + * Moreover, YY_BUF_SIZE is 2*YY_READ_BUF_SIZE in the general case. + * Ditto for the __ia64__ case accordingly. + */ +#define YY_BUF_SIZE 32768 +#else +#define YY_BUF_SIZE 16384 +#endif /* __ia64__ */ +#endif + +/* The state buf must be large enough to hold one state per character in the main buffer. + */ +#define YY_STATE_BUF_SIZE ((YY_BUF_SIZE + 2) * sizeof(yy_state_type)) + +#ifndef YY_TYPEDEF_YY_BUFFER_STATE +#define YY_TYPEDEF_YY_BUFFER_STATE +typedef struct yy_buffer_state *YY_BUFFER_STATE; +#endif + +#ifndef YY_TYPEDEF_YY_SIZE_T +#define YY_TYPEDEF_YY_SIZE_T +typedef size_t yy_size_t; +#endif + +extern int yyleng; + +extern FILE *yyin, *yyout; + +#define EOB_ACT_CONTINUE_SCAN 0 +#define EOB_ACT_END_OF_FILE 1 +#define EOB_ACT_LAST_MATCH 2 + + #define YY_LESS_LINENO(n) + #define YY_LINENO_REWIND_TO(ptr) + +/* Return all but the first "n" matched characters back to the input stream. */ +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + *yy_cp = (yy_hold_char); \ + YY_RESTORE_YY_MORE_OFFSET \ + (yy_c_buf_p) = yy_cp = yy_bp + yyless_macro_arg - YY_MORE_ADJ; \ + YY_DO_BEFORE_ACTION; /* set up yytext again */ \ + } \ + while ( 0 ) + +#define unput(c) yyunput( c, (yytext_ptr) ) + +#ifndef YY_STRUCT_YY_BUFFER_STATE +#define YY_STRUCT_YY_BUFFER_STATE +struct yy_buffer_state + { + FILE *yy_input_file; + + char *yy_ch_buf; /* input buffer */ + char *yy_buf_pos; /* current position in input buffer */ + + /* Size of input buffer in bytes, not including room for EOB + * characters. + */ + int yy_buf_size; + + /* Number of characters read into yy_ch_buf, not including EOB + * characters. + */ + int yy_n_chars; + + /* Whether we "own" the buffer - i.e., we know we created it, + * and can realloc() it to grow it, and should free() it to + * delete it. + */ + int yy_is_our_buffer; + + /* Whether this is an "interactive" input source; if so, and + * if we're using stdio for input, then we want to use getc() + * instead of fread(), to make sure we stop fetching input after + * each newline. + */ + int yy_is_interactive; + + /* Whether we're considered to be at the beginning of a line. + * If so, '^' rules will be active on the next match, otherwise + * not. + */ + int yy_at_bol; + + int yy_bs_lineno; /**< The line count. */ + int yy_bs_column; /**< The column count. */ + + /* Whether to try to fill the input buffer when we reach the + * end of it. + */ + int yy_fill_buffer; + + int yy_buffer_status; + +#define YY_BUFFER_NEW 0 +#define YY_BUFFER_NORMAL 1 + /* When an EOF's been seen but there's still some text to process + * then we mark the buffer as YY_EOF_PENDING, to indicate that we + * shouldn't try reading from the input source any more. We might + * still have a bunch of tokens to match, though, because of + * possible backing-up. + * + * When we actually see the EOF, we change the status to "new" + * (via yyrestart()), so that the user can continue scanning by + * just pointing yyin at a new input file. + */ +#define YY_BUFFER_EOF_PENDING 2 + + }; +#endif /* !YY_STRUCT_YY_BUFFER_STATE */ + +/* Stack of input buffers. */ +static size_t yy_buffer_stack_top = 0; /**< index of top of stack. */ +static size_t yy_buffer_stack_max = 0; /**< capacity of stack. */ +static YY_BUFFER_STATE * yy_buffer_stack = NULL; /**< Stack as an array. */ + +/* We provide macros for accessing buffer states in case in the + * future we want to put the buffer states in a more general + * "scanner state". + * + * Returns the top of the stack, or NULL. + */ +#define YY_CURRENT_BUFFER ( (yy_buffer_stack) \ + ? (yy_buffer_stack)[(yy_buffer_stack_top)] \ + : NULL) + +/* Same as previous macro, but useful when we know that the buffer stack is not + * NULL or when we need an lvalue. For internal use only. + */ +#define YY_CURRENT_BUFFER_LVALUE (yy_buffer_stack)[(yy_buffer_stack_top)] + +/* yy_hold_char holds the character lost when yytext is formed. */ +static char yy_hold_char; +static int yy_n_chars; /* number of characters read into yy_ch_buf */ +int yyleng; + +/* Points to current character in buffer. */ +static char *yy_c_buf_p = NULL; +static int yy_init = 0; /* whether we need to initialize */ +static int yy_start = 0; /* start state number */ + +/* Flag which is used to allow yywrap()'s to do buffer switches + * instead of setting up a fresh yyin. A bit of a hack ... + */ +static int yy_did_buffer_switch_on_eof; + +void yyrestart (FILE *input_file ); +void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ); +YY_BUFFER_STATE yy_create_buffer (FILE *file,int size ); +void yy_delete_buffer (YY_BUFFER_STATE b ); +void yy_flush_buffer (YY_BUFFER_STATE b ); +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ); +void yypop_buffer_state (void ); + +static void yyensure_buffer_stack (void ); +static void yy_load_buffer_state (void ); +static void yy_init_buffer (YY_BUFFER_STATE b,FILE *file ); + +#define YY_FLUSH_BUFFER yy_flush_buffer(YY_CURRENT_BUFFER ) + +YY_BUFFER_STATE yy_scan_buffer (char *base,yy_size_t size ); +YY_BUFFER_STATE yy_scan_string (yyconst char *yy_str ); +YY_BUFFER_STATE yy_scan_bytes (yyconst char *bytes,int len ); + +void *yyalloc (yy_size_t ); +void *yyrealloc (void *,yy_size_t ); +void yyfree (void * ); + +#define yy_new_buffer yy_create_buffer + +#define yy_set_interactive(is_interactive) \ + { \ + if ( ! YY_CURRENT_BUFFER ){ \ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_is_interactive = is_interactive; \ + } + +#define yy_set_bol(at_bol) \ + { \ + if ( ! YY_CURRENT_BUFFER ){\ + yyensure_buffer_stack (); \ + YY_CURRENT_BUFFER_LVALUE = \ + yy_create_buffer(yyin,YY_BUF_SIZE ); \ + } \ + YY_CURRENT_BUFFER_LVALUE->yy_at_bol = at_bol; \ + } + +#define YY_AT_BOL() (YY_CURRENT_BUFFER_LVALUE->yy_at_bol) + +/* Begin user sect3 */ + +#define yywrap() (/*CONSTCOND*/1) +#define YY_SKIP_YYWRAP + +typedef unsigned char YY_CHAR; + +FILE *yyin = NULL, *yyout = NULL; + +typedef int yy_state_type; + +extern int yylineno; + +int yylineno = 1; + +extern char *yytext; +#ifdef yytext_ptr +#undef yytext_ptr +#endif +#define yytext_ptr yytext + +static yy_state_type yy_get_previous_state (void ); +static yy_state_type yy_try_NUL_trans (yy_state_type current_state ); +static int yy_get_next_buffer (void ); +static void yynoreturn yy_fatal_error (yyconst char* msg ); + +/* Done after the current pattern has been matched and before the + * corresponding action - sets up yytext. + */ +#define YY_DO_BEFORE_ACTION \ + (yytext_ptr) = yy_bp; \ + yyleng = (int) (yy_cp - yy_bp); \ + (yy_hold_char) = *yy_cp; \ + *yy_cp = '\0'; \ + (yy_c_buf_p) = yy_cp; + +#define YY_NUM_RULES 28 +#define YY_END_OF_BUFFER 29 +/* This struct is not used in this scanner, + but its presence is necessary. */ +struct yy_trans_info + { + flex_int32_t yy_verify; + flex_int32_t yy_nxt; + }; +static yyconst flex_int16_t yy_accept[90] = + { 0, + 0, 0, 29, 27, 26, 25, 27, 27, 4, 4, + 27, 1, 4, 4, 4, 24, 24, 24, 24, 24, + 24, 24, 24, 24, 24, 24, 24, 24, 26, 4, + 0, 5, 2, 2, 1, 6, 24, 24, 7, 24, + 24, 24, 11, 24, 24, 24, 24, 24, 24, 16, + 24, 3, 2, 24, 24, 15, 24, 24, 20, 24, + 24, 24, 24, 24, 24, 24, 24, 13, 19, 24, + 24, 18, 24, 17, 23, 12, 24, 21, 14, 24, + 24, 9, 24, 22, 24, 8, 24, 10, 0 + } ; + +static yyconst YY_CHAR yy_ec[256] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 2, 3, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 2, 4, 5, 1, 1, 1, 1, 1, 1, + 1, 6, 7, 1, 8, 9, 10, 11, 11, 11, + 11, 11, 11, 11, 11, 11, 11, 1, 1, 12, + 13, 14, 1, 1, 15, 16, 15, 17, 18, 19, + 20, 15, 21, 15, 15, 22, 15, 23, 15, 15, + 15, 24, 25, 26, 15, 15, 27, 15, 15, 15, + 1, 1, 1, 1, 15, 1, 28, 29, 15, 30, + + 31, 32, 15, 33, 34, 15, 35, 36, 15, 37, + 38, 39, 15, 40, 41, 42, 43, 15, 15, 44, + 15, 15, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1 + } ; + +static yyconst YY_CHAR yy_meta[45] = + { 0, + 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, + 3, 1, 1, 1, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, + 3, 3, 3, 3 + } ; + +static yyconst flex_uint16_t yy_base[92] = + { 0, + 0, 0, 113, 114, 110, 114, 98, 0, 114, 96, + 98, 36, 95, 93, 93, 0, 65, 66, 67, 64, + 63, 68, 17, 68, 67, 55, 15, 63, 93, 114, + 89, 114, 82, 81, 40, 114, 0, 60, 0, 49, + 49, 46, 69, 50, 58, 40, 41, 19, 51, 0, + 47, 114, 69, 51, 47, 0, 39, 39, 0, 42, + 32, 30, 33, 32, 33, 33, 33, 0, 0, 37, + 32, 0, 25, 0, 0, 0, 33, 0, 0, 27, + 25, 43, 28, 0, 18, 0, 24, 0, 114, 57, + 49 + + } ; + +static yyconst flex_int16_t yy_def[92] = + { 0, + 89, 1, 89, 89, 89, 89, 89, 90, 89, 89, + 89, 89, 89, 89, 89, 91, 91, 91, 91, 91, + 91, 91, 91, 91, 91, 91, 91, 91, 89, 89, + 90, 89, 89, 89, 89, 89, 91, 91, 91, 91, + 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, + 91, 89, 89, 91, 91, 91, 91, 91, 91, 91, + 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, + 91, 91, 91, 91, 91, 91, 91, 91, 91, 91, + 91, 91, 91, 91, 91, 91, 91, 91, 0, 89, + 89 + + } ; + +static yyconst flex_uint16_t yy_nxt[159] = + { 0, + 4, 5, 6, 7, 8, 9, 9, 10, 11, 9, + 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, + 22, 23, 24, 25, 26, 27, 28, 16, 16, 16, + 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, + 16, 16, 16, 16, 34, 44, 35, 49, 34, 63, + 35, 37, 50, 88, 87, 45, 64, 31, 86, 31, + 85, 84, 83, 82, 81, 80, 79, 78, 77, 76, + 75, 74, 73, 72, 71, 70, 69, 68, 67, 53, + 66, 65, 62, 61, 60, 59, 58, 57, 56, 55, + 54, 53, 33, 52, 29, 51, 48, 47, 46, 43, + + 42, 41, 40, 39, 38, 30, 36, 30, 33, 32, + 30, 29, 89, 3, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89 + } ; + +static yyconst flex_int16_t yy_chk[159] = + { 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 1, 1, 1, 1, 12, 23, 12, 27, 35, 48, + 35, 91, 27, 87, 85, 23, 48, 90, 83, 90, + 82, 81, 80, 77, 73, 71, 70, 67, 66, 65, + 64, 63, 62, 61, 60, 58, 57, 55, 54, 53, + 51, 49, 47, 46, 45, 44, 43, 42, 41, 40, + 38, 34, 33, 31, 29, 28, 26, 25, 24, 22, + + 21, 20, 19, 18, 17, 15, 14, 13, 11, 10, + 7, 5, 3, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89, 89, 89, + 89, 89, 89, 89, 89, 89, 89, 89 + } ; + +static yy_state_type yy_last_accepting_state; +static char *yy_last_accepting_cpos; + +extern int yy_flex_debug; +int yy_flex_debug = 0; + +/* The intent behind this definition is that it'll catch + * any uses of REJECT which flex missed. + */ +#define REJECT reject_used_but_not_detected +#define yymore() yymore_used_but_not_detected +#define YY_MORE_ADJ 0 +#define YY_RESTORE_YY_MORE_OFFSET +char *yytext; +#line 1 "lib/lexer.l" +#line 2 "lib/lexer.l" +#include +#include + +#include "Token.hpp" +#include "parser_gen.h" + +using namespace std; + +#line 527 "lib/lexer_gen.cpp" + +#define INITIAL 0 + +#ifndef YY_NO_UNISTD_H +/* Special case for "unistd.h", since it is non-ANSI. We include it way + * down here because we want the user's section 1 to have been scanned first. + * The user has a chance to override it with an option. + */ +#include +#endif + +#ifndef YY_EXTRA_TYPE +#define YY_EXTRA_TYPE void * +#endif + +static int yy_init_globals (void ); + +/* Accessor methods to globals. + These are made visible to non-reentrant scanners for convenience. */ + +int yylex_destroy (void ); + +int yyget_debug (void ); + +void yyset_debug (int debug_flag ); + +YY_EXTRA_TYPE yyget_extra (void ); + +void yyset_extra (YY_EXTRA_TYPE user_defined ); + +FILE *yyget_in (void ); + +void yyset_in (FILE * _in_str ); + +FILE *yyget_out (void ); + +void yyset_out (FILE * _out_str ); + + int yyget_leng (void ); + +char *yyget_text (void ); + +int yyget_lineno (void ); + +void yyset_lineno (int _line_number ); + +/* Macros after this point can all be overridden by user definitions in + * section 1. + */ + +#ifndef YY_SKIP_YYWRAP +#ifdef __cplusplus +extern "C" int yywrap (void ); +#else +extern int yywrap (void ); +#endif +#endif + +#ifndef YY_NO_UNPUT + + static void yyunput (int c,char *buf_ptr ); + +#endif + +#ifndef yytext_ptr +static void yy_flex_strncpy (char *,yyconst char *,int ); +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * ); +#endif + +#ifndef YY_NO_INPUT + +#ifdef __cplusplus +static int yyinput (void ); +#else +static int input (void ); +#endif + +#endif + +/* Amount of stuff to slurp up with each read. */ +#ifndef YY_READ_BUF_SIZE +#ifdef __ia64__ +/* On IA-64, the buffer size is 16k, not 8k */ +#define YY_READ_BUF_SIZE 16384 +#else +#define YY_READ_BUF_SIZE 8192 +#endif /* __ia64__ */ +#endif + +/* Copy whatever the last rule matched to the standard output. */ +#ifndef ECHO +/* This used to be an fputs(), but since the string might contain NUL's, + * we now use fwrite(). + */ +#define ECHO do { if (fwrite( yytext, (size_t) yyleng, 1, yyout )) {} } while (0) +#endif + +/* Gets input and stuffs it into "buf". number of characters read, or YY_NULL, + * is returned in "result". + */ +#ifndef YY_INPUT +#define YY_INPUT(buf,result,max_size) \ + if ( YY_CURRENT_BUFFER_LVALUE->yy_is_interactive ) \ + { \ + int c = '*'; \ + size_t n; \ + for ( n = 0; n < max_size && \ + (c = getc( yyin )) != EOF && c != '\n'; ++n ) \ + buf[n] = (char) c; \ + if ( c == '\n' ) \ + buf[n++] = (char) c; \ + if ( c == EOF && ferror( yyin ) ) \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + result = n; \ + } \ + else \ + { \ + errno=0; \ + while ( (result = (int) fread(buf, 1, max_size, yyin))==0 && ferror(yyin)) \ + { \ + if( errno != EINTR) \ + { \ + YY_FATAL_ERROR( "input in flex scanner failed" ); \ + break; \ + } \ + errno=0; \ + clearerr(yyin); \ + } \ + }\ +\ + +#endif + +/* No semi-colon after return; correct usage is to write "yyterminate();" - + * we don't want an extra ';' after the "return" because that will cause + * some compilers to complain about unreachable statements. + */ +#ifndef yyterminate +#define yyterminate() return YY_NULL +#endif + +/* Number of entries by which start-condition stack grows. */ +#ifndef YY_START_STACK_INCR +#define YY_START_STACK_INCR 25 +#endif + +/* Report a fatal error. */ +#ifndef YY_FATAL_ERROR +#define YY_FATAL_ERROR(msg) yy_fatal_error( msg ) +#endif + +/* end tables serialization structures and prototypes */ + +/* Default declaration of generated scanner - a define so the user can + * easily add parameters. + */ +#ifndef YY_DECL +#define YY_DECL_IS_OURS 1 + +extern int yylex (void); + +#define YY_DECL int yylex (void) +#endif /* !YY_DECL */ + +/* Code executed at the beginning of each rule, after yytext and yyleng + * have been set up. + */ +#ifndef YY_USER_ACTION +#define YY_USER_ACTION +#endif + +/* Code executed at the end of each rule. */ +#ifndef YY_BREAK +#define YY_BREAK /*LINTED*/break; +#endif + +#define YY_RULE_SETUP \ + YY_USER_ACTION + +/** The main scanner function which does all the work. + */ +YY_DECL +{ + yy_state_type yy_current_state; + char *yy_cp, *yy_bp; + int yy_act; + + if ( !(yy_init) ) + { + (yy_init) = 1; + +#ifdef YY_USER_INIT + YY_USER_INIT; +#endif + + if ( ! (yy_start) ) + (yy_start) = 1; /* first start state */ + + if ( ! yyin ) + yyin = stdin; + + if ( ! yyout ) + yyout = stdout; + + if ( ! YY_CURRENT_BUFFER ) { + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_load_buffer_state( ); + } + + { +#line 19 "lib/lexer.l" + + +#line 748 "lib/lexer_gen.cpp" + + while ( /*CONSTCOND*/1 ) /* loops until end-of-file is reached */ + { + yy_cp = (yy_c_buf_p); + + /* Support of yytext. */ + *yy_cp = (yy_hold_char); + + /* yy_bp points to the position in yy_ch_buf of the start of + * the current run. + */ + yy_bp = yy_cp; + + yy_current_state = (yy_start); +yy_match: + do + { + YY_CHAR yy_c = yy_ec[YY_SC_TO_UI(*yy_cp)] ; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 90 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; + ++yy_cp; + } + while ( yy_base[yy_current_state] != 114 ); + +yy_find_action: + yy_act = yy_accept[yy_current_state]; + if ( yy_act == 0 ) + { /* have to back up */ + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + yy_act = yy_accept[yy_current_state]; + } + + YY_DO_BEFORE_ACTION; + +do_action: /* This label is used only to access EOF actions. */ + + switch ( yy_act ) + { /* beginning of action switch */ + case 0: /* must back up */ + /* undo the effects of YY_DO_BEFORE_ACTION */ + *yy_cp = (yy_hold_char); + yy_cp = (yy_last_accepting_cpos); + yy_current_state = (yy_last_accepting_state); + goto yy_find_action; + +case 1: +YY_RULE_SETUP +#line 21 "lib/lexer.l" +{ return(INTEGER); } + YY_BREAK +case 2: +YY_RULE_SETUP +#line 22 "lib/lexer.l" +{ return(FLOAT); } + YY_BREAK +case 3: +YY_RULE_SETUP +#line 23 "lib/lexer.l" +{ return(STRING); } + YY_BREAK +case 4: +YY_RULE_SETUP +#line 24 "lib/lexer.l" +{ return(DO) } + YY_BREAK +case 5: +YY_RULE_SETUP +#line 25 "lib/lexer.l" +{ return(ASSIGN); } + YY_BREAK +case 6: +YY_RULE_SETUP +#line 26 "lib/lexer.l" +{ return(IMPLIES); } + YY_BREAK +case 7: +YY_RULE_SETUP +#line 27 "lib/lexer.l" +{ return(DO); } + YY_BREAK +case 8: +YY_RULE_SETUP +#line 28 "lib/lexer.l" +{ return(LPWHILE); } + YY_BREAK +case 9: +YY_RULE_SETUP +#line 29 "lib/lexer.l" +{ return(WHILE); } + YY_BREAK +case 10: +YY_RULE_SETUP +#line 30 "lib/lexer.l" +{ return(WHILEEND); } + YY_BREAK +case 11: +YY_RULE_SETUP +#line 31 "lib/lexer.l" +{ return(IF); } + YY_BREAK +case 12: +YY_RULE_SETUP +#line 32 "lib/lexer.l" +{ return(THEN); } + YY_BREAK +case 13: +YY_RULE_SETUP +#line 33 "lib/lexer.l" +{ return(ELSE); } + YY_BREAK +case 14: +YY_RULE_SETUP +#line 34 "lib/lexer.l" +{ return(IFEND); } + YY_BREAK +case 15: +YY_RULE_SETUP +#line 35 "lib/lexer.l" +{ return(FOR); } + YY_BREAK +case 16: +YY_RULE_SETUP +#line 36 "lib/lexer.l" +{ return(TO); } + YY_BREAK +case 17: +YY_RULE_SETUP +#line 37 "lib/lexer.l" +{ return(STEP); } + YY_BREAK +case 18: +YY_RULE_SETUP +#line 38 "lib/lexer.l" +{ return(NEXT); } + YY_BREAK +case 19: +YY_RULE_SETUP +#line 39 "lib/lexer.l" +{ return(GOTO); } + YY_BREAK +case 20: +YY_RULE_SETUP +#line 40 "lib/lexer.l" +{ return(LABEL); } + YY_BREAK +case 21: +YY_RULE_SETUP +#line 41 "lib/lexer.l" +{ return(BREAK); } + YY_BREAK +case 22: +YY_RULE_SETUP +#line 42 "lib/lexer.l" +{ return(RETURN); } + YY_BREAK +case 23: +YY_RULE_SETUP +#line 43 "lib/lexer.l" +{ return(STOP); } + YY_BREAK +case 24: +YY_RULE_SETUP +#line 44 "lib/lexer.l" +{ return(IDENTIFIER); } + YY_BREAK +case 25: +/* rule 25 can match eol */ +YY_RULE_SETUP +#line 45 "lib/lexer.l" +{ return(EOL); } + YY_BREAK +case 26: +YY_RULE_SETUP +#line 46 "lib/lexer.l" + + YY_BREAK +case 27: +YY_RULE_SETUP +#line 47 "lib/lexer.l" +{ cerr << "Invalid character: " << yytext << endl; } + YY_BREAK +case 28: +YY_RULE_SETUP +#line 49 "lib/lexer.l" +ECHO; + YY_BREAK +#line 946 "lib/lexer_gen.cpp" +case YY_STATE_EOF(INITIAL): + yyterminate(); + + case YY_END_OF_BUFFER: + { + /* Amount of text matched not including the EOB char. */ + int yy_amount_of_matched_text = (int) (yy_cp - (yytext_ptr)) - 1; + + /* Undo the effects of YY_DO_BEFORE_ACTION. */ + *yy_cp = (yy_hold_char); + YY_RESTORE_YY_MORE_OFFSET + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) + { + /* We're scanning a new file or input source. It's + * possible that this happened because the user + * just pointed yyin at a new source and called + * yylex(). If so, then we have to assure + * consistency between YY_CURRENT_BUFFER and our + * globals. Here is the right place to do so, because + * this is the first action (other than possibly a + * back-up) that will match for the new input source. + */ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + YY_CURRENT_BUFFER_LVALUE->yy_input_file = yyin; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = YY_BUFFER_NORMAL; + } + + /* Note that here we test for yy_c_buf_p "<=" to the position + * of the first EOB in the buffer, since yy_c_buf_p will + * already have been incremented past the NUL character + * (since all states make transitions on EOB to the + * end-of-buffer state). Contrast this with the test + * in input(). + */ + if ( (yy_c_buf_p) <= &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + { /* This was really a NUL. */ + yy_state_type yy_next_state; + + (yy_c_buf_p) = (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + /* Okay, we're now positioned to make the NUL + * transition. We couldn't have + * yy_get_previous_state() go ahead and do it + * for us because it doesn't know how to deal + * with the possibility of jamming (and we don't + * want to build jamming into it because then it + * will run more slowly). + */ + + yy_next_state = yy_try_NUL_trans( yy_current_state ); + + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + + if ( yy_next_state ) + { + /* Consume the NUL. */ + yy_cp = ++(yy_c_buf_p); + yy_current_state = yy_next_state; + goto yy_match; + } + + else + { + yy_cp = (yy_c_buf_p); + goto yy_find_action; + } + } + + else switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_END_OF_FILE: + { + (yy_did_buffer_switch_on_eof) = 0; + + if ( yywrap( ) ) + { + /* Note: because we've taken care in + * yy_get_next_buffer() to have set up + * yytext, we can now set up + * yy_c_buf_p so that if some total + * hoser (like flex itself) wants to + * call the scanner after we return the + * YY_NULL, it'll still work - another + * YY_NULL will get returned. + */ + (yy_c_buf_p) = (yytext_ptr) + YY_MORE_ADJ; + + yy_act = YY_STATE_EOF(YY_START); + goto do_action; + } + + else + { + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; + } + break; + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = + (yytext_ptr) + yy_amount_of_matched_text; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_match; + + case EOB_ACT_LAST_MATCH: + (yy_c_buf_p) = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)]; + + yy_current_state = yy_get_previous_state( ); + + yy_cp = (yy_c_buf_p); + yy_bp = (yytext_ptr) + YY_MORE_ADJ; + goto yy_find_action; + } + break; + } + + default: + YY_FATAL_ERROR( + "fatal flex scanner internal error--no action found" ); + } /* end of action switch */ + } /* end of scanning one token */ + } /* end of user's declarations */ +} /* end of yylex */ + +/* yy_get_next_buffer - try to read in a new buffer + * + * Returns a code representing an action: + * EOB_ACT_LAST_MATCH - + * EOB_ACT_CONTINUE_SCAN - continue scanning from current position + * EOB_ACT_END_OF_FILE - end of file + */ +static int yy_get_next_buffer (void) +{ + char *dest = YY_CURRENT_BUFFER_LVALUE->yy_ch_buf; + char *source = (yytext_ptr); + yy_size_t number_to_move, i; + int ret_val; + + if ( (yy_c_buf_p) > &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] ) + YY_FATAL_ERROR( + "fatal flex scanner internal error--end of buffer missed" ); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_fill_buffer == 0 ) + { /* Don't try to fill the buffer, so this is an EOF. */ + if ( (yy_c_buf_p) - (yytext_ptr) - YY_MORE_ADJ == 1 ) + { + /* We matched a single character, the EOB, so + * treat this as a final EOF. + */ + return EOB_ACT_END_OF_FILE; + } + + else + { + /* We matched some text prior to the EOB, first + * process it. + */ + return EOB_ACT_LAST_MATCH; + } + } + + /* Try to read more data. */ + + /* First move last chars to start of buffer. */ + number_to_move = (yy_size_t) ((yy_c_buf_p) - (yytext_ptr)) - 1; + + for ( i = 0; i < number_to_move; ++i ) + *(dest++) = *(source++); + + if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_EOF_PENDING ) + /* don't do the read, it's not guaranteed to return an EOF, + * just force an EOF + */ + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars) = 0; + + else + { + int num_to_read = + YY_CURRENT_BUFFER_LVALUE->yy_buf_size - number_to_move - 1; + + while ( num_to_read <= 0 ) + { /* Not enough room in the buffer - grow it. */ + + /* just a shorter name for the current buffer */ + YY_BUFFER_STATE b = YY_CURRENT_BUFFER_LVALUE; + + int yy_c_buf_p_offset = + (int) ((yy_c_buf_p) - b->yy_ch_buf); + + if ( b->yy_is_our_buffer ) + { + int new_size = b->yy_buf_size * 2; + + if ( new_size <= 0 ) + b->yy_buf_size += b->yy_buf_size / 8; + else + b->yy_buf_size *= 2; + + b->yy_ch_buf = (char *) + /* Include room in for 2 EOB chars. */ + yyrealloc((void *) b->yy_ch_buf,b->yy_buf_size + 2 ); + } + else + /* Can't grow it, we don't own it. */ + b->yy_ch_buf = NULL; + + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( + "fatal error - scanner input buffer overflow" ); + + (yy_c_buf_p) = &b->yy_ch_buf[yy_c_buf_p_offset]; + + num_to_read = YY_CURRENT_BUFFER_LVALUE->yy_buf_size - + number_to_move - 1; + + } + + if ( num_to_read > YY_READ_BUF_SIZE ) + num_to_read = YY_READ_BUF_SIZE; + + /* Read in more data. */ + YY_INPUT( (&YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]), + (yy_n_chars), num_to_read ); + + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + if ( (yy_n_chars) == 0 ) + { + if ( number_to_move == YY_MORE_ADJ ) + { + ret_val = EOB_ACT_END_OF_FILE; + yyrestart(yyin ); + } + + else + { + ret_val = EOB_ACT_LAST_MATCH; + YY_CURRENT_BUFFER_LVALUE->yy_buffer_status = + YY_BUFFER_EOF_PENDING; + } + } + + else + ret_val = EOB_ACT_CONTINUE_SCAN; + + if ((int) ((yy_n_chars) + number_to_move) > YY_CURRENT_BUFFER_LVALUE->yy_buf_size) { + /* Extend the array by 50%, plus the number we really need. */ + int new_size = (yy_n_chars) + number_to_move + ((yy_n_chars) >> 1); + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf = (char *) yyrealloc((void *) YY_CURRENT_BUFFER_LVALUE->yy_ch_buf,new_size ); + if ( ! YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_get_next_buffer()" ); + } + + (yy_n_chars) += number_to_move; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] = YY_END_OF_BUFFER_CHAR; + YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars) + 1] = YY_END_OF_BUFFER_CHAR; + + (yytext_ptr) = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[0]; + + return ret_val; +} + +/* yy_get_previous_state - get the state just before the EOB char was reached */ + + static yy_state_type yy_get_previous_state (void) +{ + yy_state_type yy_current_state; + char *yy_cp; + + yy_current_state = (yy_start); + + for ( yy_cp = (yytext_ptr) + YY_MORE_ADJ; yy_cp < (yy_c_buf_p); ++yy_cp ) + { + YY_CHAR yy_c = (*yy_cp ? yy_ec[YY_SC_TO_UI(*yy_cp)] : 1); + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 90 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; + } + + return yy_current_state; +} + +/* yy_try_NUL_trans - try to make a transition on the NUL character + * + * synopsis + * next_state = yy_try_NUL_trans( current_state ); + */ + static yy_state_type yy_try_NUL_trans (yy_state_type yy_current_state ) +{ + int yy_is_jam; + char *yy_cp = (yy_c_buf_p); + + YY_CHAR yy_c = 1; + if ( yy_accept[yy_current_state] ) + { + (yy_last_accepting_state) = yy_current_state; + (yy_last_accepting_cpos) = yy_cp; + } + while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) + { + yy_current_state = (int) yy_def[yy_current_state]; + if ( yy_current_state >= 90 ) + yy_c = yy_meta[(unsigned int) yy_c]; + } + yy_current_state = yy_nxt[yy_base[yy_current_state] + (flex_int16_t) yy_c]; + yy_is_jam = (yy_current_state == 89); + + return yy_is_jam ? 0 : yy_current_state; +} + +#ifndef YY_NO_UNPUT + + static void yyunput (int c, char * yy_bp ) +{ + char *yy_cp; + + yy_cp = (yy_c_buf_p); + + /* undo effects of setting up yytext */ + *yy_cp = (yy_hold_char); + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + { /* need to shift things up to make room */ + /* +2 for EOB chars. */ + int number_to_move = (yy_n_chars) + 2; + char *dest = &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[ + YY_CURRENT_BUFFER_LVALUE->yy_buf_size + 2]; + char *source = + &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[number_to_move]; + + while ( source > YY_CURRENT_BUFFER_LVALUE->yy_ch_buf ) + *--dest = *--source; + + yy_cp += (int) (dest - source); + yy_bp += (int) (dest - source); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = + (yy_n_chars) = (int) YY_CURRENT_BUFFER_LVALUE->yy_buf_size; + + if ( yy_cp < YY_CURRENT_BUFFER_LVALUE->yy_ch_buf + 2 ) + YY_FATAL_ERROR( "flex scanner push-back overflow" ); + } + + *--yy_cp = (char) c; + + (yytext_ptr) = yy_bp; + (yy_hold_char) = *yy_cp; + (yy_c_buf_p) = yy_cp; +} + +#endif + +#ifndef YY_NO_INPUT +#ifdef __cplusplus + static int yyinput (void) +#else + static int input (void) +#endif + +{ + int c; + + *(yy_c_buf_p) = (yy_hold_char); + + if ( *(yy_c_buf_p) == YY_END_OF_BUFFER_CHAR ) + { + /* yy_c_buf_p now points to the character we want to return. + * If this occurs *before* the EOB characters, then it's a + * valid NUL; if not, then we've hit the end of the buffer. + */ + if ( (yy_c_buf_p) < &YY_CURRENT_BUFFER_LVALUE->yy_ch_buf[(yy_n_chars)] ) + /* This was really a NUL. */ + *(yy_c_buf_p) = '\0'; + + else + { /* need more input */ + int offset = (yy_c_buf_p) - (yytext_ptr); + ++(yy_c_buf_p); + + switch ( yy_get_next_buffer( ) ) + { + case EOB_ACT_LAST_MATCH: + /* This happens because yy_g_n_b() + * sees that we've accumulated a + * token and flags that we need to + * try matching the token before + * proceeding. But for input(), + * there's no matching to consider. + * So convert the EOB_ACT_LAST_MATCH + * to EOB_ACT_END_OF_FILE. + */ + + /* Reset buffer status. */ + yyrestart(yyin ); + + /*FALLTHROUGH*/ + + case EOB_ACT_END_OF_FILE: + { + if ( yywrap( ) ) + return 0; + + if ( ! (yy_did_buffer_switch_on_eof) ) + YY_NEW_FILE; +#ifdef __cplusplus + return yyinput(); +#else + return input(); +#endif + } + + case EOB_ACT_CONTINUE_SCAN: + (yy_c_buf_p) = (yytext_ptr) + offset; + break; + } + } + } + + c = *(unsigned char *) (yy_c_buf_p); /* cast for 8-bit char's */ + *(yy_c_buf_p) = '\0'; /* preserve yytext */ + (yy_hold_char) = *++(yy_c_buf_p); + + return c; +} +#endif /* ifndef YY_NO_INPUT */ + +/** Immediately switch to a different input stream. + * @param input_file A readable stream. + * + * @note This function does not reset the start condition to @c INITIAL . + */ + void yyrestart (FILE * input_file ) +{ + + if ( ! YY_CURRENT_BUFFER ){ + yyensure_buffer_stack (); + YY_CURRENT_BUFFER_LVALUE = + yy_create_buffer(yyin,YY_BUF_SIZE ); + } + + yy_init_buffer(YY_CURRENT_BUFFER,input_file ); + yy_load_buffer_state( ); +} + +/** Switch to a different input buffer. + * @param new_buffer The new input buffer. + * + */ + void yy_switch_to_buffer (YY_BUFFER_STATE new_buffer ) +{ + + /* TODO. We should be able to replace this entire function body + * with + * yypop_buffer_state(); + * yypush_buffer_state(new_buffer); + */ + yyensure_buffer_stack (); + if ( YY_CURRENT_BUFFER == new_buffer ) + return; + + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + YY_CURRENT_BUFFER_LVALUE = new_buffer; + yy_load_buffer_state( ); + + /* We don't actually know whether we did this switch during + * EOF (yywrap()) processing, but the only time this flag + * is looked at is after yywrap() is called, so it's safe + * to go ahead and always set it. + */ + (yy_did_buffer_switch_on_eof) = 1; +} + +static void yy_load_buffer_state (void) +{ + (yy_n_chars) = YY_CURRENT_BUFFER_LVALUE->yy_n_chars; + (yytext_ptr) = (yy_c_buf_p) = YY_CURRENT_BUFFER_LVALUE->yy_buf_pos; + yyin = YY_CURRENT_BUFFER_LVALUE->yy_input_file; + (yy_hold_char) = *(yy_c_buf_p); +} + +/** Allocate and initialize an input buffer state. + * @param file A readable stream. + * @param size The character buffer size in bytes. When in doubt, use @c YY_BUF_SIZE. + * + * @return the allocated buffer state. + */ + YY_BUFFER_STATE yy_create_buffer (FILE * file, int size ) +{ + YY_BUFFER_STATE b; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_buf_size = (yy_size_t)size; + + /* yy_ch_buf has to be 2 characters longer than the size given because + * we need to put in 2 end-of-buffer characters. + */ + b->yy_ch_buf = (char *) yyalloc(b->yy_buf_size + 2 ); + if ( ! b->yy_ch_buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_create_buffer()" ); + + b->yy_is_our_buffer = 1; + + yy_init_buffer(b,file ); + + return b; +} + +/** Destroy the buffer. + * @param b a buffer created with yy_create_buffer() + * + */ + void yy_delete_buffer (YY_BUFFER_STATE b ) +{ + + if ( ! b ) + return; + + if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ + YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; + + if ( b->yy_is_our_buffer ) + yyfree((void *) b->yy_ch_buf ); + + yyfree((void *) b ); +} + +/* Initializes or reinitializes a buffer. + * This function is sometimes called more than once on the same buffer, + * such as during a yyrestart() or at EOF. + */ + static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) + +{ + int oerrno = errno; + + yy_flush_buffer(b ); + + b->yy_input_file = file; + b->yy_fill_buffer = 1; + + /* If b is the current buffer, then yy_init_buffer was _probably_ + * called from yyrestart() or through yy_get_next_buffer. + * In that case, we don't want to reset the lineno or column. + */ + if (b != YY_CURRENT_BUFFER){ + b->yy_bs_lineno = 1; + b->yy_bs_column = 0; + } + + b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0; + + errno = oerrno; +} + +/** Discard all buffered characters. On the next scan, YY_INPUT will be called. + * @param b the buffer state to be flushed, usually @c YY_CURRENT_BUFFER. + * + */ + void yy_flush_buffer (YY_BUFFER_STATE b ) +{ + if ( ! b ) + return; + + b->yy_n_chars = 0; + + /* We always need two end-of-buffer characters. The first causes + * a transition to the end-of-buffer state. The second causes + * a jam in that state. + */ + b->yy_ch_buf[0] = YY_END_OF_BUFFER_CHAR; + b->yy_ch_buf[1] = YY_END_OF_BUFFER_CHAR; + + b->yy_buf_pos = &b->yy_ch_buf[0]; + + b->yy_at_bol = 1; + b->yy_buffer_status = YY_BUFFER_NEW; + + if ( b == YY_CURRENT_BUFFER ) + yy_load_buffer_state( ); +} + +/** Pushes the new state onto the stack. The new state becomes + * the current state. This function will allocate the stack + * if necessary. + * @param new_buffer The new state. + * + */ +void yypush_buffer_state (YY_BUFFER_STATE new_buffer ) +{ + if (new_buffer == NULL) + return; + + yyensure_buffer_stack(); + + /* This block is copied from yy_switch_to_buffer. */ + if ( YY_CURRENT_BUFFER ) + { + /* Flush out information for old buffer. */ + *(yy_c_buf_p) = (yy_hold_char); + YY_CURRENT_BUFFER_LVALUE->yy_buf_pos = (yy_c_buf_p); + YY_CURRENT_BUFFER_LVALUE->yy_n_chars = (yy_n_chars); + } + + /* Only push if top exists. Otherwise, replace top. */ + if (YY_CURRENT_BUFFER) + (yy_buffer_stack_top)++; + YY_CURRENT_BUFFER_LVALUE = new_buffer; + + /* copied from yy_switch_to_buffer. */ + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; +} + +/** Removes and deletes the top of the stack, if present. + * The next element becomes the new top. + * + */ +void yypop_buffer_state (void) +{ + if (!YY_CURRENT_BUFFER) + return; + + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + if ((yy_buffer_stack_top) > 0) + --(yy_buffer_stack_top); + + if (YY_CURRENT_BUFFER) { + yy_load_buffer_state( ); + (yy_did_buffer_switch_on_eof) = 1; + } +} + +/* Allocates the stack if it does not exist. + * Guarantees space for at least one push. + */ +static void yyensure_buffer_stack (void) +{ + int num_to_alloc; + + if (!(yy_buffer_stack)) { + + /* First allocation is just for 2 elements, since we don't know if this + * scanner will even need a stack. We use 2 instead of 1 to avoid an + * immediate realloc on the next call. + */ + num_to_alloc = 1; /* After all that talk, this was set to 1 anyways... */ + (yy_buffer_stack) = (struct yy_buffer_state**)yyalloc + (num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + memset((yy_buffer_stack), 0, num_to_alloc * sizeof(struct yy_buffer_state*)); + + (yy_buffer_stack_max) = num_to_alloc; + (yy_buffer_stack_top) = 0; + return; + } + + if ((yy_buffer_stack_top) >= ((yy_buffer_stack_max)) - 1){ + + /* Increase the buffer to prepare for a possible push. */ + yy_size_t grow_size = 8 /* arbitrary grow size */; + + num_to_alloc = (yy_buffer_stack_max) + grow_size; + (yy_buffer_stack) = (struct yy_buffer_state**)yyrealloc + ((yy_buffer_stack), + num_to_alloc * sizeof(struct yy_buffer_state*) + ); + if ( ! (yy_buffer_stack) ) + YY_FATAL_ERROR( "out of dynamic memory in yyensure_buffer_stack()" ); + + /* zero only the new slots.*/ + memset((yy_buffer_stack) + (yy_buffer_stack_max), 0, grow_size * sizeof(struct yy_buffer_state*)); + (yy_buffer_stack_max) = num_to_alloc; + } +} + +/** Setup the input buffer state to scan directly from a user-specified character buffer. + * @param base the character buffer + * @param size the size in bytes of the character buffer + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_buffer (char * base, yy_size_t size ) +{ + YY_BUFFER_STATE b; + + if ( size < 2 || + base[size-2] != YY_END_OF_BUFFER_CHAR || + base[size-1] != YY_END_OF_BUFFER_CHAR ) + /* They forgot to leave room for the EOB's. */ + return NULL; + + b = (YY_BUFFER_STATE) yyalloc(sizeof( struct yy_buffer_state ) ); + if ( ! b ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_buffer()" ); + + b->yy_buf_size = size - 2; /* "- 2" to take care of EOB's */ + b->yy_buf_pos = b->yy_ch_buf = base; + b->yy_is_our_buffer = 0; + b->yy_input_file = NULL; + b->yy_n_chars = b->yy_buf_size; + b->yy_is_interactive = 0; + b->yy_at_bol = 1; + b->yy_fill_buffer = 0; + b->yy_buffer_status = YY_BUFFER_NEW; + + yy_switch_to_buffer(b ); + + return b; +} + +/** Setup the input buffer state to scan a string. The next call to yylex() will + * scan from a @e copy of @a str. + * @param yystr a NUL-terminated string to scan + * + * @return the newly allocated buffer state object. + * @note If you want to scan bytes that may contain NUL values, then use + * yy_scan_bytes() instead. + */ +YY_BUFFER_STATE yy_scan_string (yyconst char * yystr ) +{ + + return yy_scan_bytes(yystr,(int) strlen(yystr) ); +} + +/** Setup the input buffer state to scan the given bytes. The next call to yylex() will + * scan from a @e copy of @a bytes. + * @param yybytes the byte buffer to scan + * @param _yybytes_len the number of bytes in the buffer pointed to by @a bytes. + * + * @return the newly allocated buffer state object. + */ +YY_BUFFER_STATE yy_scan_bytes (yyconst char * yybytes, int _yybytes_len ) +{ + YY_BUFFER_STATE b; + char *buf; + yy_size_t n; + yy_size_t i; + + /* Get memory for full buffer, including space for trailing EOB's. */ + n = (yy_size_t) _yybytes_len + 2; + buf = (char *) yyalloc(n ); + if ( ! buf ) + YY_FATAL_ERROR( "out of dynamic memory in yy_scan_bytes()" ); + + for ( i = 0; i < _yybytes_len; ++i ) + buf[i] = yybytes[i]; + + buf[_yybytes_len] = buf[_yybytes_len+1] = YY_END_OF_BUFFER_CHAR; + + b = yy_scan_buffer(buf,n ); + if ( ! b ) + YY_FATAL_ERROR( "bad buffer in yy_scan_bytes()" ); + + /* It's okay to grow etc. this buffer, and we should throw it + * away when we're done. + */ + b->yy_is_our_buffer = 1; + + return b; +} + +#ifndef YY_EXIT_FAILURE +#define YY_EXIT_FAILURE 2 +#endif + +static void yynoreturn yy_fatal_error (yyconst char* msg ) +{ + (void) fprintf( stderr, "%s\n", msg ); + exit( YY_EXIT_FAILURE ); +} + +/* Redefine yyless() so it works in section 3 code. */ + +#undef yyless +#define yyless(n) \ + do \ + { \ + /* Undo effects of setting up yytext. */ \ + int yyless_macro_arg = (n); \ + YY_LESS_LINENO(yyless_macro_arg);\ + yytext[yyleng] = (yy_hold_char); \ + (yy_c_buf_p) = yytext + yyless_macro_arg; \ + (yy_hold_char) = *(yy_c_buf_p); \ + *(yy_c_buf_p) = '\0'; \ + yyleng = yyless_macro_arg; \ + } \ + while ( 0 ) + +/* Accessor methods (get/set functions) to struct members. */ + +/** Get the current line number. + * + */ +int yyget_lineno (void) +{ + + return yylineno; +} + +/** Get the input stream. + * + */ +FILE *yyget_in (void) +{ + return yyin; +} + +/** Get the output stream. + * + */ +FILE *yyget_out (void) +{ + return yyout; +} + +/** Get the length of the current token. + * + */ +int yyget_leng (void) +{ + return yyleng; +} + +/** Get the current token. + * + */ + +char *yyget_text (void) +{ + return yytext; +} + +/** Set the current line number. + * @param _line_number line number + * + */ +void yyset_lineno (int _line_number ) +{ + + yylineno = _line_number; +} + +/** Set the input stream. This does not discard the current + * input buffer. + * @param _in_str A readable stream. + * + * @see yy_switch_to_buffer + */ +void yyset_in (FILE * _in_str ) +{ + yyin = _in_str ; +} + +void yyset_out (FILE * _out_str ) +{ + yyout = _out_str ; +} + +int yyget_debug (void) +{ + return yy_flex_debug; +} + +void yyset_debug (int _bdebug ) +{ + yy_flex_debug = _bdebug ; +} + +static int yy_init_globals (void) +{ + /* Initialization is the same as for the non-reentrant scanner. + * This function is called from yylex_destroy(), so don't allocate here. + */ + + (yy_buffer_stack) = NULL; + (yy_buffer_stack_top) = 0; + (yy_buffer_stack_max) = 0; + (yy_c_buf_p) = NULL; + (yy_init) = 0; + (yy_start) = 0; + +/* Defined in main.c */ +#ifdef YY_STDINIT + yyin = stdin; + yyout = stdout; +#else + yyin = NULL; + yyout = NULL; +#endif + + /* For future reference: Set errno on error, since we are called by + * yylex_init() + */ + return 0; +} + +/* yylex_destroy is for both reentrant and non-reentrant scanners. */ +int yylex_destroy (void) +{ + + /* Pop the buffer stack, destroying each element. */ + while(YY_CURRENT_BUFFER){ + yy_delete_buffer(YY_CURRENT_BUFFER ); + YY_CURRENT_BUFFER_LVALUE = NULL; + yypop_buffer_state(); + } + + /* Destroy the stack itself. */ + yyfree((yy_buffer_stack) ); + (yy_buffer_stack) = NULL; + + /* Reset the globals. This is important in a non-reentrant scanner so the next time + * yylex() is called, initialization will occur. */ + yy_init_globals( ); + + return 0; +} + +/* + * Internal utility routines. + */ + +#ifndef yytext_ptr +static void yy_flex_strncpy (char* s1, yyconst char * s2, int n ) +{ + + int i; + for ( i = 0; i < n; ++i ) + s1[i] = s2[i]; +} +#endif + +#ifdef YY_NEED_STRLEN +static int yy_flex_strlen (yyconst char * s ) +{ + int n; + for ( n = 0; s[n]; ++n ) + ; + + return n; +} +#endif + +void *yyalloc (yy_size_t size ) +{ + return malloc(size); +} + +void *yyrealloc (void * ptr, yy_size_t size ) +{ + + /* The cast to (char *) in the following accommodates both + * implementations that use char* generic pointers, and those + * that use void* generic pointers. It works with the latter + * because both ANSI C and C++ allow castless assignment from + * any pointer type to void*, and deal with argument conversions + * as though doing an assignment. + */ + return realloc(ptr, size); +} + +void yyfree (void * ptr ) +{ + free( (char *) ptr ); /* see yyrealloc() for (char *) cast */ +} + +#define YYTABLES_NAME "yytables" + +#line 49 "lib/lexer.l" + + + diff --git a/src/lib/src/location.hh b/src/lib/src/location.hh new file mode 100644 index 0000000..6e09d25 --- /dev/null +++ b/src/lib/src/location.hh @@ -0,0 +1,192 @@ +// A Bison parser, made by GNU Bison 3.0.4. + +// Locations for Bison parsers in C++ + +// Copyright (C) 2002-2015 Free Software Foundation, Inc. + +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +// As a special exception, you may create a larger work that contains +// part or all of the Bison parser skeleton and distribute that work +// under terms of your choice, so long as that work isn't itself a +// parser generator using the skeleton or a modified version thereof +// as a parser skeleton. Alternatively, if you modify or redistribute +// the parser skeleton itself, you may (at your option) remove this +// special exception, which will cause the skeleton and the resulting +// Bison output files to be licensed under the GNU General Public +// License without this special exception. + +// This special exception was added by the Free Software Foundation in +// version 2.2 of Bison. + +/** + ** \file lib/location.hh + ** Define the yy::location class. + */ + +#ifndef YY_YY_LIB_LOCATION_HH_INCLUDED +# define YY_YY_LIB_LOCATION_HH_INCLUDED + +# include "position.hh" + + +namespace yy { +#line 46 "lib/location.hh" // location.cc:296 + /// Abstract a location. + class location + { + public: + + /// Construct a location from \a b to \a e. + location (const position& b, const position& e) + : begin (b) + , end (e) + { + } + + /// Construct a 0-width location in \a p. + explicit location (const position& p = position ()) + : begin (p) + , end (p) + { + } + + /// Construct a 0-width location in \a f, \a l, \a c. + explicit location (std::string* f, + unsigned int l = 1u, + unsigned int c = 1u) + : begin (f, l, c) + , end (f, l, c) + { + } + + + /// Initialization. + void initialize (std::string* f = YY_NULLPTR, + unsigned int l = 1u, + unsigned int c = 1u) + { + begin.initialize (f, l, c); + end = begin; + } + + /** \name Line and Column related manipulators + ** \{ */ + public: + /// Reset initial location to final location. + void step () + { + begin = end; + } + + /// Extend the current location to the COUNT next columns. + void columns (int count = 1) + { + end += count; + } + + /// Extend the current location to the COUNT next lines. + void lines (int count = 1) + { + end.lines (count); + } + /** \} */ + + + public: + /// Beginning of the located region. + position begin; + /// End of the located region. + position end; + }; + + /// Join two locations, in place. + inline location& operator+= (location& res, const location& end) + { + res.end = end.end; + return res; + } + + /// Join two locations. + inline location operator+ (location res, const location& end) + { + return res += end; + } + + /// Add \a width columns to the end position, in place. + inline location& operator+= (location& res, int width) + { + res.columns (width); + return res; + } + + /// Add \a width columns to the end position. + inline location operator+ (location res, int width) + { + return res += width; + } + + /// Subtract \a width columns to the end position, in place. + inline location& operator-= (location& res, int width) + { + return res += -width; + } + + /// Subtract \a width columns to the end position. + inline location operator- (location res, int width) + { + return res -= width; + } + + /// Compare two location objects. + inline bool + operator== (const location& loc1, const location& loc2) + { + return loc1.begin == loc2.begin && loc1.end == loc2.end; + } + + /// Compare two location objects. + inline bool + operator!= (const location& loc1, const location& loc2) + { + return !(loc1 == loc2); + } + + /** \brief Intercept output stream redirection. + ** \param ostr the destination output stream + ** \param loc a reference to the location to redirect + ** + ** Avoid duplicate information. + */ + template + inline std::basic_ostream& + operator<< (std::basic_ostream& ostr, const location& loc) + { + unsigned int end_col = 0 < loc.end.column ? loc.end.column - 1 : 0; + ostr << loc.begin; + if (loc.end.filename + && (!loc.begin.filename + || *loc.begin.filename != *loc.end.filename)) + ostr << '-' << loc.end.filename << ':' << loc.end.line << '.' << end_col; + else if (loc.begin.line < loc.end.line) + ostr << '-' << loc.end.line << '.' << end_col; + else if (loc.begin.column < end_col) + ostr << '-' << end_col; + return ostr; + } + + +} // yy +#line 192 "lib/location.hh" // location.cc:296 +#endif // !YY_YY_LIB_LOCATION_HH_INCLUDED diff --git a/src/lib/src/parser.yy b/src/lib/src/parser.yy new file mode 100644 index 0000000..5f4dd91 --- /dev/null +++ b/src/lib/src/parser.yy @@ -0,0 +1,113 @@ +%{ +#include +#include + +#include + +using namespace std; + + +int yylex(void); +void yyerror(const char * msg); + +std::string filename; +SourceLocation createLocation(int line,int column); + +extern FILE * yyin; +%} + +%skeleton "lalr1.cc" /* -*- C++ -*- */ +%require "3.0" +%defines + +%define parser_class_name { Parser } +%define api.token.constructor +%define api.value.type variant +%define parse.assert + +%locations + +%define parse.trace +%define parse.error verbose + +%left '-' '+' +%left '*' '/' + +%token DO LPWHILE +%token WHILE WHILEEND +%token IF THEN ELSE IFEND +%token FOR TO STEP NEXT +%token GOTO LABEL +%token BREAK RETURN STOP +%token STRING +%token INTEGER; +%token FLOAT; +%token IDENTIFIER +%token OPERATOR +%token ASSIGN IMPLIES EOL + +%start program + +%type stmtList; +%type stmt; +%type ifStmt; +%type forStmt; +%type expr; +%type assignStmt; +%% + +program : stmtList +; +stmtList : stmtList stmt { CompoundStatement* stmt = $1; stmt.setLastStatement($2); $$ = stmt; } + | stmt { CompoundStatement* stmt = new CompoundStatement(); stmt.setLastStatement($1); $$ = stmt; } +; +stmt : assignStmt + | ifStmt + | WHILE expr EOL stmtList EOL WHILEEND { $$ = new WhileStatement($2, $4, createLocation(@$.first_line, @$.first_column)); } + | DO EOL stmtList EOL LPWHILE expr { $$ = new DoStatement($3, $6, createLocation(@1.first_line, @1.first_column), createLocation(@6.first_line, @6.first_column)); } + | forStmt + | GOTO identifier + | LABEL identifier + | BREAK { $$ = new BreakStatement(createLocation(@$.first_line, @$.first_column)); } + | RETURN { $$ = new ReturnStatement(createLocation(@$.first_line, @$.first_column)); } + | STOP { $$ = new StopStatement(createLocation(@$.first_line, @$.first_column)); } + | expr +; +expr : identifier + | STRING { $$ = new StringLiteralExpr($1, createLocation(@1.first_line, @1.first_column)); } + | INTEGER { $$ = new IntegerLiteralExpr($1, createLocation(@1.first_line, @1.first_column)) } + | FLOAT { $$ = new FloatLiteralExpr($1, createLocation(@1.first_line, @1.first_column)) } + | expr OPERATOR expr { $$ = new BinaryOperatorExpr($1, $3, BinaryOperatorExpr::getStrOpcode($2)); } +; +identifier: IDENTIFIER +; +assignStmt : expr ASSIGN identifier +; +ifStmt : IF expr EOL THEN EOL stmtList EOL IFEND { $$ = new IfStatement(createLocation(@$.first_line, @$.first_column), $2, $6); } + | IF expr EOL THEN EOL stmtList EOL ELSE EOL stmtList EOL IFEND { $$ = new IfStatement(createLocation(@$.first_line, @$.first_column), $2, $6, createLocation(@10.first_line, @10.first_column), $10); } + | expr IMPLIES assignStmt { $$ = new IfStatement($1, $3); } +; +forStmt : FOR assignStmt TO expr EOL stmtList EOL NEXT { $$ = new ForStatement(createLocation(@$.first_line, @$.first_column), $2, $4, $6);} + | FOR assignStmt TO expr STEP expr EOL stmtList EOL NEXT { $$ = new ForStatement(createLocation(@$.first_line, @$.first_column), $2, $4, $8, $6);} +%% + +void yyerror(const char * msg) +{ + cerr << "line " << lineNumber << ": " << msg << endl; +} + +SourceLocation createLocation(int line,int column) +{ + return SourceLocation(filename, line, column); +} + + +AST* parse_str(std::string str) +{ + if(argc>1) + yyin=fopen(argv[1],"r"); // check result !!! + lineNumber=1; + if(!yyparse()) + cerr << "Success" << endl; + return(0); +} diff --git a/src/include/version.h.in b/src/lib/src/version.h.in similarity index 100% rename from src/include/version.h.in rename to src/lib/src/version.h.in diff --git a/src/libtest/main.cpp b/src/libtest/main.cpp index d6122aa..9b7cc4d 100644 --- a/src/libtest/main.cpp +++ b/src/libtest/main.cpp @@ -1,4 +1,4 @@ -#include "TranslationUnit.hpp" +#include "../lib/src/TranslationUnit.hpp" using namespace std; diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 69c3d1b..1a451b7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -33,5 +33,4 @@ function(add_blang_unittest test_name) endfunction() add_subdirectory(libblang) -add_subdirectory(Lex) -add_subdirectory(Mustache) + diff --git a/tests/libblang/files/IfTest.bs b/tests/libblang/files/IfTest.bs new file mode 100644 index 0000000..a2f9a03 --- /dev/null +++ b/tests/libblang/files/IfTest.bs @@ -0,0 +1,6 @@ +If A = ":" + +If A > 0 +IfEnd +If A < 0 +IfEnd \ No newline at end of file diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt deleted file mode 100644 index aac2159..0000000 --- a/utils/CMakeLists.txt +++ /dev/null @@ -1,22 +0,0 @@ -include_directories(src) - -set(BLANG_UTILS_INCLUDE ${CMAKE_CURRENT_LIST_DIR}/src CACHE STRING "BlangUtils include directory") - -file( - - GLOB_RECURSE - - src_files - - src/* - -) - -add_library( - - blangutils - - SHARED - - ${src_files} -) diff --git a/utils/src/string.cpp b/utils/src/string.cpp deleted file mode 100644 index 97c028a..0000000 --- a/utils/src/string.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include - -#include "string.hpp" - -Blang::string::string(): std::string(){ - -} - -Blang::string::string(const std::string& str):std::string(str){ - -} - -Blang::string::string (const char* s):std::string(s){ - -} - -Blang::string Blang::string::ltrim(){ - Blang::string str = Blang::string(*this); - str.erase(str.begin(), std::find_if(str.begin(), str.end(), not1(std::ptr_fun(std::isspace)))); - return str; -} - -Blang::string Blang::string::rtrim(){ - Blang::string str = Blang::string(*this); - str.erase(std::find_if(str.rbegin(), str.rend(), not1(std::ptr_fun(std::isspace))).base(), str.end()); - return str; -} - -Blang::string Blang::string::trim(){ - return ltrim().rtrim(); -} \ No newline at end of file diff --git a/utils/src/string.hpp b/utils/src/string.hpp deleted file mode 100644 index 60c8d5d..0000000 --- a/utils/src/string.hpp +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef BLANGSTRING_HPP -#define BLANGSTRING_HPP - -#include -#include -#include - -namespace Blang{ - class string : public std::string - { - public: - string(); - string(const std::string& str); - string (const char* s); - - string ltrim(); - string rtrim(); - string trim(); - - bool startsWith(string str, bool caseSensitive = true); - bool startsWith(string str,string splitter, bool caseSensitive = true); - bool startsWith(std::list str, bool caseSensitive = true); - bool startsWith(std::regex reg, bool caseSensitive = true); - }; -} - -#endif