jeff-mott-or / cpplox Goto Github PK
View Code? Open in Web Editor NEWFollowing Nystrom's book Crafting Interpreters, implemented in C++.
Following Nystrom's book Crafting Interpreters, implemented in C++.
Members on a class that look like field reads and writes but that actually execute user-defined code.
When you call a method, it starts at the top of the class hierarchy and works down. A superclass method wins over a subclass method. In order to get to the subclass method, the superclass method can call inner, which is sort of like the inverse of super. It chains to the next method down the hierarchy.
The superclass method controls when and where the subclass is allowed to refine its behavior. If the superclass method doesn’t call inner at all, then the subclass has no way of overriding or modifying the superclass’s behavior.
Hint: Make LoxClass extend LoxInstance and go from there.
Make sure to handle newlines in them. Consider allowing them to nest.
Hiya, I'm trying to get this to compile on macos (M1). So far I'm using homebrew Boost and had to add a find_package(Boost etc...) and edit the cmake file a bit.
But the main compile error was
[ 20%] Building CXX object CMakeFiles/cpploxbc_lib.dir/src/lox.cpp.o [ 22%] Building CXX object CMakeFiles/cpploxbc_lib.dir/src/value.cpp.o [ 25%] Building CXX object CMakeFiles/cpploxbc_lib.dir/src/vm.cpp.o [ 85%] Built target benchmark [ 91%] Built target benchmark_main /Users/danielelliott/Documents/projects/cpploxJeff/src/chunk.cpp:228:32: error: implicit instantiation of undefined template 'std::basic_ostringstream<char>' 228 | std::ostringstream line; | ^ /opt/homebrew/opt/llvm/bin/../include/c++/v1/__fwd/sstream.h:27:28: note: template is declared here 27 | class _LIBCPP_TEMPLATE_VIS basic_ostringstream; | ^ 1 error generated.
...that adding the sstream file solved.
Now I just have a linker error to sort out :)
It should be a syntax error to have a break statement appear outside of any enclosing loop.
Only methods on the class can access the raw fields.
If they enter a statement, execute it. If they enter an expression, evaluate it and display the result value.
Extend the resolver to associate a unique index for each local variable declared in a scope. When resolving a variable access, look up both the scope the variable is in and its index and store that. In the interpreter, use that to quickly access a variable by its index instead of using a map.
Is there any reason to keep it around if 2017 is available?
The resolver isn't some optional optimizing pass. It's required for the interpreter to work correctly. If the resolver is required by the interpreter, then we should express that relationship directly in code, perhaps by requiring a resolver as a constructor argument for the interpreter, so that you can't make an interpreter without also making a resolver.
Consider also making resolver return its map as a result rather than causing side-effects to the interpreter.
The interpreter and related code should be able to use deferred_ptr or shared_ptr or hboehm or raw pointer or any other arbitrary strategy.
Give them the same precedence and associativity as in C.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.