Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incompatibility with Bison >= 3.5 #270

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,25 +46,23 @@ addons:
# for Mac builds, we use Homebrew
homebrew:
packages:
- flex
- bison
- boost
- cmake
- flex
- python@3
update: true

#=============================================================================
# Install dependencies / setup Spack
#=============================================================================
before_install:
# default bison in homebrew is now 3.5 but nmodl currently does not build with bison 3.5
# brew installed flex and bison is not in $PATH
# unlink python2 and use python3 as it's required for nmodl
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
export PATH=/usr/local/opt/flex/bin:/usr/local/opt/bison/bin:$PATH;
brew unlink python@2;
brew link --overwrite python;
curl -L "https://homebrew.bintray.com/bottles/bison-3.4.2.mojave.bottle.tar.gz" -o bison-3.4.2.mojave.bottle.tar.gz;
brew install file://$(pwd)/bison-3.4.2.mojave.bottle.tar.gz;
else
pyenv global $PYTHON_VERSION;
ls /usr/bin/;
Expand Down
5 changes: 1 addition & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ jobs:
- checkout: self
submodules: true
- script: |
brew install flex cmake python@3
# default bison in homebrew is now 3.5 but nmodl currently does not build with bison 3.5
curl -L "https://homebrew.bintray.com/bottles/bison-3.4.2.mojave.bottle.tar.gz" -o bison-3.4.2.mojave.bottle.tar.gz
brew install file://$(pwd)/bison-3.4.2.mojave.bottle.tar.gz
brew install flex bison cmake python@3
python3 -m pip install -U pip setuptools
python3 -m pip install --user 'Jinja2>=2.9.3' 'PyYAML>=3.13' pytest 'sympy>=1.3'
displayName: 'Install Depdendencies'
Expand Down
6 changes: 3 additions & 3 deletions src/lexer/main_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

using namespace fmt::literals;
using namespace nmodl;

using Token = parser::CParser::token;

void scan_c_code(std::istream& in) {
nmodl::parser::CDriver driver;
Expand All @@ -34,8 +34,8 @@ void scan_c_code(std::istream& in) {
/// parse C file and print token until EOF
while (true) {
auto sym = scanner.next_token();
auto token = sym.token();
if (token == nmodl::parser::CParser::token::END) {
auto token_type = sym.type_get();
if (token_type == parser::CParser::by_type(Token::END).type_get()) {
break;
}
std::cout << sym.value.as<std::string>() << std::endl;
Expand Down
55 changes: 23 additions & 32 deletions src/lexer/main_nmodl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,74 +45,65 @@ void tokenize(const std::string& mod_text) {
/// lexer instance with stream to read-in tokens
NmodlLexer scanner(driver, &in);

auto get_token_type = [](TokenType token) {
return parser::NmodlParser::by_type(token).type_get();
};

/// parse nmodl text and print token until EOF
while (true) {
SymbolType sym = scanner.next_token();
TokenType token = sym.token();
auto token_type = sym.type_get();

if (token == Token::END) {
if (token_type == get_token_type(Token::END)) {
break;
}

/** Lexer returns different ast types base on token type. We
/**
* Lexer returns different ast types base on token type. We
* retrieve token object from each instance and print it.
* Note that value is of ast type i.e. ast::Name* etc. */
switch (token) {
* Note that value is of ast type i.e. ast::Name* etc.
*/
/// token with name ast class
case Token::NAME:
case Token::METHOD:
case Token::SUFFIX:
case Token::VALENCE:
case Token::DEL:
case Token::DEL2: {
if (token_type == get_token_type(Token::NAME) ||
token_type == get_token_type(Token::METHOD) ||
token_type == get_token_type(Token::SUFFIX) ||
token_type == get_token_type(Token::VALENCE) ||
token_type == get_token_type(Token::DEL) || token_type == get_token_type(Token::DEL2)) {
auto value = sym.value.as<ast::Name>();
std::cout << *(value.get_token()) << std::endl;
break;
}

/// token with prime ast class
case Token::PRIME: {
else if (token_type == get_token_type(Token::PRIME)) {
auto value = sym.value.as<ast::PrimeName>();
std::cout << *(value.get_token()) << std::endl;
break;
}

/// token with integer ast class
case Token::INTEGER: {
else if (token_type == get_token_type(Token::INTEGER)) {
auto value = sym.value.as<ast::Integer>();
std::cout << *(value.get_token()) << std::endl;
break;
}

/// token with double/float ast class
case Token::REAL: {
else if (token_type == get_token_type(Token::REAL)) {
auto value = sym.value.as<ast::Double>();
std::cout << *(value.get_token()) << std::endl;
break;
}

/// token with string ast class
case Token::STRING: {
else if (token_type == get_token_type(Token::STRING)) {
auto value = sym.value.as<ast::String>();
std::cout << *(value.get_token()) << std::endl;
break;
}

/// token with string data type
case Token::VERBATIM:
case Token::BLOCK_COMMENT:
case Token::LINE_PART: {
else if (token_type == get_token_type(Token::VERBATIM) ||
token_type == get_token_type(Token::BLOCK_COMMENT) ||
token_type == get_token_type(Token::LINE_PART)) {
auto str = sym.value.as<std::string>();
std::cout << str << std::endl;
break;
}

/// all remaining tokens has ModToken* as a vaue
default: {
else {
auto token = sym.value.as<ModToken>();
std::cout << token << std::endl;
}
}
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/lexer/main_units.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

using namespace fmt::literals;
using namespace nmodl;
using Token = parser::UnitParser::token;

int main(int argc, const char* argv[]) {
CLI::App app{"Unit-Lexer : Standalone Lexer for Units({})"_format(Version::to_string())};
Expand All @@ -42,8 +43,8 @@ int main(int argc, const char* argv[]) {
/// parse Units file and print token until EOF
while (true) {
auto sym = scanner.next_token();
auto token = sym.token();
if (token == nmodl::parser::UnitParser::token::END) {
auto token_type = sym.type_get();
if (token_type == parser::UnitParser::by_type(Token::END).type_get()) {
break;
}
std::cout << sym.value.as<std::string>() << std::endl;
Expand Down
4 changes: 2 additions & 2 deletions src/parser/c11_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ void CDriver::scan_string(std::string& text) {
this->parser = &parser;
while (true) {
auto sym = lexer->next_token();
auto token = sym.token();
if (token == CParser::token::END) {
auto token_type = sym.type_get();
if (token_type == CParser::by_type(CParser::token::END).type_get()) {
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/parser/diffeq_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ std::string DiffEqContext::get_expr_for_nonlinear() {
/// scan entire expression
while (true) {
auto sym = scanner.next_token();
auto token = sym.token();
if (token == DiffeqParser::token::END) {
auto token_type = sym.type_get();
if (token_type == DiffeqParser::by_type(DiffeqParser::token::END).type_get()) {
break;
}
/// extract value of the token and check if it is a token
Expand Down
4 changes: 2 additions & 2 deletions src/parser/unit_driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ void UnitDriver::scan_string(std::string& text) {
this->parser = &parser;
while (true) {
auto sym = lexer->next_token();
auto token = sym.token();
if (token == UnitParser::token::END) {
auto token_type = sym.type_get();
if (token_type == UnitParser::by_type(UnitParser::token::END).type_get()) {
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/verbatim.yy
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
%}

/** print out verbose error instead of just message 'syntax error' */
%error-verbose
%define parse.error verbose

/** make a reentrant parser */
%pure-parser
Expand Down
Loading